Autor Beitrag
Ironwulf
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 733
Erhaltene Danke: 2



BeitragVerfasst: Sa 30.07.05 22:07 
Hy, ich hab folgendes Problem
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
  ini:= TIniFile.Create('maps/bla.ini');
  try
    maxhor:= Ini.ReadInteger('Map','Horizontal',0);
    maxvert:= Ini.ReadInteger('Map','Vertikal',0);

    for i:= 1 to maxhor do
    for i:= 1 to maxvert do
    begin
    Feld[i,j].Boden:= Ini.ReadInteger('Feld[' + IntToStr(i) + ',' + IntToStr(j) + ']','Boden',5);
    end;
  finally
    ini.Free;
 end;


das Problem ist das wenn ich dann auf Feld[1,1].Boden zugreifen möchte ich eine 0 erhalte, aber inder ini- datei eine 1 steht.
das maxhor und maxvert wird jedoch richtig ausgelesen und wenn ich die 2 for- schleifen auskommentiere erhalte ich den defaultwert "5"
kann mir da jemand weiter helfen?

Moderiert von user profile iconGausi: Code- durch Delphi-Tags ersetzt.
blaueled
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 133

Win XP
D5
BeitragVerfasst: Sa 30.07.05 22:35 
Ich glaube dein Fehler ist ganz einfach :

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
ini:= TIniFile.Create('maps/bla.ini');
  try
    maxhor:= Ini.ReadInteger('Map','Horizontal',0);
    maxvert:= Ini.ReadInteger('Map','Vertikal',0);

    for i:= 1 to maxhor do
    for i:= 1 to maxvert do
    begin
    Feld[i,j].Boden:= Ini.ReadInteger('Feld[' + IntToStr(i) + ',' + IntToStr(j) + ']','Boden',5);
    end;
  finally
    ini.Free;
 end;


da soll wahrscheinlich ein j hin ...

Moderiert von user profile iconKlabautermann: Higlight-Tag korrigiert.
Ironwulf Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 733
Erhaltene Danke: 2



BeitragVerfasst: Sa 30.07.05 22:48 
jop danke
aber irgendwie läd der mir jetz den default wert und nich die 1 die in der ini steht...

EDIT

hier noch ein auszug aus der ini datei falls ich mich wieder nur verschrieben hab was ich zwar nicht glaube da ich mir das nun schon 2h anseh, aber man weiß ja nie

[Feld[1,1]]
Boden=1
[Feld[1,2]]
Boden=0
[Feld[1,3]]
Boden=0
...
MrFox
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 208

WIN 2000 Professional, Ubuntu 5.10
D3 Prof, D7 Pers, D2005 Pers, Java (Eclipse)
BeitragVerfasst: So 31.07.05 15:35 
TiniFile hat eine kleine Tücke. Wenn man in Create z.B. 'settings.ini' angibt, dann wird 'C:\Windows\settings.ini' geöffnet. D.h. wenn der übergebene Pfad nicht absolut ist, wird automatisch vom Windowsverzeichnis ausgegangen.

Liegt deine IniFile unter 'C:\Windows\maps\bla.ini' ???

Lösung: IniFile.Create(ExtractFilePath(ParamStr(0))+'\maps\bla.ini');

_________________
Das Leben auf der Erde mag zwar teuer sein, aber eine jährliche Rundreise um die Sonne ist gratis mit dabei.
Ironwulf Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 733
Erhaltene Danke: 2



BeitragVerfasst: So 31.07.05 16:02 
funktioniert trotzdem irgendwie noch nicht...

und wenn ich in die ini schreibe und diese noch nicht existiert geht der bei mir auch nicht vom windows verzeichnis aus sondern von dort wo ich das project liegen habe und erstellt sie dann dort
Heiko
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3169
Erhaltene Danke: 11



BeitragVerfasst: So 31.07.05 16:43 
Kannst du uns mal die gesamte INI geben?
Ironwulf Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 733
Erhaltene Danke: 2



BeitragVerfasst: So 31.07.05 16:56 
jo klar
wobei die momentan immer so weiter geht wie oben bis Feld[25,25]
ich post auch gleich mal noch die komplette unit...
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:
procedure save;
var
  i, j: Byte;
  zaehler: Integer;
begin
  zaehler:= 0;
  form5.gauge1.maxValue:= maxhor * maxvert;
  form5.visible:= True;
  deletefile('maps/bla.ini');
  ini := TIniFile.Create('maps/bla.ini');
  try  
    for i:= 1 to maxhor do
    for j:= 1 to maxvert do
    begin
    Ini.WriteInteger('Feld[' + IntToStr(i) + ',' + IntToStr(j) + ']','Boden',Feld[i,j].Boden);
    zaehler:= zaehler + 1;
    form5.gauge1.progress:= zaehler;
    end;
    Ini.WriteInteger('Map','Horizontal',maxhor);
    Ini.WriteInteger('Map','Vertikal',maxvert);
  finally
    ini.Free;
  end;  
form5.visible:= False;
end;

procedure Load;
var i, j: Byte;
begin
  ini:= TIniFile.Create('maps/bla.ini');
  try
    maxhor:= Ini.ReadInteger('Map','Horizontal',0);
    maxvert:= Ini.ReadInteger('Map','Vertikal',0);

    for i:= 1 to maxhor do
    for j:= 1 to maxvert do
    begin
    Feld[i,j].Boden:= Ini.ReadInteger('Feld[' + IntToStr(i) + ',' + IntToStr(j) + ']','Boden',5);
    end;
  finally
    ini.Free;
 end;
end;



die procedure save funktioniert so wie ichs mir vorstelle
und der pfad der ini ist: *\Desktop\projects\bla\maps/bla.ini

Moderiert von user profile iconAXMD: Code- durch Delphi-Tags ersetzt.
Einloggen, um Attachments anzusehen!
Heiko
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3169
Erhaltene Danke: 11



BeitragVerfasst: So 31.07.05 19:05 
Ich habe es jetzt so und es funzt (allerdings ist die INI im gleichem Ordner):

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
procedure TForm1.Button3Click(Sender: TObject);
var i, j: Byte;
    ini: TIniFile;
    maxhor, maxvert: Integer;
begin
  ini:= TIniFile.Create(ExtractFilePath(ParamStr(0))+'bla.ini');
  try
    maxhor:= Ini.ReadInteger('Map','Horizontal',0);
    ShowMessage(IntToStr(maxhor));
    maxvert:= Ini.ReadInteger('Map','Vertikal',0);
  finally
    ini.Free;
 end;
end;
Ironwulf Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 733
Erhaltene Danke: 2



BeitragVerfasst: So 31.07.05 19:18 
öhm ja...
das war nich das problem
die 2 werte hat er schon richtig ausgelesehn, nur nicht die die unter Feld[i,j].Boden stehn...
Heiko
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3169
Erhaltene Danke: 11



BeitragVerfasst: So 31.07.05 19:35 
Kannst du mal auch deine Variablendeklaration geben? Also die Varaiblen die in den beiden Prozeduren verwendet werden (ich habe gerade keine Lust mir die selber herzuleiten).
Ironwulf Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 733
Erhaltene Danke: 2



BeitragVerfasst: So 31.07.05 19:39 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
type
  TFeld = record
    Boden: Byte;
end;

var  Feld: array[1..100,1..100of TFeld;


Moderiert von user profile iconraziel: Code- durch Delphi-Tags ersetzt.
MrFox
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 208

WIN 2000 Professional, Ubuntu 5.10
D3 Prof, D7 Pers, D2005 Pers, Java (Eclipse)
BeitragVerfasst: So 31.07.05 20:32 
Mir fällt gerade auf, dass du den schrägstrich in den Pfadangaben falschherum machst.
Weiß nicht ob das was bewirkt. Nur so als Tipp. :wink:

_________________
Das Leben auf der Erde mag zwar teuer sein, aber eine jährliche Rundreise um die Sonne ist gratis mit dabei.
Ironwulf Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 733
Erhaltene Danke: 2



BeitragVerfasst: So 31.07.05 20:48 
mmh nö, daran liegts auch nich das schreiben funktioniert weiterhin so perfekt und das lesen immernoch fehlerhaft :(


EDIT

ich glaub ja irgendwie das der
'Feld[' + IntToStr(i) + ',' + IntToStr(j) + ']'
das nich richtig zusammen setzt... somit der eintrag in der ini nicht gefudnen wird, mir deshalb den default wert ausgibt
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: So 31.07.05 21:36 
Hallo,

mit den eckigen Klammern kommt TiniFile nicht zurecht, ist eigentlich auch nicht verwunderlich, da ja die Sectionen darüber erkannt werden, vermute ich mal.
Ersetz doch die eckigen durch runde Klammern oder lass sie einfach weg.
ausblenden Delphi-Quelltext
1:
2:
3:
'Feld(' + IntToStr(i) + ',' + IntToStr(j) + ')'
//oder 
'Feld' + IntToStr(i) + ',' + IntToStr(j)

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
Ironwulf Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 733
Erhaltene Danke: 2



BeitragVerfasst: So 31.07.05 21:45 
jo danke jetz gehts :dance: