Autor Beitrag
sabi_14
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 40



BeitragVerfasst: Mi 08.10.08 10:44 
Hallo zusammen,
ich hoffe mir kann jemand helfen.
also, ich habe ein ini file, welches ungfähr so aussieht:
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
[Database]
Driver=bla
Servername=blubb
User=Test
Paswort=glugg

[Test]
etwas=gligg
nochwas=blala


und nun möchte ich, dass es mir in einer Kombobox nur diejenigen Sections anzeigt, welche die Zeile Passwort haben.
mit ini.ReadString bekomme ich aber nur den Wert und nicht die ganze Zeile herraus.
Weiss jemand eine Lösung?

Danke schonmal im vorraus. (benutze Delphi 5)
Grüsse
Sabi

Moderiert von user profile iconmatze: INI-Text hervorgehoben
DeddyH
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Mi 08.10.08 11:08 
Du möchtest die Namen der Sections, die den Ident "Passwort" aufweisen, in der ComboBox listen? In Deinem Beispiel also "Database"?
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: Mi 08.10.08 11:21 
Du musst dir zuerst eine Liste der Sektionen holen und dann in jeder schauen ob es den Eintrag Passwort gibt:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
var
  ini: TIniFile;
  SectionList: TStringList;
  i: Integer;
begin
  ini := TIniFile.Create(ExtractFilePath(ParamStr(0)) + 'test.ini');
  SectionList := TStringList.Create;
  ini.ReadSections(SectionList);
  for i := 0 to SectionList.Count - 1 do
    if ini.ValueExists(SectionList[i], 'Passwort') then
      cbbPasswordSections.Items.Add(SectionList[i]);
  SectionList.Free;
  ini.Free;
DeddyH
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Mi 08.10.08 11:28 
Und mit Ressourcen-Schutzblöcken sähe das dann etwa so aus:
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:
procedure TForm1.Button1Click(Sender: TObject);
var ini: TIniFile;
    i: integer;
    secs: TStringList;
begin
  ComboBox1.Items.BeginUpdate;
  ini := TIniFile.Create('C:\test.ini');
  try
    secs := TStringList.Create;
    try
      ComboBox1.Items.Clear;
      ini.ReadSections(secs);
      for i := 0 to Pred(secs.Count) do
        if ini.ValueExists(secs[i],'Passwort') then
          ComboBox1.Items.Add(secs[i]);
    finally
      secs.Free;
    end;
  finally
    ini.Free;
    ComboBox1.Items.EndUpdate;
  end;
end;
sabi_14 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 40



BeitragVerfasst: Mi 08.10.08 12:32 
Hey,
danke leute für eure schnelle Antwort.
@jaenicke: Danke, dies hat super funktioniert.

schöner Tag noch.
Grüsse
Sabi