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