الكود التالي يبين لنا كيفية استعمال تعليمات أختبار if للتحقق من كون شرط معين محققا أم لا :
interface uses System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.StdCtrls, FMX.Edit, FMX.Controls.Presentation, FMX.ScrollBox, FMX.Memo; type TForm1 = class(TForm) Memo1: TMemo; Button1: TButton; Button2: TButton; Button3: TButton; Edit1: TEdit; CheckBox1: TCheckBox; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Button3Click(Sender: TObject); private { Déclarations privées } public { Déclarations publiques } procedure Show(const msg: string); end; var Form1: TForm1; implementation uses Character; {$R *.fmx} procedure TForm1.Button1Click(Sender: TObject); var isChecked: Boolean; begin isChecked := CheckBox1.isChecked; if isChecked then Show('Checkbox is checked'); end; procedure TForm1.Button2Click(Sender: TObject); begin // if-then-else statement if CheckBox1.isChecked then Show('Checkbox is checked') else Show('Checkbox is not checked'); end; procedure TForm1.Button3Click(Sender: TObject); var aChar: Char; begin /// multiple nested if statements if Edit1.Text.Length > 0 then begin aChar := Edit1.Text.Chars[0]; // checks for a lowercase char (two conditions) if (aChar >= 'a') and (aChar <= 'z') then Show('char is lowercase'); // follow up conditions if aChar <= Char(47) then Show('char is lower symbol') else if (aChar >= '0') and (aChar <= '9') then Show('char is a number') else Show('char is not a number or lower symbol'); end; end; procedure TForm1.Show(const msg: string); begin Memo1.Lines.Add(msg); end; end.