Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Inserting Values From .Ini files in TValueListEditor

Posted on 2006-05-10
4
Medium Priority
?
2,367 Views
Last Modified: 2008-01-09
This is My INI file

[ESPERA]
1=Rafael Rodrigues Guimaraes Lima
48=Flavio Rodrigues
62=pedro

I would like to insert this on TValueListEditor but i don´t know what´s is the Ident on INI file, becouse can be change anytime.

TValueListEditor1.InsertRow(Const Ident from my INI File, Const Value From my Ini File ,true);


0
Comment
Question by:rafaelrgl
  • 2
4 Comments
 
LVL 17

Expert Comment

by:TheRealLoki
ID: 16654546
Do you just mean this?
  ValueListEditor1.Strings.LoadFromFile('d:\someini.ini');
Ir, if you wish to preserve the existing data in the ValueListEditor1 you can just add the values by doing this

var
  sl: tstringlist;
begin
  sl := TStringList.create;
  try
    sl.LoadFromFile('d:\someini.ini');
    ValueListEditor1.Strings.AddStrings(sl);
  finally
    sl.free;
  end;
0
 
LVL 17

Accepted Solution

by:
TheRealLoki earned 1200 total points
ID: 16654586
If you know the "Section" is always "ESPERA" and you only want that 1 section, then you can read just that section by doing the following

var
  sl: tstringlist;
begin
  sl := TStringList.create;
  try
      with TInifile.create('d:\someini.ini') do
      try
        ReadSectionValues('ESPERA', sl);
        //now just add the Section header you wish to display in the ValueListEditor
        SL.Insert(0, '[FROM ESPERA]');
        ValueListEditor1.Strings.Assign(SL);
// or if you want to preserver the existing data in teh ValueListEditor1 you can do the following instead
// ValueListEditor1.AddStrings(SL);
      finally
        free;
      end;
  finally
    sl.free;
  end;
0
 
LVL 5

Assisted Solution

by:Scay7
Scay7 earned 800 total points
ID: 16676916
heres another way...

This example load any ini file and reads everthing out of that ini file, you dont even have to know the section name
because it will load all 'sections' into a list box and you can then click on it to load the relevant value to the valuelisteditor with all key+values inputed...

*.pas file =====
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Grids, ValEdit, inifiles;

type
  TForm1 = class(TForm)
    vle: TValueListEditor;
    Button1: TButton;
    ListBox1: TListBox;
    Edit1: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    procedure Button1Click(Sender: TObject);
    procedure ListBox1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
Ini: TIniFile;
sl : Tstringlist;
begin
Ini := TIniFile.Create(edit1.Text);
ini.ReadSections(listbox1.Items);
Ini.free;
end;

function getvalue(tempdir : string): string;
var
c,d,e : byte;
pathdir : string;
begin

  if tempdir <> '' then
  begin
  c := length(tempdir);
  d := length(tempdir);
    while (tempdir[c] <> '=') do
    begin
    dec(c);
    end;
    inc(c);
    pathdir := '';
      for e := c to d do
      begin
      pathdir := pathdir + tempdir[e];
      end;
  end;
result := pathdir
end;

procedure TForm1.ListBox1Click(Sender: TObject);
var
id, count, x : integer;
Ini: TIniFile;
idname, value : string;
sl1, sl2 : tstringlist;
begin
vle.Strings.Clear;
id := listbox1.ItemIndex;
idname := listbox1.Items.Strings[id];

sl1 := TStringList.create;
sl2 := TStringList.create;
Ini := TIniFile.Create(edit1.Text);

  with ini do
  begin
  readsection(idname, sl1);
  readsectionvalues(idname, sl2);
  end;

count := sl1.Count;

  for x := 0 to count - 1 do
  vle.InsertRow(sl1.Strings[x],getvalue(sl2.Strings[x]),true);

Ini.free;
sl1.free;
sl2.free;
end;

end.
==========

*.dfm file ===
object Form1: TForm1
  Left = 192
  Top = 114
  Width = 696
  Height = 408
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object Label1: TLabel
    Left = 16
    Top = 16
    Width = 286
    Height = 13
    Caption = 'Read Sections                       ReadSections + SectionValues'
  end
  object Label2: TLabel
    Left = 584
    Top = 352
    Width = 86
    Height = 13
    Caption = 'Program by Scay7'
  end
  object vle: TValueListEditor
    Left = 144
    Top = 32
    Width = 529
    Height = 273
    TabOrder = 0
    ColWidths = (
      150
      373)
  end
  object Button1: TButton
    Left = 8
    Top = 320
    Width = 75
    Height = 25
    Caption = 'Load INI'
    TabOrder = 1
    OnClick = Button1Click
  end
  object ListBox1: TListBox
    Left = 8
    Top = 32
    Width = 121
    Height = 273
    ItemHeight = 13
    TabOrder = 2
    OnClick = ListBox1Click
  end
  object Edit1: TEdit
    Left = 88
    Top = 320
    Width = 585
    Height = 21
    TabOrder = 3
    Text = 'c:\test.ini'
  end
end
==========

Peace Scay7

PS loki that last post you made doesnt seem to work?
0
 
LVL 1

Author Comment

by:rafaelrgl
ID: 16695567
Thank you so much.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Screencast - Getting to Know the Pipeline
Suggested Courses

575 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