How to access properties or methods of another class object within a class in DWScript?

221 Views Asked by At

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...

0

There are 0 best solutions below