Q&A

  • 잠깐들 시간점 내셔서 갈쿄주세욤.....(왕초보)
계산기 만드는데요...잠깐들 시간점 내셔서 점 갈쿄 주세욤...
음..폼하구 다 돼는데요...에러두 안나구....근데 제가 구현하려고 했던것은
계산기 폼에서 '+','-'...등등..이런거 누르면 그때까지의 연산된 total이 표시돼게 할려구 했는데...안돼네요..글거...'='이거 눌러도 합계가 안나와요...
왜 그럴까요...소스 올릴테니 점 갈쿄주세욤..
<소스>

unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    Button5: TButton;
    Button6: TButton;
    Button7: TButton;
    Button8: TButton;
    Button9: TButton;
    Button0: TButton;
    ButtonEq: TButton;
    ButtonPl: TButton;
    ButtonMi: TButton;
    ButtonMu: TButton;
    ButtonDi: TButton;
    ButtonC: TButton;
    ButtonAC: TButton;
    ButtonMod: TButton;
    entry: TRitEdit1;
    procedure Button0Click(Sender: TObject);
    procedure ButtonPlClick(Sender: TObject);
    procedure ButtonMiClick(Sender: TObject);
    procedure ButtonMuClick(Sender: TObject);
    procedure ButtonDiClick(Sender: TObject);
    procedure ButtonCClick(Sender: TObject);
    procedure ButtonACClick(Sender: TObject);
    procedure ButtonModClick(Sender: TObject);
    procedure ButtonEqClick(Sender: TObject);
    procedure entryChange(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  complete: boolean;
  total: integer;
  operator: char;
implementation

{$R *.DFM}
function strtoint(s: string): integer;
var
l: integer;
begin
strtoint:= l;
end;

function inttostr(l: integer): string;
var
s: string;
begin

inttostr:= s;
end;

procedure clc(number: integer; next: char);
begin
  if {not} complete{ or (total=0) }then
  case operator of
        '+': total:= total+ number;
        '-': total:= total- number;
        '*': total:= total* number;
        '%': total:= total div number;
        'm': total:= total mod number;
  end;
operator:= next;
complete:= true;
end;


procedure TForm1.Button0Click(Sender: TObject);
begin
if complete then entry.text:= '';
case (sender as tbutton).tag of
      0: entry.text:= entry.text+ '0';
      1: entry.text:= entry.text+ '1';
      2: entry.text:= entry.text+ '2';
      3: entry.text:= entry.text+ '3';
      4: entry.text:= entry.text+ '4';
      5: entry.text:= entry.text+ '5';
      6: entry.text:= entry.text+ '6';
      7: entry.text:= entry.text+ '7';
      8: entry.text:= entry.text+ '8';
      9: entry.text:= entry.text+ '9';
end;
end;

procedure TForm1.ButtonPlClick(Sender: TObject);
begin
clc(strtoint(entry.text),'+');
entry.text:= inttostr(total);
end;

procedure TForm1.ButtonMiClick(Sender: TObject);
begin
clc(strtoint(entry.text),'-');
entry.text:= inttostr(total);
end;

procedure TForm1.ButtonMuClick(Sender: TObject);
begin
clc(strtoint(entry.text),'*');
entry.text:= inttostr(total);
end;

procedure TForm1.ButtonDiClick(Sender: TObject);
begin
clc(strtoint(entry.text), '%');
entry.text:= inttostr(total);
end;

procedure TForm1.ButtonCClick(Sender: TObject);
begin
entry.text:= '0';
complete:= true;
end;

procedure TForm1.ButtonACClick(Sender: TObject);
begin
entry.text:= '0';
total:= 0;
complete:= true;
end;

procedure TForm1.ButtonModClick(Sender: TObject);
begin
clc(strtoint(entry.text), 'm');
entry.text:= inttostr(total);
end;

procedure TForm1.ButtonEqClick(Sender: TObject);
begin
clc(strtoint(entry.text),operator);
entry.text:= inttostr(total);
end;

procedure TForm1.entryChange(Sender: TObject);
begin
if entry.text= '' then complete:= false;
end;

end.
1  COMMENTS