?? u_point24.~pas
字號:
PluPos:=200; //將PluPos設置成一個不可能的值
if (MulPos=0) then //如果沒有*號
MulPos:=200; //將MulPos設置成一個不可能的值
if (DivPos=0) then //如果沒有/號
DivPos:=200; //將DivPos設置成一個不可能的值
Operator:='-';
tempPos:=SubPos;
if(tempPos>PluPos) then
begin
tempPos:=PluPos;
Operator:='+';
end;
if(tempPos>MulPos) then
begin
tempPos:=MulPos;
Operator:='*';
end;
if(tempPos>DivPos) then
begin
//tempPos:=DivPos;
Operator:='/';
end;
Result:=Operator; //結束函數,返回位置
end;
//此計算用于計算不帶()號的加、減、乘、除運算
function TFrm_Point.SubCompute(Str: String): integer;
var
Middle:String;
Mul2:String;
Right:String;
First:integer;
tempStr:String;
temp:integer;
Left:String;
Mul1:String;
MulPos:Integer;
DivPos:Integer;
Fuhao:Char;
begin
Middle:='';
Mul2:='';
Right:='';
//定位第一個^號位置 ,計算乘方
First:=Pos('^',Str);
while (First<>0) do//循環計算乘方
begin
tempStr:=Copy(Str,1,First-1);
temp:=AnyLastPos(tempStr);
Left:=Copy(Str,1,temp);
Mul1:=Copy(str,temp+1,First-temp-1);
tempStr:=Copy(str,First+1,Length(str)-First);
temp:=AnyFirstPos(tempStr);
if(temp=200) then
begin
Mul2:=tempStr;
Right:='';
end
else
begin
Mul2 :=Copy(tempStr,1,temp-1);
Right:=Copy(tempStr,temp,Length(tempStr)-temp+1);
end;
Middle:=FloatToStr(IntPower(StrToInt(Mul1),StrToInt(Mul2)));
Str:=Left+Middle+Right;
First:=Pos('^',Str);
end;
//定位第一個*號或/號的位置
MulPos:=Pos('*',Str);
DivPos:=Pos('/',Str);
First:=MulPos;
if (MulPos>DivPos) then
First:=DivPos;
if ((DivPos=0) and (MulPos<>0)) then
begin
First:=MulPos;
DivPos:=2000; // 將除號所在位置設置成一個大于MulPos但又不可能的值
end;
if ((DivPos<>0) and (MulPos=0)) then
begin
First:=DivPos; // 將乘號所在位置設置成一個大于DivPos但不可能的值
MulPos:=2000;
end;
while(First<>0) do//循環計算乘、除
begin
tempStr:=Copy(Str,1,First-1);
temp:=AnyLastPos(tempStr);
Left:=Copy(Str,1,temp);
Mul1:=Copy(Str,temp+1,First-temp-1);
tempStr:=Copy(Str,First+1,Length(Str)-First);
temp:=AnyFirstPos(tempStr);
if(temp=200) then
begin
Mul2:=tempStr;
Right:='';
end
else
begin
Mul2 :=Copy(tempstr,1,temp-1);
Right:=Copy(tempStr,temp,Length(tempStr)-temp+1);
end;
if(MulPos>DivPos) then
Middle:=IntToStr(StrToInt(Mul1) div StrToInt(Mul2))
else
Middle:=IntToStr(StrToInt(Mul1)*StrToInt(Mul2));
Str:=Left+Middle+Right;
MulPos:=Pos('*',Str);
DivPos:=Pos('/',Str);
First:=MulPos;
if (MulPos>DivPos) then
First:=DivPos;
if((DivPos=0) and (MulPos<>0)) then
begin
First:=MulPos;
DivPos:=2000; // 將除號所在位置設置成一個大于MulPos但又不可能的值
end;
if((DivPos<>0) and (MulPos=0)) then
begin
First:=DivPos; // 將乘號所在位置設置成一個大于DivPos但不可能的值
MulPos:=2000;
end;
end;
//定位+、-號首先出現的位置
First:=AnyFirstPos(Str);
if (First=200) then//如果沒有+、-號,則可以直接返回結果
begin
SubCompute:=StrToInt(Str);
exit;
end;
Fuhao:=AnyFirstF(Str); //確定首先出現的符號是+號還是-號
while (First<>0) do
begin
//如果找到+號或-號
tempStr:=Copy(Str,1,First-1);
temp:=AnyLastPos(tempStr);
Left:=Copy(Str,1,temp);
Mul1:=Copy(Str,temp+1,First-temp-1);
tempStr:=Copy(Str,First+1,Length(Str)-First);
temp:=AnyFirstPos(tempStr);
if(temp=200) then
begin
Mul2:=tempStr;
Right:='';
end
else
begin
Mul2 :=Copy(tempStr,1,temp-1);
Right :=Copy(tempStr,temp,Length(tempStr)-temp+1);
end;
if (Fuhao='+') then
Middle:=IntToStr(StrToInt(Mul1)+StrToInt(Mul2))
else
Middle:=IntToStr(StrToInt(Mul1)-StrToInt(Mul2));
Str:=Left+Middle+Right;
First:=AnyFirstPos(Str);
if (First=200) then break;
Fuhao:=AnyFirstF(Str);
end;
Result:=StrToInt(Middle);
end;
//用于計算表達式的結果
function TFrm_Point.TotalCompute(Str: String): integer;
var
First:integer;
Last:integer;
SubStr:String;
LeftStr:String;
Middle:String;
Right:String;
temp:integer;
begin
First:=LastDelimiter ('(',Str); //定位最后一個(號位置
while(First<>0) do
begin
SubStr:=Copy(Str,First+1,Length(Str)-First);
Last:= Pos (')',SubStr);
Last:=Last+First; //定位最后一個(號以后的最開始的)號位置
LeftStr:=Copy(Str,1,First-1); //(號左邊的字符串
Middle:=Copy(Str,First+1,Last-First-1); //()號中間的字符串
Right:=Copy(Str,Last+1,Length(Str)-Last); //)號右邊的字符串
temp:=SubCompute(Middle); //進入下面的計算
Middle:=IntToStr(temp);
Str:=LeftStr+Middle+Right;
First:=LastDelimiter ('(',Str);
end;
Result:=SubCompute(Str);
end;
function TFrm_Point.isInputValid: Boolean;
var
tempStr,Current:String;
ppos:Integer;
InputData:array of Integer;
i:integer;
begin
tempStr:=E_Point.Text;
//去掉(和)號
ppos:=Pos('(',tempStr);
while(ppos<>0) do
begin
Delete(tempStr,ppos,1);//刪除括號
ppos:=Pos('(',tempStr);
end;
ppos:=Pos(')',tempStr);
while(ppos<>0) do
begin
Delete(tempStr,ppos,1);//刪除括號
ppos:=Pos(')',tempStr);
end;
//獲取輸入的數字
setLength(InputData,4);
ppos:=AnyFirstPos(tempStr);
InputData[0]:=StrToInt(Copy(tempStr,1,ppos-1));
tempStr:=Copy(tempStr,ppos+1,Length(tempStr)-ppos);
ppos:=AnyFirstPos(tempStr);
InputData[1]:=StrToInt(Copy(tempStr,1,ppos-1));
tempStr:=Copy(tempStr,ppos+1,Length(tempStr)-ppos);
ppos:=AnyFirstPos(tempStr);
InputData[2]:=StrToInt(Copy(tempStr,1,ppos-1));
tempStr:=Copy(tempStr,ppos+1,Length(tempStr)-ppos);
ppos:=AnyFirstPos(tempStr);
InputData[3]:=StrToInt(Copy(tempStr,1,ppos-1));
//將大于10的數設置為1
for i:=0 to 3 do
begin
if(RandomData[i]>10) then
RandomData[i]:=1;
end;
//利用循環判斷當前字符是不是不屬于4個數中的任何一個
for i:=0 to 3 do
begin
Current:=Copy(tempStr,i+1,1);
//如果不屬于4個數中的任何一個,則返回false,表示輸入有誤
if((InputData[i]<>RandomData[0])
and (InputData[i]<>RandomData[1])
and (InputData[i]<>RandomData[2])
and (InputData[i]<>RandomData[3])) then
begin
isInputValid:=false;//返回False
exit;
end;
end;
Result:=true;
end;
procedure TFrm_Point.E_PointKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if (E_Point.Text <> '') and (key = VK_RETURN) then
Btn_Calc.Click;
end;
end.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -