Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi strToIntDEF??? (https://www.delphipraxis.net/81637-strtointdef.html)

xilos 30. Nov 2006 15:30


strToIntDEF???
 
hallo ich habe mal eine frage...
...und zwar hab ich irgendwo gesehn , dass man strtointDEF benutzt...
was ist der unterschied zwischen strtoint und strtoinDEF???
kann mir den einer erklärn?? bei mir in der delphihilfe steht nämlich bei beiden das gleiche ^^

alzaimar 30. Nov 2006 15:33

Re: strToIntDEF???
 
Zitat:

Zitat von Die Delphi-Hilfe (StrToIntDef)
StrToIntDef converts the string S, which represents an integer-type number in either decimal or hexadecimal notation, into a number. If S does not represent a valid number, StrToIntDef returns the number passed in Default.

Zitat:

Zitat von Die Delphi-Hilfe (StrToInt)
StrToInt converts the string S, which represents an integer-type number in either decimal or hexadecimal notation, into a number. If S does not represent a valid number, StrToInt raises an EConvertError exception.

Das ist also das Gleiche? :wall:

Thorben_K 1. Dez 2006 06:24

Re: strToIntDEF???
 
um die sache mal auf deutsch zu erklären ;)

StrToInt konvertiert einen String in einen Integer, wenn der String aber andere sachen als zahlen oder halt das Komma enthällt komm es zu einem Fehler

StrToIntDef macht erst mal das selbe, nur wenn es zu einem fehler kommt, setzt es den default wert ein. im prinzip macht StrToIntDef so was in der art

Delphi-Quellcode:
var
  x : LongInt;
  s : String;

begin

  x := StrToIntDef(s, -1);

end;
das selbe mit StrToInt müsstest du so machen:

Delphi-Quellcode:
var
  x : LongInt;
  s : String;

begin

try

  x := StrToInt(s);

except

  x := -1;

end;
end;
hoffe geholfen zu haben ;)

mkinzler 1. Dez 2006 06:44

Re: strToIntDEF???
 
Eine weitere Möglichkeit wäre noch TryStrToInt


Alle Zeitangaben in WEZ +1. Es ist jetzt 17:32 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz