0

I want to get address of each overloaded class constructor.

TSomeClass = class
public
  constructor Create; overload;
  constructor Create(Value: String); overload;
end;

procedure Problem;
var
  Address1, Address2: Pointer;
begin
  Address1 := @TSomeClass.Create;
  Address2 := @TSomeClass.Create; // I want the address of constructor Create(Value: String) here. 
end;

How can I get the address of the constructor Create(Value: String)? Any help would be appreciated. Thanks.

subo
  • 1
  • Do it with RTTI. That said, what can you do with that pointer anyway? – David Heffernan Mar 10 '18 at 19:47
  • Answer from #11183243 does not work here. Define constructor type does not work in XE7. Does later versions support that? RTTI seems only option but It would better if there are non RTTI-dependent way. – subo Mar 10 '18 at 20:37
  • What can you do with the address anyway? – David Heffernan Mar 10 '18 at 20:39
  • I need to pass method pointer with argument count and types to 3rd party component. – subo Mar 10 '18 at 20:42
  • It's not a method pointer though. Constructors are special. And even if it was a normal method, @TMyClass.Foo doesn't get you a method pointer. It's just the address of the code. You'd also need the address of the subject. – David Heffernan Mar 10 '18 at 21:04
  • 1
    Anyway, in your position you can simply write another function that calls the constructor and pass that wrapper function to your library. – David Heffernan Mar 10 '18 at 21:11
  • Note that what you show are **not class constructors**, they are normal constructors. Class constructors only run once, before the *class* is used. http://docwiki.embarcadero.com/RADStudio/Tokyo/en/Methods_(Delphi)#Class_Constructors – Rudy Velthuis Mar 11 '18 at 02:35

0 Answers0