Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Load INI DB To Listview

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

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…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …

926 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