Autor Beitrag
Wolle92
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 1296

Windows Vista Home Premium
Delphi 7 PE, Delphi 7 Portable, bald C++ & DirectX
BeitragVerfasst: Do 23.07.09 11:25 
Moderiert von user profile iconNarses: Abgetrennt von [url=www.delphi-forum.de/...?t=93799]hier[/url].

So, ich missbrauche diesen Thread mal, da es um die gleiche Funktion geht...
Moderiert von user profile iconNarses: Nein, das wirst du nicht tun, du bist schon lange genug hier, um die Regeln zu kennen.

Ich muss für eine Zufallsauswahl die höchste Id, die in der Datei steht, rausfinden.
Die steht in der letzten Section, also besorge ich mir mit ini.ReadSections(quotes) alle Sections und nehme dann die letzte davon, und daraus lese ich den Wert Id...
Sollte ach eigentlich funktionieren, aber ich bekomme nicht die letzte Section, und auch keine andere die in der Ini steht. Sondern eine, die überhaupt nicht existiert!

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:
procedure TForm1.Button5Click(Sender: TObject);
var maxid, id: Integer;
    section: String;
    quotes: TStringList;
begin
  Randomize;
  quotes := TStringList.Create;
  ini.ReadSections(quotes);
  section := quotes[quotes.Count-1];
  if quotes.Count <> 0 then
  begin
    maxid := ini.ReadInteger(quotes[quotes.Count-1],'Id',0);
    if maxid <> 0 then
    begin
      repeat
        id := Random(maxid);
      until ini.SectionExists('Quote_'+IntToStr(id));
      ShowQuote(id);
    end
    else
    begin
      Memo1.Clear;
      Memo1.Lines.Add('Ein Fehler ist aufgetreten!');
    end;
  end
  else
  begin
    Memo1.Clear;
    Memo1.Lines.Add('Es sind keine Zitate gespeichert!');
  end;
end;


maxid ist eben gleich 0, und deshalb klappts nicht. Hab auch mit dem Debugger mal reingeguckt, was in der section steht, und es ist glaub ich Quote_1304. Aber Quote_1304 gibt es nicht, und die letzte ist es genausowenig...

Hat jemand nen Ratschlag?

Danke,
Wolle

_________________
1405006117752879898543142606244511569936384000000000.
Xentar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2077
Erhaltene Danke: 2

Win XP
Delphi 5 Ent., Delphi 2007 Prof
BeitragVerfasst: Do 23.07.09 12:16 
Zeig mal bitte eine Beispiel-Ini? Ich versteh das Prinzip noch nicht so ganz.

Edit: Wenn maxid = 0 ist, wurde eben der Default-Wert genommen. Entweder, weil es die Section nicht gibt, oder weil es dort keinen Key "Id" gibt (Groß- / Kleinschreibung sollte egal sein). Schau dir mal die Section im Debugger an, ob es diese überhaupt gibt.

Btw.:
- deine Variable section wird nich verwendet
- try ... finally :D

_________________
PROGRAMMER: A device for converting coffee into software.
Wolle92 Threadstarter
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 1296

Windows Vista Home Premium
Delphi 7 PE, Delphi 7 Portable, bald C++ & DirectX
BeitragVerfasst: Do 23.07.09 19:35 
Ich hab ja oben schon geschrieben, dass die Section nicht existiert, deshalb ist es 0...
Nur hat die Section doch eigentlich zu existieren, wenn sie in dem Ergebnis von ReadSections steht, oder?

Die section-Variable hab ich erstellt, um beim Debuggen zu sehen, was drinsteht ;)

_________________
1405006117752879898543142606244511569936384000000000.
Xentar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2077
Erhaltene Danke: 2

Win XP
Delphi 5 Ent., Delphi 2007 Prof
BeitragVerfasst: Do 23.07.09 20:56 
Kann das Problem nicht nachvollziehen..

hab grad mal schnell nen Test zusammengetippt:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
procedure TForm1.FormCreate(Sender: TObject);
var ini: tinifile;
    mySL: TStringList;
begin
  Ini := TIniFile.Create('d:\test.ini');
  mySL := TStringList.Create;

  try
    ini.ReadSections(mySL);
    showmessage(mySL[mySL.Count-1]);
  finally
    FreeAndNil(ini);
    FreeAndNil(mySL);
  end;
end;


Die zugehörige Ini:
ausblenden Quelltext
1:
2:
3:
4:
5:
[test1]
id=1337

[test2]
id=123

Funktioniert, wie es soll. Es wird "test2" als Message ausgegeben.

Deswegen nochmal die Bitte, eine Beispiel-Ini von dir anzuhängen. Vielleicht ist da der Wurm drin.
Außerdem könntest du mit dem Debugger nochmal nachschauen, ob in quotes.Text was drin steht.

Btw:
Ich seh nirgends, wo deine Ini erzeugt wird...? Ist das etwa eine globale Variable? omg..
Da das ein sehr beliebter Fehler von dir ist, weise ich vorsichtshalber mal auf "ABSOLUTE Dateipfade" hin!

_________________
PROGRAMMER: A device for converting coffee into software.
Wolle92 Threadstarter
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 1296

Windows Vista Home Premium
Delphi 7 PE, Delphi 7 Portable, bald C++ & DirectX
BeitragVerfasst: Do 23.07.09 22:28 
Ja, die Variable ist global... Bzw. gehört der Form1...
Wird nunmal von mehreren Methoden verwendet.

Ini:
ausblenden 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:
[Basic]
Count=1506
LastUpdate=22-07-2009 20:50
[Quote_2]
Id=2
Date=05.12.2004 02:01
QuoteRows=[Base64-kodierter Text]
[Quote_3]
Id=3
Date=04.12.2004 19:45
QuoteRows=[Base64-kodierter Text]
[Quote_4]
Id=4
Date=21.11.2004 08:54
QuoteRows=[Base64-kodierter Text]
[Quote_5]
Id=5
Date=04.12.2004 22:00
QuoteRows=[Base64-kodierter Text]
[Quote_6]
Id=6
Date=05.12.2004 03:02
QuoteRows=[Base64-kodierter Text]
[... viele weiter nach diesem schema, bis zu ...]
[Quote_69311]
Id=69311
Date=30.12.2006 18:21
QuoteRows=[Base64-kodierter Text]


Es sind im moment genau 3000 "Quote"-Sections in der INI... Auch wenn das nicht mit dem Counter übereinstimmt, ich habs kontrolliert, exakt 12003 Zeilen, 3 davon zur Basic-Section, 4 pro Quote, also 3000 Quotes...

Absolute Dateipfade sind kein beliebter Fehler von mir... Ich hab den letztens einmal gemacht ;)

_________________
1405006117752879898543142606244511569936384000000000.
Xentar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2077
Erhaltene Danke: 2

Win XP
Delphi 5 Ent., Delphi 2007 Prof
BeitragVerfasst: Do 23.07.09 22:38 
Hab den von dir reingestellten Code leicht modifiziert, um ihn bei mir lauffähig zu bekommen:
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:
procedure TForm1.FormCreate(Sender: TObject);
var maxid, id: Integer;
    section: String;
    quotes: TStringList;
    ini: tinifile;
begin
  Randomize;
  quotes := TStringList.Create;
  ini := TIniFile.Create('d:\test.ini');
  ini.ReadSections(quotes);
  section := quotes[quotes.Count-1];
  if quotes.Count <> 0 then
  begin
    maxid := ini.ReadInteger(quotes[quotes.Count-1],'Id',0);
    if maxid <> 0 then
    begin
      repeat
        id := Random(maxid);
      until ini.SectionExists('Quote_'+IntToStr(id));
      ShowMessage(IntToStr(ID));
    end
    else
    begin
      Memo1.Clear;
      Memo1.Lines.Add('Ein Fehler ist aufgetreten!');
    end;
  end
  else
  begin
    Memo1.Clear;
    Memo1.Lines.Add('Es sind keine Zitate gespeichert!');
  end;
end;


Mit diesem Code, und deiner Ini, kann ich das Problem NICHT nachvollziehen.
Es wird die letzte Section ausgewählt (maxid hat den Wert 69311)
Es wird eine Zufallszahl erzeugt und angezeigt. Dauert zwar relativ lang, da nur wenige Quotes drin sind - aber es funktioniert.

-> Dein Problem muss woanders liegen. Ich weiß nicht wo, aber irgendwas stimmt nicht.

_________________
PROGRAMMER: A device for converting coffee into software.
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Do 23.07.09 22:39 
Moin!

Du weißt, dass INI-Dateien (konkret: TIniFile) eine Maximalgrößenbeschränkung von IIRC 64KB haben (und nebenbei gesagt schneckenlangsam sind)? ;) Insgesamt hört sich das alles nach ordentlichem Missbrauch von INI-Files an... :?

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Wolle92 Threadstarter
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 1296

Windows Vista Home Premium
Delphi 7 PE, Delphi 7 Portable, bald C++ & DirectX
BeitragVerfasst: Do 23.07.09 22:47 
ne, wusste ich nicht :oops:

_________________
1405006117752879898543142606244511569936384000000000.
Blackheart666
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2195

XP
D3Prof, D6Pers.
BeitragVerfasst: Fr 24.07.09 06:50 
BigIni bei Torry zb. hat keine Größenbeschränkung.
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Fr 24.07.09 09:12 
Moin!

user profile iconBlackheart666 hat folgendes geschrieben Zum zitierten Posting springen:
BigIni bei Torry zb. hat keine Größenbeschränkung.
Das gibt´s auch als Bordmittel: TMemIniFile (genau genommen kann das ab D7 schon eine TStringList). ;)

Aber entscheidender dürfte sein: Dafür sind INI-Dateien nicht da! :|

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Wolle92 Threadstarter
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 1296

Windows Vista Home Premium
Delphi 7 PE, Delphi 7 Portable, bald C++ & DirectX
BeitragVerfasst: Fr 24.07.09 09:34 
ich brauchte halt ne schnelle lösung, muss nicht sauber sein, nur heute fertig werden... und da ich mit fehlern gerechnet habe, ist die rechnung ja auch aufgegangen...

_________________
1405006117752879898543142606244511569936384000000000.
Blackheart666
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2195

XP
D3Prof, D6Pers.
BeitragVerfasst: Fr 24.07.09 14:38 
user profile iconNarses hat folgendes geschrieben Zum zitierten Posting springen:

Aber entscheidender dürfte sein: Dafür sind INI-Dateien nicht da! :|

Wer sagt das, du ? :wink:
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Fr 24.07.09 23:23 
Moin!

user profile iconBlackheart666 hat folgendes geschrieben Zum zitierten Posting springen:
user profile iconNarses hat folgendes geschrieben Zum zitierten Posting springen:

Aber entscheidender dürfte sein: Dafür sind INI-Dateien nicht da! :|
Wer sagt das, du ? :wink:
Wenn keiner meinen Account geknackt hat, kannst du ja mal raten, wer noch über bleibt. :D

Kann man damit machen <> Ist dafür gemacht

Schau dir die Performance an, dann weißt du was ich meine (und das Beste daran: ich sage dabei nicht mal was :mrgreen:).

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
ffgorcky
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 573

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

BeitragVerfasst: Sa 25.07.09 13:42 
Also ich habe von diesem Thema noch überhaupt keine Ahnung und mich wohl gerade genau deswegen dafür interessiert und mal ein bisschen gesucht.
Gefunden habe ich durch die Suche nach Inidatei Beispiel dann diesen Thread:
[INI] Ini-Datei, Anzahl Einträge einer Section
Ist das nicht genau die Antwort auf Deine Frage?
- Oder hast Du die IDs nicht von 0 oder 1 aufsteigend durchnummeriert?
Xentar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2077
Erhaltene Danke: 2

Win XP
Delphi 5 Ent., Delphi 2007 Prof
BeitragVerfasst: Sa 25.07.09 14:26 
user profile iconffgorcky hat folgendes geschrieben Zum zitierten Posting springen:
Ist das nicht genau die Antwort auf Deine Frage?

Nein ;)
Es ging darum, die Sections auszulesen, nicht die Einträge einer bestimmten Section.

Aber das Thema hat sich inzwischen erledigt. Es lag einfach daran, dass TIniFile nicht für solch große Datenmengen ausgelegt ist.

_________________
PROGRAMMER: A device for converting coffee into software.