Kod: Tümünü seç
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,strutils;
type
TForm1 = class(TForm)
Edit1: TEdit;
Memo1: TMemo;
procedure Edit1KeyPress(Sender: TObject; var Key: Char);
private
function icindebul(ara,metin:string):integer;
function topla(s:string):double;
function cikar(s:string):double;
function islemyap(s:string):double;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function TForm1.icindebul(ara, metin: string): integer;
var
i:integer;
begin
if length(metin)<length(ara) then
begin
result:=1050;
exit;
end;
for i:=1 to length(metin)-length(ara)+1 do
begin
if copy(metin,length(metin)-length(ara)+1-i,length(ara))=ara then
begin
if length(metin)=length(ara) then
result:=0
else
result:=i;
exit;
end;
end;
result:=1050;
end;
function TForm1.islemyap(s: string): double;
var
t,c:integer;
q:string;
begin
result:=1050E22;
t:=icindebul('TOPLA(',s);
c:=icindebul('çıKAR(',s);
if (t=1050) and (c=1050) then
begin
result:=strtofloat(s);
exit;
end;
if (c<t) and (c>0) then
begin
q:=copy(s,length(s)-c-6+1,c+6);
q:=copy(q,1,ansipos(')',q));
q:=ansireplacestr(s,copy(q,length(q)-6-c+1,6+c),floattostr(cikar(copy(q,length(q)-6-c+1,6+c))));
result:=islemyap(q);
end;
if (t<c) and (t>0) then
begin
q:=copy(s,length(s)-t-6+1,t+6);
q:=copy(q,1,ansipos(')',q));
q:=ansireplacestr(s,copy(q,length(q)-6-t+1,6+t),floattostr(topla(copy(q,length(q)-6-t+1,6+t))));
result:=islemyap(q);
end;
end;
function TForm1.cikar(s: string): double;
var
i,j,k:integer;
s1,s2:double;
begin
i:=ansipos('(',s);
j:=ansipos(',',s);
k:=ansipos(')',s);
s1:=strtofloat(copy(s,i+1,j-i-1));
s2:=strtofloat(copy(s,j+1,k-j-1));
result:=s1-s2;
end;
function TForm1.topla(s:string): double;
var
i,j,k:integer;
s1,s2:double;
begin
i:=ansipos('(',s);
j:=ansipos(',',s);
k:=ansipos(')',s);
s1:=strtofloat(copy(s,i+1,j-i-1));
s2:=strtofloat(copy(s,j+1,k-j-1));
result:=s1+s2;
end;
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if key=#13 then
memo1.lines.add(floattostr(islemyap(uppercase(edit1.text))));
end;
end.
Böyle bir şeyler yaptım. Gayet iyi çalışıyor. Ancak yine de farklı bir yol öneriniz varsa memnuniyet ile ilgilenirim..