tb0356.pp 577 B

123456789101112131415161718192021222324252627
  1. {$mode objfpc}
  2. type
  3. tc = class
  4. left,right: tc;
  5. function test(var c: tc): boolean;
  6. end;
  7. testfunc = function(var c: tc):boolean of object;
  8. function foreach(var c: tc; p: testfunc): boolean;
  9. begin
  10. if not assigned(c) then
  11. exit;
  12. end;
  13. function tc.test(var c: tc): boolean;
  14. begin
  15. { if you use @test, the compiler tries to get the address of the }
  16. { function result instead of the address of the method (JM) }
  17. result := foreach(c.left,@self.test);
  18. result := foreach(c.right,@self.test) or result;
  19. end;
  20. begin
  21. end.