0

I am actually using dwscript with delphi and got stuck with the follwing problem:

I have defined two classes as follows

TClassOne = class
  private
   FName : String;
 public
   property Name: String read FName write FName;
end;

TClassTwo = class
  private
    FName      : String;
    FClassOne  : TClassOne;
  public
    property Name: String read FName write FName;
    property ClassOne: TClassOne read FClassOne write FClassOne;
end;

I am exposing both Classes to DWScript via ExposeRTTI:

dwsUnitExternal.ExposeRTTI(TypeInfo(TClassOne), [eoExposeVirtual, eoNoFreeOnCleanup, eoExposePublic]);
dwsUnitExternal.ExposeRTTI(TypeInfo(TClassTwo), [eoExposeVirtual, eoNoFreeOnCleanup, eoExposePublic]);

This basically is working, because when I insert the follwing lines

var myClassTwo : TClassTwo = TClassTwo.Create;
myClassTwo.Name := 'test';

var myClassOne : TClassOne = TClassOne.Create;
myClassOne.Name := 'abc';

myClassTwo.ClassOne := myClassOne;
myClassTwo.ClassOne.Name := 'xyz';  // Comiler error

var myClassOne2 : TClassOne;
myClassOne2 := myClassTwo.ClassOne; // Compiler error
myClassOne2 := (myClassTwo.ClassOne as TClassOne); // Compiler error

to a DWScript, the first 5 lines are properly compiled, but when I try to access the property of ClassOne within ClassTwo (6th line), compiler throws "no member expected". I understand that this is due to limited RTTI capabilities, but I have no idea how to solve this problem.

Does anybody know how to get access to myClassTwo.ClassOne.Name within the script? Same with Methods, btw.

Thanks in advance!

PS: Added 3 more lines to show more attempts - no success...

Radiesel
  • 371
  • 1
  • 3
  • 10
  • 1
    where did you assign classOne to ClassTwo?? – whosrdaddy Dec 20 '18 at 14:43
  • OK, correct, forgot that. But since there is a compiler error "no member expected" it never got executed. Compiler error still is at the last line. Question was how to get this solved. Thanks! – Radiesel Dec 20 '18 at 19:00
  • 1
    The ExposeRTTI functions did not really leave the experimental stage, as no way was found to ensure secure script sandboxing when using Delphi RTTI. To this day, I am still exposing Delphi classes only through TdwsUnit and extra layers of code to secure state, parameters and memory management. – Eric Grange Jan 31 '19 at 08:53
  • OK, understood, thank you Eric... – Radiesel Feb 04 '19 at 09:46

0 Answers0