Guest User

Freepascal Helper Scope Test

a guest
Oct 5th, 2013
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 0.94 KB | None | 0 0
  1. program HelperScopeTest;
  2.  
  3. type
  4.  
  5. { TMyObject }
  6.  
  7. TMyObject = class
  8. public
  9.       function GetString: string;
  10.       function GetAnotherString: string;
  11. end;
  12.  
  13. //=====Location A
  14. //Prints
  15. //       Helper String
  16. //       Object String
  17.  
  18.  
  19. //--- Block to move ---------------------------------
  20. function TMyObject.GetAnotherString: string;
  21. begin
  22.      result:=GetString;
  23. end;
  24.  
  25. function TMyObject.GetString: string;
  26. begin
  27.      result:='Object String';
  28. end;
  29. //---------------------------------------------------
  30.  
  31.  
  32. type
  33.     TMyObjectHelper = class helper for TMyObject
  34.       function GetString: string;
  35.     end;
  36.  
  37. //=====Location B
  38. //Prints
  39. //       Helper String
  40. //       Helper String
  41.  
  42.  
  43.  
  44.  
  45. function TMyObjectHelper.GetString: string;
  46. begin
  47.      result:='Helper String';
  48. end;
  49.  
  50. begin
  51.      with TMyObject.Create do
  52.      begin
  53.           WriteLn(GetString);
  54.           WriteLn(GetAnotherString);
  55.           Free;
  56.      end;
  57. end.
Add Comment
Please, Sign In to add comment