Home > Back-end >  Delphi6, the compiled program has been running normally, suddenly yesterday strtoint function cannot
Delphi6, the compiled program has been running normally, suddenly yesterday strtoint function cannot

Time:09-28

Delphi6, compiled the program has been running normally, suddenly yesterday strtoint function cannot convert characters to digital, and analysis the reason,

CodePudding user response:

Press CTRL to open it, and see if it is to realize the,

CodePudding user response:

In the original program
1, press the CTRL key,
2, the mouse to click IntToStr,
One, open not SysUnit IntToStr method, is to rewrite IntToStr method, should be deleted,,
Two, open SysUnit IntToStr method, check whether agree with the following:
Value:
 function IntToStr (Integer) : string; 
//FmtStr (Result, '% d', [Value]);
Asm
PUSH ESI
MOV ESI, ESP
SUB ESP, 16
XOR ECX, ECX//base: 0 for signed decimal
PUSH the EDX//result PTR
XOR EDX, EDX//zero filled the field width: 0 for no leading zeros
CALL CvtInt
MOV EDX, ESI
POP EAX//result PTR
CALL System. @ LStrFromPCharLen
ADD the ESP, 16
POP ESI
The end;

Modified to run again,
Three, if invalid, only reinstall the,

CodePudding user response:



Upstairs, strtoint with inttostr don't mix well.


Before calling strtoint, can try their judgment, if character is a number [0.. 9]
Sometimes appear in character non-numeric characters, or numeric characters for whole Angle input, will go wrong.


CodePudding user response:

Sorry wrong,

Advice before StrToInt function called by judgment, after execution:
Whether S plastic function:
 function IsInteger (Str: string) : Boolean;//determine the integer 
Var V, Code: Integer;
The begin
Val (Str, V, Code);
Result:=(Code=0) and (Pos (' X ', Str) & lt;=0);
The end;

Execute the code
"
 if IsInteger (S) then I:=StrToInt (S) 


My code, so, also avoids the error of digital characters,

CodePudding user response:

StrToInt in time for the incoming string is not a number, there are two methods, the use of the try... Except, capture process, or using TryStrToInt function,

CodePudding user response:

reference 4 floor lyhoo163 response:
sorry wrong,

Advice before StrToInt function called by judgment, after execution:
Whether S plastic function:
 function IsInteger (Str: string) : Boolean;//determine the integer 
Var V, Code: Integer;
The begin
Val (Str, V, Code);
Result:=(Code=0) and (Pos (' X ', Str) & lt;=0);
The end;

Execute the code
"
 if IsInteger (S) then I:=StrToInt (S) 


My code, so, also avoids the error of digital characters,



StrToIntDef (' 3 ', 0) function can be in non integer data shows the default values, when the original poster can use this to look at you the problem of function transformation,

CodePudding user response:

Characters in the source are Numbers

CodePudding user response:

reference 5 floor pathletboy reply:
StrToInt in time for the incoming string is not a number, there are two methods, the use of the try... Except, capture process, or using TryStrToInt function,


If there is no guarantee that the STR the number, had better use the TryStrToInt