0

I'm overriding TRTTIEnvironment and am implementing function FindUnknownName(). I'd like to return a Symbol that is already exposed to the program by ExposeInstanceToUnit(). In some of my scripts the property of a global object is in the script but without the object. Eg. Global object "User" has property UserName. "UserName" is in the script NOT "User.UserName".

The code in FindUnknownName is

sym := compiler.CurrentProg.Table.FindSymbol("User", cvMagic);
result := TPropertySymbol(TClassSymbol(sym.Typ).Members.FindSymbol(name, cvMagic)).ReadSym;

Problem here is that it returns the class Symbol for the property and since it is not a class property it will AV.

Any help getting the property symbol for the instance of User greatly appreciated.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Tom Robertson
  • 151
  • 10
  • I'm not sure to understand what you use to back your symbol... If it's really a shortcut to an implicit class, then you can first lookup a reference to the variable (or other) that holds that class, and then lookup the members of that class. If you don't want to class variable to be accessible, you can create an anonymous variable (whose name is an empty string) and keep a reference to its symbol for yourself. Such a variable will only be accessible from Delphi-side code. – Eric Grange Jun 18 '13 at 07:57
  • Yes I guess the question boils down to how do I get the symbol for a property of "User". I can get the property from the class of "User" but not of the instance of "User". – Tom Robertson Jun 19 '13 at 00:16
  • Is the "User" instance on the script side or on the Delphi side? Ie. should the script behave like if it was compiled as a method of the User class? Or is it just a way to expose directly properties on the script-side of an object that exists on the Delphi side? – Eric Grange Jun 19 '13 at 14:44
  • User is on the Delphi side, exposed via ExposeInstanceToUnit. As the script does not contain a reference to User does that mean there will be no symbols created for the instance of User? All works fine if I put User.Username in the script. – Tom Robertson Jun 19 '13 at 23:10
  • Then a symbol isn't enough, since there is no single symbol that does what you want. One way would be to expose functions rather than an instance (f.i a UserName function), you can create those functions dynamically in FindUnknownName, this will allow you to return a single symbol( that of the function). – Eric Grange Jun 20 '13 at 11:52
  • Ok thanks Eric. I'll do that. – Tom Robertson Jun 21 '13 at 07:15

0 Answers0