Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

where to put the uses clause?

Status
Not open for further replies.

bianchin

Programmer
Mar 26, 2006
19
0
0
BR
Guys,

when I type Alt+f11, delphi puts my unit in the 'uses' clause in the 'implementation' section and never in the 'uses' of then 'interface' section

is there a difference between putting my unit in one uses or in the other?

this should turn my code faster or smaller

I have this doubt since Delphi 2 ... oh, My...

"Suffering, anguish, desperation and hard work are the materials a good programmer is made of." (buho (A))
"and against short remaining time..." (me)
 

AFAIK it doesn't really matter as long as it compiles.

There is at least one situation where you must put the uses reference in the implementation section: viz. when you have two units that "use" each other.

 
As per the rules, if in the interface section you are using anything defined in the "foo" unit you need to put "foo" in the interface uses clause.

PASCAL states that any object (var, const, procedure, etc) need to be defined before it is used (with a few exceptions, like the forward definitions for co-routines and pointers).

On the other hand, if something defined in "bar" is used only in the implementation section, you can put "bar" in the implementation uses clause (and is good style to do it so).

buho (A).
 
Yes, I observed this two situations.

about the case that two units, one referencing the other I had a problem, years ago.

I defined two TForm descendantes
TMyMDIParent and TMyMDIChild
each one with methods with parameter of type of the other

I planed it so perfectly and, of course, it was a disaster...

there's no way to put the units in the uses above the definitions of the parameters.

that project became realty only after I understood the inheritance and the 'as' operator



"Suffering, anguish, desperation and hard work are the materials a good programmer is made of." (buho (A))
"and against short remaining time..." (me)
 
but my point was:

"(and is good style to do it so)."

only this? a good style?



"Suffering, anguish, desperation and hard work are the materials a good programmer is made of." (buho (A))
"and against short remaining time..." (me)
 
Yep. Actually it is only a matter of style.

If you are using "bar" entities only in the implementation section, you can put "bar" in the interface section (if you have not circular references); the compiler will compile fine... but it is poor style, and style is a very important thing when maintenance time comes.

buho (A).
 
You can use the GExperts Uses Clause Manager to control where they go and move them back and forth.

It also provides a list of all units in your search path. That's helpful for me because I always forget the name of the JclFileUtils unit, for example.

GExperts should be part of your Delphi toolkit:

 
DjangMan:
Its it true to say that the GExperts tool only allows you to choose where a uses clause entry goes. Its not intelligent enough to tell you where it should go.

In fact IMHO this is true for all the GExperts tools. I worked for years without it!
The tools I use are the Message dialog creator and the Block marker (though this could be implemented better)
This is going off topic a bit though, start a new thread to discuss GExperts (& other add ons)?


Steve: Delphi a feersum engin indeed.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top