Autor Beitrag
awzvm
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 27



BeitragVerfasst: Di 21.07.09 12:37 
Hallo Zusammen,

ich habe ein kleines Poblem in einer Schleife. Dort setzte ich jedesmal einen Zeiger auf nil. Das funktioniert allerdings nur 2 mal, dann steigt er mit einer Exception aus.
Wird diese Zeile (PKatalog:=nil; ) auskommentiert, funktioniert die ganze Funktion.

Woran kann das liegen?

ausblenden volle Höhe 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:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:


type TZeile = record
     Spalte: array [0..MAX_COLUMN] of string;
end;

type TKatalog = record
     Dateiname: String;
     Zeile: array of TZeile;
end;

PointerKatalog = ^TKatalog;



implementation

function TMain.LinkCheck(zahl:Integer):Integer;
var …
      PKatalog:PointerKatalog;

Begin

PKatalog:=TranslateKatalog(ComboBox_Katalog.Text,9);
For i:=2 to length(PKatalog.Zeile)-1 do
Begin

    if PKatalog.Zeile[i].Spalte[22]<>'' then
       //..

      for j := 0 to StringGrid_Parse_W.RowCount - 1 do
      begin

       if StringGrid_Parsen_W.Cells[0,j]<>'' then
        begin
          //…

          PKatalog:=nil;  //wenn auskommentiert, dann läuft es durch

          for c:=0 to length(AllDefaultCatalogs) - 1 do
             if length(AllDefaultCatalogs[c].Zeile)>=1 then  if AllDefaultCatalogs[c].Zeile[1].Spalte[0]=catalog then begin PKatalog:=AllDefaultCatalogs[c]; break; end;

          //…
        end;  //if StringGrid_Parse_W.Cells[0,j]<>'' then

      end//for j := 0 to StringGrid_Parsen_W.RowCount - 1 do

   end;  //if PKatalog.Zeile[i].Spalte[22]<>'' then

end;   //For i:=2 to length(PKatalog.Zeile)-1 do


Viele Grüße
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8554
Erhaltene Danke: 481

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Di 21.07.09 12:41 
Naja, du setzt das Ding auf Nil, hinterher unter bestimmten Umständen wieder auf ein anderes Objekt, und greifst dann im nächsten Schleifendurchlauf auf dieses Objekt dahinter zu. Was ist, wenn das Ding immer noch auf Nil zeigt? Das kann doch eigentlich gar nicht sicher funktionieren :nixweiss:.

_________________
We are, we were and will not be.
awzvm Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 27



BeitragVerfasst: Di 21.07.09 12:43 
habe nun statt den Zeiger eine Bool'sche variable benommen und diese gesetzt.
Jetzt überprüf ich immer diese Variable statt den Zeiger auf nil zu testen... Nun geht alles... war schon komisch das ganze..

Danke.
ffgorcky
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 573

WIN XP/2000 & 7Prof (Familie:Win95,Win98)

BeitragVerfasst: Di 21.07.09 13:13 
Also ich sehe aber auch nirgendwo den Test if not (PKatalog=nilthen
Ich denke mal, das wäre doch auch eine Möglichkeit.
Dann brauchst Du keine extra Variable - wobei sich natürlich streiten lässt, ob nicht Deine Variante mit der boolschen Variable sowieso besser ist... - Ich denke schon!
awzvm Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 27



BeitragVerfasst: Di 21.07.09 14:35 
Die Abfrage PKatalog<>nil habe ich ausgeblendet, da hier kein Fehler war. Diese steht aber natürlich ab Zeile 43 mit drin :-)

Es war eben merkwürdig, dass er nach der dritten Zweisung von PKatalog:=nil immer ausgestiegen ist.