1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
...
TForm1 = class(TForm)
ComboBox1: TComboBox;
ComboBox2: TComboBox;
Button1: TButton;
Edit1: TEdit;
ComboBox3: TComboBox;
ComboBox4: TComboBox;
Button2: TButton;
procedure Button1Click(Sender: TObject);
private
{ Déclarations privées }
public
{ Déclarations publiques }
function getComboBox(ntag: word):TCombobox;
function calculate(Sender: TObject; var z: integer):boolean;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function somme(x,y: Tcombobox; var z: integer):boolean;
begin
Result := true;
if (x = nil) or (y = nil)
then begin
Result := false;
exit;
end;
z := strToInt(x.Text) + strToInt(y.Text);
end;
{ TForm1 }
function TForm1.calculate(Sender: TObject; var z: integer): boolean;
var x,y: integer;
begin
x := TButton(Sender).Tag div 100;
y := TButton(Sender).Tag mod 100;
Result := somme(getComboBox(x),getComboBox(y),z);
end;
function TForm1.getComboBox(ntag: word): TCombobox;
var I:integer;
begin
Result := nil;
for I := 0 to Pred(ComponentCount) do
if (Components[i] is TComboBox) and (Components.Tag = ntag)
then begin
Result := TComboBox(Components);
break;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var z:integer;
begin
if calculate(TButton(Sender),z)
then edit1.Text := intToStr(z);
end;
... |