Solved

Load INI DB To Listview

Posted on 2003-11-12
4
346 Views
Last Modified: 2010-04-05
Hi, does anyone know how to load an INI file into a listview.

[MyDatabase1]
Table0=Field0
Table1=Field1
Table2=Field2
Table3=Field3
Table4=Field4

[MyDatabase2]
Table0=Field0
Table1=Field1
Table2=Field2
Table3=Field3
Table4=Field4

[MyDatabase3]
Table0=Field0
Table1=Field1
Table2=Field2
Table3=Field3
Table4=Field4

I would like to load [MyDatabase2] only into the listview like below.

Table    | Field
Table0    Field0
Table1    Field1
Table2    Field2
Table3    Field3
Table4    Field4

thxs
0
Comment
Question by:SaLz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 9737945
procedure TForm1.Button1Click(Sender: TObject);
var
i:Integer;
s: TStrings;
l: TListItem;
C: TListColumn;
begin
   s := TStringList.Create;
   try
   s.LoadFromFile('MyIniDb.ini');
   with ListView1 do begin
      ViewStyle := vsReport;
      Columns.Clear;
      C := Columns.Add;
      C.Caption := 'Table';
      c.AutoSize := true;
      C := Columns.Add;
      C.Caption := 'Field';
      c.AutoSize := true;
      for i := 0 to s.Count-1 do begin
         l := Items.Add;
         l.Caption := S.Names[i];
         l.SubItems.Add(s.Values[l.Caption]);
         end;
      end;
    finally
    s.free;
    end;
end;

F68 ;-)
0
 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 9737951
opss...wait pls...i misunderstood your question...
0
 
LVL 22

Accepted Solution

by:
Ferruccio Accalai earned 50 total points
ID: 9737996
Here's the correct one (sorry for the first wrong code example):

...
uses ...,...,IniFiles;
...
...
procedure TForm1.Button1Click(Sender: TObject);
var
i:Integer;
s: TStrings;
l: TListItem;
C: TListColumn;
MyIni: TiniFile;
begin
   s := TStringList.Create;
   MyIni := TiniFile.Create('c:\MyIniDb.ini');
   try
   MyIni.ReadSectionValues('MyDatabase2',s);
   with ListView1 do begin
      ViewStyle := vsReport;
      Columns.Clear;
      C := Columns.Add;
      C.Caption := 'Table';
      c.AutoSize := true;
      C := Columns.Add;
      C.Caption := 'Field';
      c.AutoSize := true;
      for i := 0 to s.Count-1 do begin
         l := Items.Add;
         l.Caption := S.Names[i];
         l.SubItems.Add(s.Values[l.Caption]);
         end;
      end;
    finally
    s.free;
    MyIni.Free;
    end;
end;

F68 ;-)
0
 
LVL 2

Author Comment

by:SaLz
ID: 9739369
thxu :)))))
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question