fork download
  1. {$APPTYPE CONSOLE}
  2. {$IFDEF FPC}
  3. {$MODE DELPHI}
  4. {$ENDIF}
  5. uses SysUtils;
  6.  
  7. type
  8. users_t = (tarasB, superhackkiller1997, other_shit);
  9. say_ptr_t = procedure (str: PChar) of object;
  10. anon_class_t = class(TObject)
  11. anon_field1: users_t;
  12. constructor Create(usr: users_t);
  13. procedure anon_method(str: PChar);
  14. end;
  15. const
  16. users: array[users_t] of PChar = ('tarasB', 'superhackkiller1997', 'other_shit');
  17.  
  18. procedure anon_class_t.anon_method(str: PChar);
  19. begin
  20. Writeln(ErrOutput, Format('%s: %s', [users[anon_field1], str]))
  21. end;
  22.  
  23. constructor anon_class_t.Create(usr: users_t);
  24. begin
  25. inherited Create;
  26. anon_field1 := usr;
  27. end;
  28.  
  29.  
  30. function bind(usr: users_t): say_ptr_t; export;
  31. begin
  32. bind := anon_class_t.Create(usr).anon_method
  33. end;
  34.  
  35. begin
  36. bind(tarasB)('shit');
  37. bind(superhackkiller1997)('i''m god');
  38. bind(other_shit)('ko-ko-ko')
  39. end.
stdin
Standard input is empty
stdout
Standard output is empty
stderr
tarasB: shit
superhackkiller1997: i'm god
other_shit: ko-ko-ko