Solved

Load INI DB To Listview

Posted on 2003-11-12
4
340 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
  • 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

792 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