Autor Beitrag
Krefti
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 164

Win XP/Vista/Win7/ubuntu
Delphi 7/2006/2009 Pro
BeitragVerfasst: Di 20.05.08 13:51 
Hi zusammen,

ich hab ein Problem beim auslesen einer .txt datei in mein Stringgrid. Die dargestellten Inhalte aus dem Stringgrid werden zu erst in einer .txt abgespeichert. Beim Laden bekomm ich dann eine access violation, read of adress

das abspeichern funktioniert problemlos.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
procedure TForm1.SaveStringGridToFile(Sender: Tobject);
var
  sl: TStringList;
  x,y: Integer;
begin
     StartDir := inifWerte.Programmpfad;
                  sdSpeichernDialog.Filter := 'Protokolldatei (*.txt)|*.txt';
                  sdSpeichernDialog.options := [ofAllowMultiSelect];
                  sdSpeichernDialog.initialDir := StartDir;

   if sdSpeichernDialog.Execute then

   sl := TStringlist.Create;
   sl.add(inttostr(sgTabelle.ColCount));
   sl.add(inttostr(sgTabelle.RowCount));

   for x := 0 to sgTabelle.ColCount - 1 do
     for y := 0 to sgTabelle.RowCount - 1 do
       sl.add(sgTabelle.cells[x,y]);
   sl.savetofile(sdSpeichernDialog.filename);
   sl.free;
end;


beim laden kommt der fehler:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
procedure TForm1.LoadStringGridFromFile(Sender: TObject);
var
  sl: TStringList;
  x,y,z: Integer;
begin
    If odLadenDialog.Execute then

 StartDir := inif.ReadString('Pfadangabe','speicher',s);
        odLadenDialog.Filter := 'Protokolldatei (*.txt)|*.txt';
        odLadenDialog.options := [ofAllowMultiSelect];

        odLadenDialog.initialDir := StartDir;


  sl := TStringList.Create;
  sl.loadfromfile(odLadenDialog.FileName);
  sgTabelle.ColCount := strtoint(sl.strings[0]);
  sgTabelle.RowCount := strtoint(sl.strings[1]);
  z := 2;
  for x := 0 to sgTabelle.ColCount - 1 do
      for y := 0 to sgTabelle.RowCount - 1 do
        begin
          sgTabelle.Cells[x,y] := sl.strings[z];
          inc(z);
        end;
end;


vielen dank schon mal für eure hilfe!!
Marc.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1876
Erhaltene Danke: 129

Win 8.1, Xubuntu 15.10

BeitragVerfasst: Di 20.05.08 14:03 
Hi!
So auf Anhieb sehe ich nichts, aber setz doch mal einen Breakpoint an den Anfang der Prozedur und Steppe dann mit F7 durch. Damit sollte sich der Fehler ziemlich genau lokalisieren lassen. ;)

Cheers,
Marc
Krefti Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 164

Win XP/Vista/Win7/ubuntu
Delphi 7/2006/2009 Pro
BeitragVerfasst: Di 20.05.08 14:10 
alles klar, hab ich gemacht, von mir aus kann man das thema löschen..ich hab übersehen, dass ich noch den startprogrammpfad aus dem ini-file lese, dabei lese ich bei programmstart alle parameter aus dem inifile in ein record und mache es wieder zu, damit ich es nicht die ganze zeit offen haben muss und arbeite mit dem record und schreibe zum schluss wieder alle variablen des records ins ini-file.
hätt ich selbst drauf kommen müssen;) trotzdem danke..
Marc.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1876
Erhaltene Danke: 129

Win 8.1, Xubuntu 15.10

BeitragVerfasst: Di 20.05.08 14:13 
user profile iconKrefti hat folgendes geschrieben:
alles klar, hab ich gemacht, von mir aus kann man das thema löschen..

Gelöscht wird hier nichts, es könnte ja auch sein, dass andere User das selbe Problem haben. :P
Krefti Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 164

Win XP/Vista/Win7/ubuntu
Delphi 7/2006/2009 Pro
BeitragVerfasst: Di 20.05.08 14:17 
user profile iconMarc. hat folgendes geschrieben:
user profile iconKrefti hat folgendes geschrieben:
alles klar, hab ich gemacht, von mir aus kann man das thema löschen..

Gelöscht wird hier nichts, es könnte ja auch sein, dass andere User das selbe Problem haben. :P


glaub ich in diesem Fall zwar kaum, aber passt schon ;-)
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Di 20.05.08 15:30 
Hallo,

user profile iconKrefti hat folgendes geschrieben:
das abspeichern funktioniert problemlos.

aber nur solange Du den Speicherndialog nicht abbrichst.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
//...
   if sdSpeichernDialog.Execute then

   sl := TStringlist.Create;
   sl.add(inttostr(sgTabelle.ColCount));//<-- hier knallt es
//...

da fehlt noch die Klammerung in einen begin-end-Block. :wink:

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
Krefti Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 164

Win XP/Vista/Win7/ubuntu
Delphi 7/2006/2009 Pro
BeitragVerfasst: Di 20.05.08 15:54 
user profile iconLannes hat folgendes geschrieben:
Hallo,

user profile iconKrefti hat folgendes geschrieben:
das abspeichern funktioniert problemlos.

aber nur solange Du den Speicherndialog nicht abbrichst.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
//...
   if sdSpeichernDialog.Execute then

   sl := TStringlist.Create;
   sl.add(inttostr(sgTabelle.ColCount));//<-- hier knallt es
//...

da fehlt noch die Klammerung in einen begin-end-Block. :wink:


nö, funktioniert doch..der einzige fehler lag darin, wie ich es in meinem obigen beitrag gepostet habe, aber trotzdem danke fürs anschauen;)
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: Di 20.05.08 17:50 
Funktioniert nicht, brich den Dialog mal ab ;-). Die Zeile, in der du die StringList erzeugst, wird nur ausgeführt, wenn der Dialog mit nicht abgebrochen wird.
Der Rest (in dem auch die gar nicht erzeugte StringList benutzt wird) aber auch, wenn du keine Datei auswählst und auf Abbrechen drückst.
Krefti Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 164

Win XP/Vista/Win7/ubuntu
Delphi 7/2006/2009 Pro
BeitragVerfasst: Mi 21.05.08 06:19 
user profile iconjaenicke hat folgendes geschrieben:
Funktioniert nicht, brich den Dialog mal ab ;-). Die Zeile, in der du die StringList erzeugst, wird nur ausgeführt, wenn der Dialog mit nicht abgebrochen wird.
Der Rest (in dem auch die gar nicht erzeugte StringList benutzt wird) aber auch, wenn du keine Datei auswählst und auf Abbrechen drückst.


achso, dass meintest du..das hatte ich schon behoben gehabt..aber trotzdem danke!!