Autor Beitrag
monty.ms
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 47



BeitragVerfasst: Do 21.04.05 15:02 
Ich hab ein kleines Problem:

Ich hab zwei forms! Jeweils ein Memo! Im 1. Form steht, dass er im Memo2 den text aus einer txt datei laden soll! aber irgendwie kommt immer ein fehler, obwohl mir der code richtig erscheint, da er beim complimieren ja auch keine fehler anzeigt..

hier mal der code:

ausblenden Delphi-Quelltext
1:
form2.memo2.Lines.LoadFromFile(speicherort+'test.txt');					


die variable "speicherort" hat den korrekten "Wert", und die Datei existiert auch..

hier der fehler:
Zitat:
"Project Project1.exe raised exception class EAccessViolation with message 'Access violation at address 0046290C in module 'Project1.exe'. Read of address 000002F8'. Process stopped. Use Step or Run to continue."


dann springt er auch auf die oben angegebene zeile!

Kann mir einer sagen, was ich falsch gemacht hab?

danke im vorraus
mfg monty

Moderiert von user profile iconTino: Code- durch Delphi-Tags ersetzt.
Moderiert von user profile iconTino: Quote-Tags hinzugefügt.
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Do 21.04.05 15:06 
Kann es sein, dass bei dir die Formulare dynamisch erstellt werden und Form2 einfach noch nicht erzeugt wurde?
--> Haltepunkt auf die Zeile, und Form2 VOR der Ausführung des Befehls auswerten. Ich vermute, dass Form2 = nil ist...
monty.ms Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 47



BeitragVerfasst: Do 21.04.05 15:09 
Wenn ich das Programm schließe, führt er (im Form1) diesen code durch:

ausblenden Delphi-Quelltext
1:
form2.memo2.Lines.SaveToFile(speicherort+'test.txt');					


d.h: speichern kann er die datei, nur nicht laden! also müsste form2 erzeugt sein..

Moderiert von user profile iconTino: Code- durch Delphi-Tags ersetzt.
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Do 21.04.05 15:19 
Wenn du beim Programmstart die Datei lädst, ist Form2 vielleicht noch nicht erzeugt!?
monty.ms Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 47



BeitragVerfasst: Do 21.04.05 15:25 
wie kann ich denn dafür sorgen, dass die form vor dem befehl erzeugt wird?
c.wuensch
Hält's aus hier
Beiträge: 11

Win 95, Win 98, Win 200
D5 Std, D6 Pers
BeitragVerfasst: Do 21.04.05 15:25 
Vielleicht muss es ja heißen:

ausblenden Delphi-Quelltext
1:
form2.memo2.Lines.SaveToFile(speicherort+'\test.txt');					

?
monty.ms Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 47



BeitragVerfasst: Do 21.04.05 15:31 
ne, das ist es nicht! der selbe fehler kommt auch, wenn ich ein bestimmtes wort in die memo bringen will. wenn ich die befehle in eine andere prozedure rein mache, funktioniert es..

also scheint es wirklich an der form zu liegen, dass die, warum auch immer, noch nicht erzeugt wurde.. aber gibt es irgend eine möglichkeit die form eher zu erzeugen?
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Do 21.04.05 15:35 
user profile iconmonty.ms hat folgendes geschrieben:
wie kann ich denn dafür sorgen, dass die form vor dem befehl erzeugt wird?

Indem du den Befehl im Create der Form2 ausführst.
monty.ms Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 47



BeitragVerfasst: Do 21.04.05 15:40 
user profile iconjasocul hat folgendes geschrieben:

Indem du den Befehl im Create der Form2 ausführst.


ah ^^ .. warum bin ich da nicht gleich drauf gekommen =) .. danke schön
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Do 21.04.05 15:52 
Ich habe manchmal auch ein Brett vor dem Kopf. Vor allem kurz vor Feierabend. :wink: