问题
Imagine this procedure, which is callable in a script:
// Foo is not implemented in the Script but via Delphi
procedure Foo(ClassType: TClass);
The Script looks like that:
type
TMyClass = class
end;
Foo(TMyClass);
When Foo gets called my Delphi App sees an Int64-Value for the ClassType.
e.g. Foo(661259635);
You can see in the DWS sources that a TClass
is explicitly converted to an Int64
(see dwsCompiler.pas, procedure TObjectClassTypeMethod.Execute -> Info.ResultAsInteger := Int64(info.ValueAsClassSymbol[SYS_SELF]);
).
Now in which structure I can search for that number to find the corresponding TdwsClass?
Note: In fact TMyClass is not implemented in the script, but created exposed via the Delphi App...I don't know if this makes a difference.
回答1:
You currently have to cast the Int64 back to a TClassSymbol manually, the conversion is performed to store the reference in a Variant (which doesn't support TClass).
Once you have the TClassSymbol, you can lookup the symbol table, or navigate to the members.
There is at the moment no IInfo helper to class symbols.
来源:https://stackoverflow.com/questions/7109376/delphi-web-script-how-to-find-the-class-name-of-a-script-tclass-in-delphi