또다른 계산기 프로그램 소스입니다.
도움이 되셨기를...
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Button5: TButton;
Button6: TButton;
Button7: TButton;
Button8: TButton;
Button9: TButton;
Button10: TButton;
Button11: TButton;
Button12: TButton;
Button13: TButton;
Button14: TButton;
Button15: TButton;
Button16: TButton;
dap: TPanel;
procedure Button10Click(Sender: TObject);
procedure Button16Click(Sender: TObject);
procedure Button15Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
chk : boolean;
flag : integer;
su1, su2 : integer;
implementation
{$R *.DFM}
procedure TForm1.Button10Click(Sender: TObject);
begin
if not chk then dap.caption := '';
if dap.caption = '0' then dap.caption := '';
chk := true;
case TComponent(Sender).Tag of
0: dap.caption := dap.caption + '0';
1: dap.caption := dap.caption + '1';
2: dap.caption := dap.caption + '2';
3: dap.caption := dap.caption + '3';
4: dap.caption := dap.caption + '4';
5: dap.caption := dap.caption + '5';
6: dap.caption := dap.caption + '6';
7: dap.caption := dap.caption + '7';
8: dap.caption := dap.caption + '8';
9: dap.caption := dap.caption + '9';
10..13 : begin
flag := TComponent(Sender).Tag;
if dap.caption = '' then showmessage('Error!!!')
else su1 := strtoint(dap.caption);
chk := false;
end;
end;
end;
procedure TForm1.Button16Click(Sender: TObject);
begin
dap.caption := '0';
flag := -1;
su1 := 0;
su2 := 0;
end;
procedure TForm1.Button15Click(Sender: TObject);
var
res : integer;
begin
// 계산
su2 := strtoint(dap.caption);
chk := false;
res := 0;
case flag of
-1 : begin
showmessage('연산자가 정의되지 않았습니다');
end;
10 : res := su1 + su2;
11 : res := su1 - su2;
12 : res := su1 * su2;
13 : res := su1 div su2;
end;
dap.caption := floatTostr(res);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
chk := false;
dap.caption := '0';
flag := -1;
su1 := 0;
su2 := 0;
end;
end.