From 1c31e8b8c46b52e04896aec452712d4cfda36f4a Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Tue, 5 Oct 2021 14:35:24 -0400 Subject: [PATCH] Add procedural type example --- simple_examples/procedural_type.pas | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 simple_examples/procedural_type.pas 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.