MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.
Add your voice to the tech community where 5M+ people just like you are talking about what matters.
unit CommonFunctions;
interface
uses
Math, StrUtils, SysUtils, classes;
//the 3 IfThen from Math
function IfThen(AValue: Boolean; const ATrue: Integer; const AFalse: Integer = 0): Integer; overload;
function IfThen(AValue: Boolean; const ATrue: Int64; const AFalse: Int64): Int64; overload;
function IfThen(AValue: Boolean; const ATrue: Double; const AFalse: Double = 0.0): Double; overload;
// then the IfThen from StrUtils
function IfThen(AValue: Boolean; const ATrue: string; AFalse: string = ''): string; overload;
//and finally your own ifthen
function IfThen(AValue: Boolean; const ATrue: char; AFalse: char): TStrings; overload;
implementation
//the 3 IfThen from Math
function IfThen(AValue: Boolean; const ATrue: Integer; const AFalse: Integer = 0): Integer;
begin
result := Math.IfThen(AValue, ATrue, AFalse);
end;
function IfThen(AValue: Boolean; const ATrue: Int64; const AFalse: Int64): Int64;
begin
result := Math.IfThen(AValue, ATrue, AFalse);
end;
function IfThen(AValue: Boolean; const ATrue: Double; const AFalse: Double): Double;
begin
result := Math.IfThen(AValue, ATrue, AFalse);
end;
// then the IfThen from StrUtils
Function IfThen(AValue: Boolean; const ATrue: string; AFalse: string = ''): string;
begin
result := StrUtils.IfThen(AValue, ATrue, AFalse);
end;
//and finally your own ifthen
Function IfThen(AValue: Boolean; const ATrue: char; AFalse: char): TStrings;
begin
result.Add(ATrue);
result.Add(AFalse);
end;
end.
Then you can call any IfThen just by adding CommonFunctions in the uses (no math or strutils necessary now) as followsunit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses
CommonFunctions;
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
s: TStrings;
begin
ShowMEssage(IntToStr(IfThen(true, 10, 20))); //from math
ShowMEssage(IfThen(true, 'True', 'False')); //from strutils
s := TStringList.create;
s.AddStrings(IfThen(false, 'a', 'z')); //and your own
ShowMEssage(s[0]);
ShowMEssage(s[1]);
s.Free;
end;
end.
If you are experiencing a similar issue, please ask a related question
Title | # Comments | Views | Activity |
---|---|---|---|
Working this component WebCopy with proxy, help | 3 | 100 | |
Correct Component for Shopping Cart. | 2 | 121 | |
update joined tables | 2 | 62 | |
firemonkey Android Listview Sort items | 7 | 72 |
Join the community of 500,000 technology professionals and ask your questions.