Solved

Load INI DB To Listview

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now