Znaci treba da napravim kalkulator koji izgleda ovako:
Napisao sam kod za racunske operacije ali kad kliknem RUN pojavi se ova poruka:
Evo ga kompletan kod:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
rez: TEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
ComboBox1: TComboBox;
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure ComboBox1Change(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
close
end;
procedure TForm1.ComboBox1Change(Sender: TObject);
begin
case combobox1.itemindex of
0:rez.text:=floattostr(strtofloat(edit1.Text)+strtofloat(edit2.Text));
1:rez.text:=floattostr(strtofloat(edit1.Text)-strtofloat(edit2.Text));
2:rez.text:=floattostr(strtofloat(edit1.Text)*strtofloat(edit2.Text));
3:if(strtofloat(edit2.Text)=0)
then begin
showmessage('deljenje nulom');edit2.SetFocus;
end
else rez.Text:=floattostr(strtofloat(edit1.Text)/strtofloat(edit2.Text));
end
end.
|