SHARE
TWEET

FPC TObject Helper Self

a guest Mar 16th, 2013 46 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. program Project1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. uses
  6.     Classes, sysutils;
  7.  
  8. type
  9.     TObjHelper = class helper for TObject
  10.         function HelperSelf: TObject;
  11.     end;
  12.  
  13.  
  14. function TObjHelper.HelperSelf: TObject;
  15. begin
  16.      result:=self;
  17. end;
  18.  
  19.  
  20. type
  21.     TNewType = class
  22.        var
  23.           Name: string;
  24.        procedure WriteName(nt: TNewType);
  25.  
  26.     end;
  27.  
  28. procedure TNewType.WriteName(nt: TNewType);
  29. begin
  30.      WriteLn('Object name=>', QuotedStr(nt.Name));
  31. end;
  32.  
  33. var
  34.    o: TObject;
  35.    nt1, nt2: TNewType;
  36. begin
  37.      nt1:=TNewType.Create;
  38.      nt1.Name:='nt1';
  39.  
  40.      nt2:=TNewType.Create;
  41.      nt2.Name:='nt2';
  42.  
  43.      with nt1 do
  44.         nt2.WriteName(HelperSelf as TNewType);
  45.  
  46.      nt1.WriteName(nt2);
  47. end.
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top