tw2059.pp 956 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. {$mode tp}
  2. {$F+}
  3. type ProcType = procedure(s:string);
  4. GetProcType = function(s:string;var Proc:ProcType):boolean;
  5. var ProcVar : ProcType;
  6. GetProcVar : GetProcType;
  7. procedure Default(s:string);
  8. begin
  9. writeln('This is Default:',s);
  10. end;
  11. procedure Proc1(s:string);
  12. begin
  13. writeln('This is Proc1:',s);
  14. end;
  15. procedure Proc2(s:string);
  16. begin
  17. writeln('This is Proc2:',s);
  18. end;
  19. function GetProc(s:string;var ProcVar:ProcType):boolean;
  20. begin
  21. if s='Proc1' then begin
  22. ProcVar:=Proc1;
  23. GetProc:=true;
  24. end
  25. else
  26. if s='Proc2' then begin
  27. ProcVar:=Proc2;
  28. GetProc:=true;
  29. end
  30. else begin
  31. ProcVar:=Default;
  32. GetProc:=false;
  33. end;
  34. end;
  35. begin
  36. GetProcVar:=GetProc;
  37. if GetProcVar('Proc1',ProcVar) then
  38. ProcVar('ok')
  39. else
  40. halt(1);
  41. if GetProcVar('Proc2',ProcVar) then
  42. ProcVar('ok')
  43. else
  44. halt(1);
  45. if GetProcVar('xyz',ProcVar) then
  46. halt(1)
  47. else
  48. writeln('ok');
  49. end.