Two Classes In Two Units With The Same Class Name in Delphi

I Have a case in Delphi such as:

Unit A contains class "One" Unit B contains class "One"

I'm in a class that uses unit A and want to use a static function from the class One in B; how do I do it? In C#, I'd write something like:


Or even I would use "using" to "rename" one namespace. What can I do in Delphi? (Removing the "uses" for unit A is not an option, nor is renaming one of the two classes.)

Edit: I'm using Delphi 2007.


You can use the following way: [UnitName].[Function]. For example B.SomeProcedure

What do you mean by "a class that uses"? Maybe you mean "a unit that uses"? If so, you need to add both A and B to the uses clause. You can then distinguish between the two procedures by writing A.One.SomeProcedure or B.One.SomeProcedure. If you just write One.SomeProcedure, the procedure in the unit listed last in the uses clause will be used. [Here I assume that One are classes containing class procedures SomeProcedure. If SomeProcedure is an ordinary procedure of the One class, you need -- of course -- to create an object of this class and use this. You can then do myobj := A.One.Create or myobj := B.One.Create, where var myobj: A.One or var myobj: B.One, respectively.]

(Remember also that each unit contains two uses clauses: one at the beginning of the interface section and one at the beginning of the implementation section. If you use something from unit A at line N, the uses clause containing the unit A needs to be located on a line above N.)

Also notice that in Delphi, the class should be called TOne, with the T prefix. Everyone follows this convention, and it looks odd without it.

how about TNewClassA = class(UnitA.One) and TNewClassB = class(UnitB.One)?

You can do exactly the same thing. UnitName.ClassName.Method, just like in C#.

Need Your Help

Subclass Overwrite c++

c++ dynamic subclass overwrite

I'm trying to get my head around why I can't overwrite a subclass object with another subclass object if they share base class.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.