fork download
  1. {$APPTYPE CONSOLE}
  2. {$IFDEF FPC}
  3. {$MODE Delphi}
  4. {$ENDIF}
  5.  
  6. type
  7.  
  8. PB = ^B;
  9. B = object
  10. public
  11. test: string;
  12.  
  13. constructor Init;
  14.  
  15. function GetTest: string;
  16. end;
  17.  
  18. PA = ^A;
  19. A = object
  20. public
  21. function TestFunc: string;
  22. end;
  23.  
  24. function A.TestFunc;
  25. begin
  26. Writeln('>> this.test = ', PB(@self)^.test);
  27. Result := PB(@self)^.test
  28. end;
  29.  
  30. constructor B.init;
  31. begin
  32. self.test := 'Nice trick';
  33. end;
  34.  
  35. function B.GetTest;
  36. begin
  37. Result := PA(@self)^.TestFunc;
  38. end;
  39.  
  40. var theb: PB;
  41. begin
  42. theb := new(PB, Init);
  43. Writeln(theb^.GetTest())
  44. end.
  45.  
Success #stdin #stdout 0s 4340KB
stdin
Standard input is empty
stdout
>> this.test = Nice trick
Nice trick