Autor Beitrag
Georg08
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 155
Erhaltene Danke: 6

Win XP
Delphi 7.0 Personal
BeitragVerfasst: So 31.05.09 03:14 
Hallo,
ich programmiere gerade ien programm und hätte gerne, dass eine variable den sleben wert wie am anfang hat... nämlich garkeinen :D also weder 0 noch sonst was sondern einfach nichts

Danke im vorraus
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19321
Erhaltene Danke: 1749

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: So 31.05.09 03:26 
ausblenden Delphi-Quelltext
1:
i := Random(MaxInt);					
:mrgreen:
Im Ernst: Wenn eine lokale Integervariable nicht nicht initialisiert wurde, dann ist der Wert zufällig, du weißt nicht, was für einen Wert die hat. Bei globalen Variablen oder Feldern eines Objekts werden die Variablen mit 0 initialisiert.

Was hast du denn vor?
Georg08 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 155
Erhaltene Danke: 6

Win XP
Delphi 7.0 Personal
BeitragVerfasst: So 31.05.09 03:37 
hmm ich wollt ne codeabfrage machen und das war, wenn man den code löschen und neu eingeben wollte habs jetzt aber etwas komplizierter und uneleganter gelöst...
Tilo
ontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 1098
Erhaltene Danke: 13

Win7 geg. WInXP oder sogar Win98
Rad2007
BeitragVerfasst: So 31.05.09 07:51 
Wie wäre es mit einem typischiertem Pointer?
am Anfang setzt Du den Pointer auf nil und damit ist bekannt das die Variable noch keinen Wert hat da sie noch nicht existiert.
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19321
Erhaltene Danke: 1749

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: So 31.05.09 14:41 
Es reicht auch eine zusätzliche boolsche Variable, aber es kommt ganz darauf an, was genau der Sinn ist. Vermutlich gibt es eine sinnvollere Lösung, das ist richtig.