unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls;
type
{ TForm1 }
TForm1 = class(TForm)
Edit1: TEdit;
Label1: TLabel;
procedure Edit1Change(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.Edit1Change(Sender: TObject);
var
i: integer;
a, b: single;
c, sign: char;
digits: string;
line: string;
result: string;
begin
digits := '';
sign := ' ';
a := 0;
b := 0;
line := Edit1.Text;
try
for i := 1 to length(line) do begin
c := line[i];
if (c='+') or (c='-') or (c='*') or (c='/') then begin
a := StrToFloat(digits);
digits := '';
sign := c;
end else
if c = '=' then begin
b := StrToFloat(digits);
digits := '';
result := '';
if sign='+' then result := FloatToStr(a + b);
if sign='-' then result := FloatToStr(a - b);
if sign='*' then result := FloatToStr(a * b);
if sign='/' then result := FloatToStr(a / b);
Edit1.Text := copy(line, 1, i) + result;
end else begin
digits := digits + c;
end;
end;
except end;
end;
end.