Thread View: borland.public.delphi.nativeapi.win32
10 messages
10 total messages
Started by Monzer George Yazigi
Sat, 28 Jun 2008 12:06
TIniFile Problem
Author: Monzer George Yazigi
Date: Sat, 28 Jun 2008 12:06
Date: Sat, 28 Jun 2008 12:06
28 lines
1785 bytes
1785 bytes
Dear All
I am facing a strange problem. I could not figure it out. it might be so
simple that I could not see.
I have the following code, which create an INI file variable, and read a
section out of the INI file. edAttach and edPicsPath are TEdit controls.
S:=TStringList.Create;
FName:=ExtractFilePath(ParamStr(0))+'file.ini';
IniF:=TIniFile.Create(FName);
IniF.ReadSection('FILLERSETS',S);
edAttach.Text:=S.Values['Attachments'];
edPicsPath.Text:=S.Values['Images'];
When debugging, the FName is set properly to the correct full file path.
But when reading the section and its values, its always empty.
I tried the direct reading
IniF.ReadString('FILLERSETS','Attachments','') but still it didnt work.
Somehow, IniF is not created properly.
I am using Delphi 2007 for Win32 / Vista Business Edition
Any advice
Regards
Re: TIniFile Problem
Author: John Herbster
Date: Sat, 28 Jun 2008 14:30
Date: Sat, 28 Jun 2008 14:30
23 lines
1759 bytes
1759 bytes
"Monzer George Yazigi" <monzer_yazigi@hotmail.com> wrote
> I have the following code, which create an INI file variable, and read a
> section out of the INI file. edAttach and edPicsPath are TEdit controls.
> S:=TStringList.Create;
> FName:=ExtractFilePath(ParamStr(0))+'file.ini';
> IniF:=TIniFile.Create(FName);
> IniF.ReadSection('FILLERSETS',S);
> edAttach.Text:=S.Values['Attachments'];
> edPicsPath.Text:=S.Values['Images'];
> When debugging, the FName is set properly to the correct full file path.
> But when reading the section and its values, its always empty.
> ...
> Somehow, IniF is not created properly.
Monzer,
Have you updated, closed, or freed the INI file and
tried looking at it with NotePad?
Rgds, JohnH
Re: TIniFile Problem
Author: Monzer George Yazigi
Date: Sat, 28 Jun 2008 23:42
Date: Sat, 28 Jun 2008 23:42
26 lines
1895 bytes
1895 bytes
John Herbster wrote:
> "Monzer George Yazigi" <monzer_yazigi@hotmail.com> wrote
>> I have the following code, which create an INI file variable, and read a
>> section out of the INI file. edAttach and edPicsPath are TEdit controls.
>> S:=TStringList.Create;
>> FName:=ExtractFilePath(ParamStr(0))+'file.ini';
>> IniF:=TIniFile.Create(FName);
>> IniF.ReadSection('FILLERSETS',S);
>> edAttach.Text:=S.Values['Attachments'];
>> edPicsPath.Text:=S.Values['Images'];
>> When debugging, the FName is set properly to the correct full file path.
>> But when reading the section and its values, its always empty.
>> ...
>> Somehow, IniF is not created properly.
>
> Monzer,
>
> Have you updated, closed, or freed the INI file and
> tried looking at it with NotePad?
>
> Rgds, JohnH
Hi John,
Yes, I tried all possible cases. This is really strange.
Regards
Re: TIniFile Problem
Author: John Herbster
Date: Sun, 29 Jun 2008 01:17
Date: Sun, 29 Jun 2008 01:17
44 lines
2274 bytes
2274 bytes
"Monzer George Yazigi" <monzer_yazigi@hotmail.com> wrote
>>> I am using Delphi 2007 for Win32 / Vista Business Edition
>>> ... Somehow, IniF is not created properly.
>> Have you updated, closed, or freed the INI file and
>> tried looking at it with NotePad?
> Yes, I tried all possible cases.
Monzer,
So what did NotePad show you?
Did it look like a properly constructed INI file?
In order to avoid spelling mistakes I usually parameterize the
names -- maybe something like this::
Const {To be used for both reading and writing}
IniFileName = 'File.INI';
FillerSectName = 'FILLERSETS';
AttachmentsName = 'Attachments';
ImagesName = 'Images';
procedure TForm1.Button1Click(Sender: TObject);
var SL: TStringList; IniF: TIniFile; FName, s: string;
begin
FName:=ExtractFilePath(ParamStr(0)) + IniFileName;
IniF:=TIniFile.Create(FName);
Try
SL := TStringList.Create;
IniF.ReadSection(FillerSectName,SL);
edAttach.Text := SL.Values[AttachmentsName];
edPicsPath.Text := SL.Values[ImagesName];
Finally
SL.Free;
IniF.Free;
End;
end;
I see that you are using Vista.
Does your EXE directory permit writing of an INI file?
Rgds, JohnH
Re: TIniFile Problem
Author: Monzer George Yazigi
Date: Mon, 14 Jul 2008 11:33
Date: Mon, 14 Jul 2008 11:33
55 lines
2607 bytes
2607 bytes
hi
Thanks for your support. I found the problem. For a reason, the
application was looking for the file in the Windows\System directory
rather than looking into the same folder of the EXE. This is funny.
When I included he file path, then it works fine.
Regards
On Sat, 28 Jun 2008 20:17:51 -0500, "John Herbster"
<herb-sci1_AT_sbcglobal.net> wrote:
>"Monzer George Yazigi" <monzer_yazigi@hotmail.com> wrote
>
>>>> I am using Delphi 2007 for Win32 / Vista Business Edition
>>>> ... Somehow, IniF is not created properly.
>
>>> Have you updated, closed, or freed the INI file and
>>> tried looking at it with NotePad?
>
>> Yes, I tried all possible cases.
>
>Monzer,
>
>So what did NotePad show you?
>Did it look like a properly constructed INI file?
>
>In order to avoid spelling mistakes I usually parameterize the
>names -- maybe something like this::
>
>Const {To be used for both reading and writing}
> IniFileName = 'File.INI';
> FillerSectName = 'FILLERSETS';
> AttachmentsName = 'Attachments';
> ImagesName = 'Images';
>
>procedure TForm1.Button1Click(Sender: TObject);
>var SL: TStringList; IniF: TIniFile; FName, s: string;
>begin
> FName:=ExtractFilePath(ParamStr(0)) + IniFileName;
> IniF:=TIniFile.Create(FName);
> Try
> SL := TStringList.Create;
> IniF.ReadSection(FillerSectName,SL);
> edAttach.Text := SL.Values[AttachmentsName];
> edPicsPath.Text := SL.Values[ImagesName];
> Finally
> SL.Free;
> IniF.Free;
> End;
>end;
>
>I see that you are using Vista.
>Does your EXE directory permit writing of an INI file?
>
>Rgds, JohnH
Re: TIniFile Problem
Author: John Herbster
Date: Mon, 14 Jul 2008 12:27
Date: Mon, 14 Jul 2008 12:27
11 lines
1543 bytes
1543 bytes
"Monzer George Yazigi" <monzer_yazigi@hotmail.com> wrote > ... the application was looking for the file in the Windows\System > directory rather than looking into the same folder of the EXE. ... > When I included he file path, then it works fine. Monzer, Please be aware that the folder where the EXE resides may become readonly in future versions of Windows. Regards, JohnH
Re: TIniFile Problem
Author: Remy Lebeau (TeamB)
Date: Mon, 14 Jul 2008 17:39
Date: Mon, 14 Jul 2008 17:39
13 lines
1484 bytes
1484 bytes
"Monzer George Yazigi" <monzer_yazigi@hotmail.com> wrote in message news:j7em7455nufa9o13dn8vhi6eo76s0gbbjt@4ax.com... > Thanks for your support. I found the problem. For a reason, > the application was looking for the file in the Windows\System > directory rather than looking into the same folder of the EXE. That is what it is supposed to do when you don't specify a full path, just a filename. Gambit
Re: TIniFile Problem
Author: Monzer George Yazigi
Date: Mon, 14 Jul 2008 19:06
Date: Mon, 14 Jul 2008 19:06
23 lines
1740 bytes
1740 bytes
Hi Logically, it should look first in the current directory of the EXE before going to Windows\System folder. anyway, thanks for your kind support. On Mon, 14 Jul 2008 10:39:49 -0700, "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com> wrote: > >"Monzer George Yazigi" <monzer_yazigi@hotmail.com> wrote in message >news:j7em7455nufa9o13dn8vhi6eo76s0gbbjt@4ax.com... > >> Thanks for your support. I found the problem. For a reason, >> the application was looking for the file in the Windows\System >> directory rather than looking into the same folder of the EXE. > >That is what it is supposed to do when you don't specify a full path, just a >filename. > > >Gambit >
Re: TIniFile Problem
Author: Chris Rolliston
Date: Mon, 14 Jul 2008 21:50
Date: Mon, 14 Jul 2008 21:50
6 lines
1387 bytes
1387 bytes
> Logically, it should look first in the current directory of the EXE > before going to Windows\System folder. You are confusing the 'current directory' (set explicitly with SetCurrentDir and implicitly through a file dialog, amongst other possible things) with the directory in which the EXE resides.
Re: TIniFile Problem
Author: Remy Lebeau (TeamB)
Date: Mon, 14 Jul 2008 22:20
Date: Mon, 14 Jul 2008 22:20
16 lines
1843 bytes
1843 bytes
"Monzer George Yazigi" <monzer_yazigi@hotmail.com> wrote in message news:ur8n74l1t5ct0qd6oj0jiop1hcr8t3lbkr@4ax.com... > Logically, it should look first in the current directory of > the EXE before going to Windows\System folder. Windows INI files are not that logical, though. In the Windows 3.1 days, all INI files were stored underneath the system folder, and no file paths were specified in code when accessing them. So, for backwards compatibility, Win9x onwards have to maintain that logic when no paths are specified for INI files. If you want to access an INI file in a specific location, you have to provide the full path. Gambit
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads