wqmeng 0 Posted Wednesday at 07:14 PM (edited) I have a function which need pass a class referrence in as a parameter. So I have type TFooBase = class; TFooBaseClass = class of TFooBase; TFooA = class(TFooBase) end; TFooB = class(TFooBase) end; //Then in another class type TBar = class public function FindFooByClass(AFooClass: TFooBaseClass): TFooBase; end; implement function TBar.FindFooByClass(AFooClass: TFooBaseClass): TFooBase; Then at the line function TBar.FindFooByClass(AFooClass: TFooBaseClass): TFooBase; Delphi report [dcc32 Error] xxx: E2037 Declaration of 'FindFooByClass' differs from previous declaration, But as you see, the Declaration is same. And if I change TFooBaseClass to be TClass in both the declaration and the implement as function FindFooByClass(AFooClass: TClass): TFooBase; function TBar.FindFooByClass(AFooClass: TClass): TFooBase; Then the source will complile. Just want to know that why TFooBaseClass not work? Edited Wednesday at 07:17 PM by wqmeng Share this post Link to post
Dave Nottage 605 Posted Wednesday at 07:20 PM 3 minutes ago, wqmeng said: So I have You do not have that. Please provide a complete example, that has the correct spelling of implementation, and the declaration for TFooBase, e.g. unit Unit2; interface type TFooBase = class; TFooBaseClass = class of TFooBase; TFooBase = class end; TFooA = class(TFooBase) end; TFooB = class(TFooBase) end; //Then in another class type TBar = class public function FindFooByClass(AFooClass: TFooBaseClass): TFooBase; end; implementation function TBar.FindFooByClass(AFooClass: TFooBaseClass): TFooBase; begin end; end. Which incidentally, compiles. Also, please just ask your question in one group. Share this post Link to post
wqmeng 0 Posted Wednesday at 07:41 PM Hello Dave, Thank you, I just create an empty project and add the code above, It could compiles. But in my work project, it use the similar approach, get the error as [dcc32 Error] xxx.pas(517): E2037 Declaration of 'FindIndicatorByClass' differs from previous declaration. Not sure why. Share this post Link to post
wqmeng 0 Posted Wednesday at 07:50 PM Sorry, Find the problem that the TFooBaseClass = class of TFooBase; Was defined in two units, after delete one, the problem get fixed. Thanks. Share this post Link to post
David Heffernan 2414 Posted Thursday at 06:34 PM 22 hours ago, wqmeng said: Sorry, Find the problem that the TFooBaseClass = class of TFooBase; Was defined in two units, after delete one, the problem get fixed. Thanks. The best piece of advice you can take from here is that you need to learn how to ask questions effectively. Because if you ask like this then nobody can help you. And it's just a waste of your time. 1 Share this post Link to post