tags:

views:

233

answers:

4

One of the problems I often run into, is that I will include 'Windows' in my uses clause, and then I will later add 'JwaWinBase' for some specific calls.

However, many of the functions in the 'Windows' unit are the same as in JwaWinBase, and I start getting errors in my main unit, all over the place, until I fix all my calls by pre-pending the correct unit name, like this:

Old:

  • CreateProcessAsUser(...)

New:

  • Windows.CreateProcessAsUser(...)
  • JwaWinBase.CreateProcessAsUser(...)

What I want to know, is if there is a way to have the unit name automatically pre-pended to every call to a function in another unit? This way, before I added JwaWinBase to my uses clause, I could have the 'Windows' unit name pre-pended to any function calls. Then adding JwaWinBase wouldn't give me any errors.

I'm currently using Delphi 2007.

+1  A: 

Maybe it's enough to just switch the order of the two units in the uses clause.

Ulrich Gerhardt
+5  A: 

There isn't.

However, the function calls are handled in the reverse order they're in the uses clause, so that if you have this:

uses
  Windows, JwaWinBase;

... it will call Jwa functions by default. However, if you reverse them:

uses
  JwaWinBase, Windows;

... it should call the Windows functions by default, and you can preface your Jwa functions as required.

Tim Sullivan
I did not know that. Thanks for the info!
Mick
+3  A: 

If you really need the resolution on a per-routine base, you could try inline forwarders:

procedure Blah; inline;
begin
  Windows.Blah;
end;

procedure Blubb; inline;
begin
  JwaWinBase.Blubb;
end;

// later:
procedure UseThem;
begin
  Blah; // calls Windows.Blah
  Blubb; // calls JwaWinBase.Blubb
end;

at the beginning of the implementation section (completely untested :-)).

Ulrich Gerhardt
+2  A: 

If you use an editor like CodeRush (D7 and before) or Castalia or even the template feature of D2009, you can create templates that expand to what you want AS you enter them. Then you can keep the Windows, jwaWinBase order in the uses section. You can set jcpau to expand to jwaWinBase.CreateProcessAsUser while cpau expands to CreateProcessAsUser or to Windows.CreateProcessAsUser depending on your preference. You'd only have to go through the various functions in jwaWinBase and make templates for them to be safe.

Otherwise, I think it's search and replace on a case-by-case basis.