diff --git a/simple_examples/procedural_type.pas b/simple_examples/procedural_type.pas new file mode 100644 index 0000000..07e7738 --- /dev/null +++ b/simple_examples/procedural_type.pas @@ -0,0 +1,24 @@ +program procedural_type; + +{$mode objfpc}{$H+} + +// Interface for an event handler +// This is a 'procedural type' +type TOneStringParamProc = procedure(aString: string); + +var stringProc: TOneStringParamProc = nil; + +// A possible implementation +procedure ShowStr(s: string); +begin + WriteLn('The string passed to this procedure is ', s); +end; + +begin + // Use the event handler + stringProc := @ShowStr; + stringProc('"string parameter"'); + {$IFDEF WINDOWS} + ReadLn; + {$ENDIF} +end.