We help IT Professionals succeed at work.

Read INI

SULTAN
SULTAN asked
on
When im trying to read Win.ini I get the following error:

To many actual parameters.......the code looks some thing like this

f0:='Win.ini';
f1:= WindowsDirectory+'Win.ini';
f2:='load=';
if fileexists (f1) then Form1.seekintext(f1,f2,false)

what can be wrong? the error seems to be  (f1,f2,false)

Any ideas?
Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2004

Commented:
why not use the tinifile-object?

Author

Commented:
whats that?

Commented:
It's a little object packaged with delphi (you can read about it in the hlp file) that's build specifically to read/write/modify ini files.  Pretty handy item that one. TRegIniFile is a similar object meant to work in a similar manner to TIniFile, but it stores it's info in a registry key.

GL
Mike

Author

Commented:
ok...but is there a solution to the code Im allredy using?

Commented:
It's a little difficult as we don't know how you've declared seekInText - could you show us that?

GL
Mike

Author

Commented:
procedure seekintext(datei,wort:string;gleicheschreibweise:boolean);
var sl:TStringList;
x,y:integer;
begin
if fileexists (f1) then
if not gleicheschreibweise then wort:=ansilowercase(wort);
sl:=TStringList.create;
sl.loadfromfile(datei);
if sl.count > 0 then
for x:=0 to sl.count-1 do begin
if not gleicheschreibweise then sl.strings[x]:=ansilowercase(sl.strings[x]);
y:=pos(wort,sl.strings[x]);
if y>0 then begin
dec(y,20);if y<1 then y:=1;
form1.ini01.items.add(f0+' : '+ExtractFileName(copy(sl.strings[x],y,length(wort)+30)));
end;
end;
sl.free;
end;

Author

Commented:
any better?

I have trouble understanding this code my self

Commented:
Hi Sultan.

> I have trouble understanding this code my self

Me too. Could you say why don't you use TIniFile object to perform your task as correctly suggested by meikl? This object was designed especially to work with all those ini files. Let's see the following simple code:

uses IniFiles;

function GetStringFromIni(const FileName, Section, KeyName: string): string;
begin
  Result := '';
  with TIniFile.Create(FileName) do
  try
    Result := ReadString(Section, KeyName, 'default value');
  finally
    Free;
  end;
end;


example of calling:

MyStringValue := GetStringFromIni('win.ini', 'load', 'n/a');

Note: When you work with ini files that reside in \Windows directory, then you can omit the path to windows directory. A simple file name should be enough in this case.

That's it! Similarly, when you need to extract a float number value then replace a call to ReadString by a call to ReadFloat etc. See online help for more info.

Best regards, Ivo.

P.S. I have typed this sample directly into the browser so it may contain several syntax errors...

Author

Commented:
is it posible tho get the next one in line?

for exaple....how would I do if I wanted to list the auto start section in a ListBox?
Commented:
> how would I do if I wanted to list the auto start section in a ListBox?

I can't see this as real problem. Just make use of TIniFile's ReadSection & ReadSectionValues. The former populates a TStrings with key names of a specified ini section, whereas the latter fills the TStrings with corresponding key values.

If you need an sample code, don't hesitate to ask me again.

Best regards, Ivo.
SULTAN:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
CERTIFIED EXPERT

Commented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

accept ivobauer's comment as answer

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Thanks,

geobul
EE Cleanup Volunteer

Explore More ContentExplore courses, solutions, and other research materials related to this topic.