timplements2.pp 639 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. {$ifdef fpc}
  2. {$mode objfpc}
  3. {$endif fpc}
  4. uses
  5. classes;
  6. type
  7. to1 = class(TObject,IInterface)
  8. fi : IInterface;
  9. function getfi : IInterface;
  10. property i : IInterface read getfi implements IInterface;
  11. end;
  12. function to1.getfi : IInterface;
  13. begin
  14. result:=fi;
  15. end;
  16. var
  17. o1 : to1;
  18. i1,i2 : IInterface;
  19. begin
  20. o1:=to1.create;
  21. o1.fi:=TInterfacedObject.Create;
  22. i1:=o1;
  23. i1.QueryInterface(IInterface,i2);
  24. if i2=nil then
  25. halt(1);
  26. o1.fi:=nil;
  27. i1.QueryInterface(IInterface,i2);
  28. if i2=nil then
  29. halt(1);
  30. o1.free;
  31. i1.QueryInterface(IInterface,i2);
  32. if i2=nil then
  33. halt(1);
  34. writeln('ok');
  35. end.