Add procedural type example
This commit is contained in:
parent
06d0b981b7
commit
1c31e8b8c4
24
simple_examples/procedural_type.pas
Normal file
24
simple_examples/procedural_type.pas
Normal file
@ -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.
|
Loading…
Reference in New Issue
Block a user