| Example
One
This example demonstrates how to do some basic calculation for given
data.

Download this example
On
this example just set following three events as shown here.
1)
Form create event
procedure TForm1.FormCreate(Sender: TObject);
begin
{ Initialize the labels }
Label6.Caption:='0.00';
Label7.Caption:='0.00';
Label8.Caption:='0.00';
{ Initialize the edit boxes }
Edit1.Text:='0.00';
Edit2.Text:='0.00';
end;
2)
(Calculate button) on click event
procedure TForm1.Button1Click(Sender: TObject);
Var
V1, V2, VSum, VSub, VMul : Variant;
begin
{ Variant type variables are very easy to
use
these can hold any data type. And the advantage
is you can convert them into any data type easily }
V1:=Edit1.Text;
V2:=Edit2.Text;
{ function Real() convert the variant to a
real no. }
VSum:=Real(V1)+Real(V2);
VSub:=Real(V1)-Real(V2);
VMul:=Real(V1)*Real(V2);
{ Put the results back in labels . . . }
Label6.Caption:=VSum;
Label7.Caption:=VSub;
Label8.Caption:=VMul;
end;
3)
(Exit button) on click event.
procedure TForm1.Button2Click(Sender: TObject);
begin
{ Close the form }
Close;
end;
DOWNLOAD this example
Click
here
to download this complete example for Delphi 6. (File size 4 KB)


|