Avatar of AbhiJeet
AbhiJeet

asked on 

interface vs. implementation uses clause

experts,

what is difference between interface uses clause and implementation uses clause, which is to be used in which scenario?
Delphi

Avatar of undefined
Last Comment
Mike McCracken
Avatar of Mahdi78
Mahdi78
Flag of Algeria image

Interface clause used by all unit function/procedure body and declaration, but implementation clause used by just function/procedure body
Avatar of AbhiJeet
AbhiJeet

ASKER

my question was different, my question was difference between uses clause in interface section and implementation section

interface
uses
 unit1;
implemenation
uses
 unit1;

in which scenario a unit to be referenced in implementation uses clause and in what scenario a unit can be referenced in interface section? ( excluding the reason of circular unit reference)
SOLUTION
Avatar of systan
systan
Flag of Philippines image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
ASKER CERTIFIED SOLUTION
Avatar of Geert G
Geert G
Flag of Belgium image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of Geert G
Geert G
Flag of Belgium image

oh yeah ...
only items in the interface section are visible  outside of the unit
I personally make it a goal to avoid using the implementation uses clause.  The primary reason for using the implementation uses clause, in practical use, is to attempt to get around a circular unit reference.  Just in case you are not aware... a circular unit reference is where Unit A uses Unit B which uses Unit C, which in turn, uses Unit A.  This will produce a compiler error that you have to address before you would be able to compile.  To get into this situation in the first place shows a poor design.  This is a clear indication that the design needs to be redone.  While I have seen this situation, and even gotten around it moving uses into the implementation section, it is not a fix.  At best it is a patch.  If the same design practices continue then the patch will need to be patched again and again until it cannot be fixed using the implementation section.  At this point the whole thing is such a mess that it would have saved a lot of time if it had been corrected the first time the situation was encountered.

Types made available through using another unit will not be available in your own public (interface section) types if they are used from the implementation section.  

I know that you mentioned "excluding the reason of circular unit reference", but since it is the main difference, and not often seen for the poor design trap that it can be, I thought I should go over it.

1. Anything declared in the interface section is global to your application. It can be used in any other unit of your system

2. Anything declared in implementation section is only available to methods in that unit. They can not be used in any other unit
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
Delphi
Delphi

Delphi is the most powerful Object Pascal IDE and component library for cross-platform Native App Development with flexible Cloud services and broad IoT connectivity. It provides powerful VCL controls for Windows 10 and enables FMX development for Windows, Mac and Mobile. Delphi is your choice for ultrafast Enterprise Strong Development™. Look for increased memory for large projects, extended multi-monitor support, improved Object Inspector and much more. Delphi is 5x faster for development and deployment across multiple desktop, mobile, cloud and database platforms including 32-bit and 64-bit Windows 10.

60K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo