?
Solved

Load INI DB To Listview

Posted on 2003-11-12
4
Medium Priority
?
353 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 23

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 23

Expert Comment

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

Accepted Solution

by:
Ferruccio Accalai earned 200 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

718 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