示例1:
{$mode objfpc}
uses sysutils;
var
a:integer = 12345;
b:integer = 54321;
begin
writeln(specialize ifthen<integer>(b > a,a,b));
writeln(specialize ifthen<integer>(b <= a,a,b));
end.
示例2:
program tifthen;
{$mode objfpc}
uses
SysUtils;
type
TTest = class
f: LongInt;
end;
var
t: TTest;
procedure DoTest;
begin
{ with $B+ this would crash if t is Nil }
Writeln(specialize IfThen<LongInt>(Assigned(t) and (t.f = 42), 1, 2));
end;
begin
t := Nil;
DoTest;
t := TTest.Create;
DoTest;
t.f := 42;
DoTest;
end.