tw2059.pp 950 B

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