Home
Forum: "Main";
Current archive: 2002.01.08;

Down

Monopulation of numbers. Find similar branches

Socol   (2001-12-18 10:01) [0]

Hello!
Suppose there is a label1.caption: = "450"
if label1.caption> "500" then boton1.enabled: = true
else
if label1.caption> "1000" then boton1.enabled: = true
else
In the first case, everything turns out and in the second no.
Ie Delphi shields that 450> 1000 Ie she compares on the first digit how to avoid it so that she began to compare on the whole number?

Виктор Щербаков   (2001-12-18 10:04) [1]

Compare numbers, not their string representations.

Socol   (2001-12-18 10:06) [2]

it's like?

gek   (2001-12-18 10:07) [3]

Or compare them tag_i

Виктор Щербаков   (2001-12-18 10:15) [4]

if StrToInt (Label1.Caption)> StrToInt (Label2.Caption) then ...

Voron   (2001-12-18 13:19) [5]

Box1.Enabled: = StrToInt (Label1.Caption)> 500;
Like this. Only it is necessary to take into account that StrToInt will cause an exception if the string passed to it contains something other than numbers, well, there may still be a minus ahead.

Андрей Сенченко   (2001-12-18 13:45) [6]

If Label1.Caption can contain anything (and at the development stage it cannot be assumed that), then it’s better to use for conversion

`StrToIntDef (St: string, Default: integer): LongInt`

Voron   (2001-12-18 14:35) [7]

StrToIntDef in case of failure does not raise an exception, but returns Default
Suppose we have something like

I: = StrToIntDef (St, -1);

If St is equal to "-1" then does the function return -1 anyway, and then how do you know if it returns Default or the string representation of the whole from St?

StrToInt generates an exception in case of failure, it can be processed.
Best regards Voron

Pages: 1 whole branch

Forum: "Main";
Current archive: 2002.01.08;