Cel :

Chcemy uzyskać efekt, aby po wpisaniu liczb w oba pola i wciśnięciu przycisku została wyświetlona suma tych liczb.


Końcowy efekt :


Potrzebne komponenty :


Metoda :

1) Wstawiamy komponenty, wypisane.w powyższej tabeli i zmieniamy im właściwość name na taką jaka jest w kolumnie "Nazwa"

2) Zmieniamy właściwości Caption lub Text według własnego uznania lub sugerując się rysunkiem

3) Do obsługi funkcji OnClick przycisku dodajemy poniższy kod:

procedure TForm1.Button1Click(Sender: TObject);
var
X, Y, Z : Integer;
begin
X := StrToInt(Edit1.text);
Y := StrToInt(Edit2.text);
Z := X + Y;
Label3.Caption := IntToStr(Z);

4) Uruchamiamy program.


Porady :

Zmieniając znak działania na +, -, /, * zmienia się sposub wykonywania działania.

Kod źródłowy :

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;

type
TForm1 = class(TForm)
Edit1: TEdit;
Label1: TLabel;
Edit2: TEdit;
Label2: TLabel;
Label3: TLabel;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var
X, Y, Z : Integer;
begin
X := StrToInt(Edit1.text);
Y := StrToInt(Edit2.text);
Z := X + Y;
Label3.Caption := IntToStr(Z);
end;

end.