tinterface9.pp 839 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. { %VERSION=1.1 }
  2. { %SKIPTARGET=macos }
  3. { On macos it crashes when run.}
  4. {$mode objfpc}
  5. type
  6. IInterface = interface(IUnknown)
  7. procedure mydo;
  8. end;
  9. TMyClass = class(TInterfacedObject, IInterface)
  10. procedure mydo;virtual;
  11. end;
  12. TMyClassCopy = type TMyClass;
  13. TMyClass2 = class(TMyClassCopy)
  14. i : integer;
  15. end;
  16. TMyClass3 = class
  17. private
  18. fi: IInterface;
  19. public
  20. property intf: IInterface read fi write fi;
  21. end;
  22. var
  23. l : longint;
  24. procedure tmyclass.mydo;
  25. begin
  26. l:=1;
  27. end;
  28. var
  29. c: TMyClassCopy;
  30. c2 : TMyClassCopy;
  31. c3 : TMyClass3;
  32. begin
  33. c := TMyClassCopy.Create;
  34. c3 := TMyClass3.Create;
  35. c3.intf := c;
  36. l:=0;
  37. c3.intf.mydo;
  38. if l<>1 then
  39. halt(1);
  40. c2 := TMyClass2.Create;
  41. c3.intf := c2;
  42. l:=0;
  43. c3.intf.mydo;
  44. if l<>1 then
  45. halt(1);
  46. c3.free;
  47. end.