AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

In English (Ini question)

Ein Thema von jcop · begonnen am 26. Dez 2004 · letzter Beitrag vom 28. Dez 2004
Antwort Antwort
Seite 1 von 2  1 2      
jcop

Registriert seit: 16. Dez 2004
9 Beiträge
 
Delphi 2005 Personal
 
#1

In English (Ini question)

  Alt 26. Dez 2004, 12:05
Hello,

Sorry i write this in english (I can read and understand german, just no write correctly)

I would like to read some values from a ini file, but not the sections, some lines in the title.
EG

[Section.1]
Title= Nissan
colour= Red

[Section.2]
Title= Renault
colour= Blue

etc...

I just want a combobox showing all titles from this ini file

Nissan
Renault
etc...

I know you can do that with readscetions, but then it's reading all [] and thats not the result what I want cause I also have a section

[general]
settings=56

and this may not be shown in the combobox or listbox.

hope you can assist me.
Merry X-mass to all of you.
  Mit Zitat antworten Zitat
Fubar

Registriert seit: 8. Sep 2004
Ort: bei Stuttgart
30 Beiträge
 
Delphi 7 Professional
 
#2

Re: In English (Ini question)

  Alt 26. Dez 2004, 12:14
Du kannst doch "ReadSections" verwenden und anschliessend aus jeder Section den Eintrag "Title" herauslesen.
  Mit Zitat antworten Zitat
jcop

Registriert seit: 16. Dez 2004
9 Beiträge
 
Delphi 2005 Personal
 
#3

Re: In English (Ini question)

  Alt 26. Dez 2004, 12:19
Yes I know how to perform the readsections, but I don't know how extract the title's, should I create a streamtype or array for those?
Thanks for the quick reply
  Mit Zitat antworten Zitat
Elite
(Gast)

n/a Beiträge
 
#4

Re: In English (Ini question)

  Alt 26. Dez 2004, 12:29
Nehm doch die Funktion ReadString(const Section, Ident, Default: String): String;
So benutzt du die:
Code:
MyTitleVar := MyIni.ReadString('Section.1', 'Title', 'TheDefaultTitle');
  Mit Zitat antworten Zitat
Christian Seehase
(Co-Admin)

Registriert seit: 29. Mai 2002
Ort: Hamburg
11.105 Beiträge
 
Delphi 11 Alexandria
 
#5

Re: In English (Ini question)

  Alt 26. Dez 2004, 13:13
Moin Jcop,

Welcome to Delphi-PRAXiS.

First you can read all sectionnames into a TStringList using ReadSections.
Then you remove the fixed section names.
Now you can loop through the TStringList and read all title entries to add them to the TComboBox.
Tschüss Chris
Die drei Feinde des Programmierers: Sonne, Frischluft und dieses unerträgliche Gebrüll der Vögel.
Der Klügere gibt solange nach bis er der Dumme ist
  Mit Zitat antworten Zitat
Benutzerbild von Sprint
Sprint

Registriert seit: 18. Aug 2004
Ort: Edewecht
712 Beiträge
 
Delphi 5 Professional
 
#6

Re: In English (Ini question)

  Alt 26. Dez 2004, 13:51
Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
const
  S_TITLE = 'Title';
var
  Sections: TStringList;
  I: Integer;
begin

  Sections := TStringList.Create;
  try
    IniFile.ReadSections(Sections);
    for I := 0 to Sections.Count - 1 do
    begin
      if IniFile.ValueExists(Sections[I], S_TITLE) then
        ComboBox1.Items.Add(IniFile.ReadString(Sections[I], S_TITLE, ''));
    end;
  finally
    Sections.Free;
  end;

end;
Ciao, Sprint.

"I don't know what I am doing, but I am sure I am having fun!"
  Mit Zitat antworten Zitat
jcop

Registriert seit: 16. Dez 2004
9 Beiträge
 
Delphi 2005 Personal
 
#7

Re: In English (Ini question)

  Alt 26. Dez 2004, 14:31
Thanks, seems to be working, danke sehr, dank U, merci etc....
  Mit Zitat antworten Zitat
Christian Seehase
(Co-Admin)

Registriert seit: 29. Mai 2002
Ort: Hamburg
11.105 Beiträge
 
Delphi 11 Alexandria
 
#8

Re: In English (Ini question)

  Alt 26. Dez 2004, 15:48
Moin Sprint,

gute Idee, so geht's natürlich noch besser.
(vorausgesetzt, dass es den Wertnamen nicht noch in einer anderen Section gibt)
Tschüss Chris
Die drei Feinde des Programmierers: Sonne, Frischluft und dieses unerträgliche Gebrüll der Vögel.
Der Klügere gibt solange nach bis er der Dumme ist
  Mit Zitat antworten Zitat
jcop

Registriert seit: 16. Dez 2004
9 Beiträge
 
Delphi 2005 Personal
 
#9

Re: In English (Ini question)

  Alt 27. Dez 2004, 14:48
Hello,

Again a question concerning this method.

[Section.1]
Title= Nissan
colour= Red
engine= 1400cc
Turbo = no

[Section.2]
Title= Renault
colour= Blue
engine = 1800
Turbo= yes

Now I can see the titles inside de combobox, but when I click on 1 of them to view the colour for eg.
my dedicated textbox stays empty.
I was using the following method for this function but then again this was only working when loading the sections into the combobox.
Delphi-Quellcode:
procedure TForm1.cboSectionsChange(Sender: TObject);
begin
  carconfig := Tinifile.Create(opendialog1.FileName);

  with carconfig do
  try
  ReadSections(CboSections.Items);

  txtTitle.Text := Readstring(cboSections.Text, 'Title', '');
  txtColour.Text := ReadString (cboSections.Text, 'Colour', '');
  txtEngine.Text := ReadString (cboSections.Text, 'engine', '');
  txtTurbo.Text := ReadString (cboSections.Text, 'Turbo','');

  Finally
  carconfig.Free;
  end;
end;
I was thinking of porting the button1.openclick event also into the cbosctionschange event but that's resulting in a error.

Hope you can help me this one also, providing me with the right direction to search would also be welcome.
Thanks
  Mit Zitat antworten Zitat
Benutzerbild von Sprint
Sprint

Registriert seit: 18. Aug 2004
Ort: Edewecht
712 Beiträge
 
Delphi 5 Professional
 
#10

Re: In English (Ini question)

  Alt 27. Dez 2004, 15:48
Zitat von jcop:
I was thinking of porting the button1.openclick event also into the cbosctionschange event but that's resulting in a error.
Delphi-Quellcode:
type
  TForm1 = class(TForm)
  ...
  private
    { Private-Deklarationen }
    IniFile: TIniFile;
  ...
  end;

  ...

{------------------------------------------------------------------------------}

procedure TForm1.FormDestroy(Sender: TObject);
begin

  if Assigned(IniFile) then
    IniFile.Free;

end;

{------------------------------------------------------------------------------}

procedure TForm1.ComboBox1Change(Sender: TObject);
var
  Sections: TStringList;
  I: Integer;
begin

  Sections := TStringList.Create;
  try
    with Sections, IniFile, ComboBox1 do
    begin
      ReadSections(Sections);
      for I := 0 to Sections.Count - 1 do
        if ReadString(Sections[I], 'Title', '') = Items[ItemIndex] then
        begin
          txtTitle.Caption := ReadString(Sections[I], 'Title', '');
          txtColour.Caption := ReadString(Sections[I], 'Colour', '');
          txtEngine.Caption := ReadString(Sections[I], 'Engine', '');
          txtTurbo.Caption := ReadString(Sections[I], 'Turbo', '');
        end;
    end;
  finally
    Sections.Free;
  end;

end;

{------------------------------------------------------------------------------}

procedure TForm1.Button1Click(Sender: TObject);
var
  Sections: TStringList;
  I: Integer;
begin

  if OpenDialog1.Execute then
  begin
    if Assigned(IniFile) then
      FreeAndNil(IniFile);
    IniFile := TIniFile.Create(OpenDialog1.FileName);
    Sections := TStringList.Create;
    try
      with IniFile, ComboBox1 do
      begin
        Clear;
        ReadSections(Sections);
        for I := 0 to Sections.Count - 1 do
          if ValueExists(Sections[I], 'Title') then
            Items.Add(ReadString(Sections[I], 'Title', ''));
      end;
    finally
      Sections.Free;
    end;
  end;

end;

{------------------------------------------------------------------------------}

  ...
Ciao, Sprint.

"I don't know what I am doing, but I am sure I am having fun!"
  Mit Zitat antworten Zitat
Antwort Antwort
Seite 1 von 2  1 2      


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 13:26 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz