Guest User

Untitled

a guest
Jun 29th, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.26 KB | None | 0 0
  1. program Project1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. type
  6.   IChainer = interface['{07515829-4A17-463B-8E34-6AEA42CC9C3F}']
  7.     function Chain: IChainer; stdcall;
  8.     procedure Done; stdcall;
  9.   end;
  10.  
  11.   TChainer = class(TInterfacedObject, IChainer)
  12.     function _AddRef: longint; stdcall;
  13.     function _Release: longint; stdcall;
  14.     function Chain: IChainer; stdcall;
  15.     procedure Done; stdcall;
  16.   end;
  17.  
  18. { TChainer }
  19.  
  20. function TChainer._AddRef: longint; stdcall;
  21. begin
  22.   Result:=inherited _AddRef;
  23.   Writeln('Addref: ',HexStr(Pointer(Self)),' Refcount: ',RefCount,' at ',hexstr(get_caller_addr(get_frame)));
  24. end;
  25.  
  26. function TChainer._Release: longint; stdcall;
  27. begin              
  28.   Writeln('Release: ',HexStr(Pointer(Self)),' Refcount: ',RefCount,' at ',hexstr(get_caller_addr(get_frame)));
  29.   Result:=inherited _Release;
  30. end;
  31.  
  32. function TChainer.Chain: IChainer; stdcall;
  33. begin
  34.   Writeln('Chain: ',HexStr(Pointer(Self)));
  35.   Result:= Self as IChainer;
  36. end;
  37.  
  38. procedure TChainer.Done; stdcall;
  39. begin
  40.   Writeln('Done: ',HexStr(Pointer(Self)));
  41. end;
  42.  
  43. function GetChainer:IChainer;
  44. begin
  45.   Result:= TChainer.Create as IChainer;
  46. end;
  47.  
  48. procedure Test;
  49. begin
  50.   GetChainer.
  51.     Chain.
  52.     Chain.
  53.     Done;
  54.   Writeln('fin');
  55. end;
  56.  
  57. begin
  58.   Test;
  59.   Readln;
  60. end.
Advertisement
Add Comment
Please, Sign In to add comment