Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save owlsperspective/1532a057fb25fdf23f04 to your computer and use it in GitHub Desktop.
Save owlsperspective/1532a057fb25fdf23f04 to your computer and use it in GitHub Desktop.
IfThen<T>をrecordで実装する
type
&IF = record
class function &Then<T>(AValue: Boolean; AThen: T; AElse: T): T; static; inline;
end;
class function &IF.&Then<T>(AValue: Boolean; AThen: T; AElse: T): T;
begin
if AValue then
begin
Result := AThen;
end
else
begin
Result := AElse;
end;
end;
var
I: Integer;
D: Double;
S: String;
B: TButton;
begin
I := &IF.&Then(False,1,2);
D := &IF.&Then(True,1.0,2.0);
S := &IF.&Then(False,'OK','NG');
B := &IF.&Then(Button1.Enabled,Button1,Button2);
end;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment