tinterface10.pp 716 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. { %VERSION=1.1 }
  2. {$ifdef fpc}
  3. {$mode objfpc}
  4. {$endif}
  5. type
  6. ITest = interface(IUnknown)
  7. procedure DoSomething;
  8. end;
  9. TMyClass = class(TInterfacedObject, ITest)
  10. procedure MyDoSomething;
  11. procedure ITest.DoSomething = MyDoSomething;
  12. end;
  13. var
  14. i : longint;
  15. procedure TMyClass.MyDoSomething;
  16. begin
  17. inc(i);
  18. end;
  19. procedure DoTest(const ATest: ITest);
  20. begin
  21. ATest.DoSomething;
  22. end;
  23. procedure DoTest2(ATest: ITest);
  24. begin
  25. ATest.DoSomething;
  26. end;
  27. type TMyClassCopy = type TMyClass;
  28. var
  29. c: ITest;
  30. begin
  31. i:=0;
  32. c := TMyClassCopy.Create;
  33. DoTest(c);
  34. DoTest2(c);
  35. if i<>2 then
  36. begin
  37. writeln('Problem with passing interfaces as parameters');
  38. halt(1);
  39. end;
  40. end.