Autor Beitrag
Mäthew Glide
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 31



BeitragVerfasst: Fr 22.10.10 22:10 
Hallo!
Bei mir ergibt sich ein PRoblem wenn ich versuche in Stringgrid zu schreiben. Es soll eine Bestenliste sein die Name udn Punktzahl aus einer ini Datei ausliest. Allerdings wird bei mir nur angezeigt: Name Punktzahl und noch 1. . Weiter läuft die Schleife nicht und ich sehe gerade nciht mein Problem woran das liegt

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
procedure TForm2.FormCreate(Sender: TObject);
var i: integer;
begin
stringgrid1.Cells[1,0]:='Name';
stringgrid1.cells[2,0]:='Punktzahl';
for i := 1 to 10 do
  begin
    stringgrid1.Cells[0,i]:=inttostr(i)+'.';
    stringgrid1.Cells[1,i]:=BEstenliste.ReadString('Platz '+inttostr(i),'Name','kein Wert');
    stringgrid1.Cells[2,i]:=BEstenliste.ReadString('Platz '+inttostr(i),'Punktzahl','kein Wert');
  end;
end;
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: Fr 22.10.10 22:49 
Wo initialisierst du denn BEstenliste? Was passiert denn beim schrittweisen Debuggen?

Und wozu ist das überhaupt eine globale Variable?!? :shock:
Mäthew Glide Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 31



BeitragVerfasst: Fr 22.10.10 23:06 
so sieht es aus wenn 'Bestenliste' erstellt wird:

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
procedure TForm1.FormCreate(Sender: TObject);
var i : integer;
begin
  if not Fileexists(ExtractFilePath(ParamStr(0))+'Bestenliste.ini') then
  begin
    Bestenliste:=Tinifile.Create(ExtractFilePath(ParamStr(0))+'Bestenliste.ini');
    for i := 1 to 10 do
    begin
      BEstenliste.WriteString('Platz '+inttostr(i),'Name','keine Angabe');
      BEstenliste.WriteString('Platz '+inttostr(i),'Punktzahl','keine Angabe');
    end;
  end;
end;


die ini-wird erstellt wenn die Form erstellt wird, aber jetzt wo du mcih drauf auf merksam machst macht dies als globale variable keinen Sinn.

In das ini-File soll dann die vom Spieler errecihte Punktzahl geschrieben werden je nach dem wie hoch die Punktzahl ist.
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: Fr 22.10.10 23:07 
Tja, in deinem Code erzeugst du aber das ganze Objekt Bestenliste nur, wenn die Datei nicht existiert...

Trotzdem versuchst du später darauf zuzugreifen...
Mäthew Glide Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 31



BeitragVerfasst: Fr 22.10.10 23:15 
Danke das war mein Fehler
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: Fr 22.10.10 23:21 
Das hättest du aber beim Debuggen auch sehen können. Wenn du die Maus über Bestenliste gehalten hättest, hättest du gesehen, dass die Variable nil war.

Was den Fehler angeht: Sowas passiert eben, wenn man globale Variablen benutzt...