![]() |
kleine Frage zu kleinem befehl
hi,
ich hab irgendwo folgenden befehl aufgeschnappt! var n:double; code:integer; ..... Val(Edit1.text,n,code) ich weiß was es bewirkt, ich verstehs nur programmtechnisch nicht! kann mir wer helfen? |
Hi,
ein Blick in die OH hätte Dir dies bescherrt:
Delphi-Quellcode:
Grüsse, Daniel :hi:
Val procedure
Converts a string to a numeric representation. Unit System Category string handling routines procedure Val(S; var V; var Code: Integer); Description Val converts the string value S to its numeric representation, as if it were read from a text file with Read. S is a string-type expression; it must be a sequence of characters that form a signed real number. V is an integer-type or real-type variable. If V is an integer-type variable, S must form a whole number. Code is a variable of type Integer. If the string is invalid, the index of the offending character is stored in Code; otherwise, Code is set to zero. For a null-terminated string, the error position returned in Code is one larger than the actual zero-based index of the character in error. Val performs range checking differently depending upon the setting of the $R compiler directive and the type of the parameter V. Setting Result {$R+} An out-of-range value always generates a run-time error. {$R-} The values for out-of-range vary depending upon the data type of V. |
Hallo Daniel!
Der Befehl val() wandelt einen String in einen Double/Integer-Wert um. Mit Parameter Code wird überprüft, ob es sich um eine gültige nummerische Eingabe handelt. Ist Code <> 0, handelt es sich somit um eine nicht nummerische Eingabe. Gruß 1PM |
... und gibt den Index des ersten Zeichens an dem die Umwandlung gescheitert ist.
|
und gibt das bei code<>0 ein Laufzeitfehler, oder macht delphi dann einfach nicht weiter im programm, oder überspringt irgendwas??
ist das also sowas wie StrToFloat(Edit1.text); mit integriertem Falsch-Eingabe-Abfang-Mechanismus? (ach schönes wort) ;) ok machs gut haegar |
Sorry, hatte meinen letzten Thread an die falsche Person geschrieben, fällt mir gerade auf! :oops:
Hallo Haegar! Nein, er bringt keinen Laufzeitfehler! Die Variable wird nicht umgewandelt. Gruß 1PM :hello: |
Hallo!
@1PM: Es wird doch umgewandelt, aber nur am Anfang, soweit wie möglich. Beispiele: '123ab' ergibt 123, Code 4, 'ab123' ergibt 0, Code 1. Dabei wird der Wert der Variablen zuerst auf 0 gesetzt - dann soweit wie möglich umgewandelt und beim ersten ungültigen Zeichen abgebrochen. Gruß Dietmar Brüggendiek |
Alle Zeitangaben in WEZ +1. Es ist jetzt 01:50 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz