Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2009-04

ExtractFilePath(GetModuleName(0)) problem

5 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

lloyd thomas

Need Help please "confini :=
ExtractFilePath(GetModuleName(0))+'\myfile.ini';" returns C:Program FilesMyApp\myfile.ini should be C:\Program Files\MyApp\myfile.ini . Am I doing something wrong?

The Problem is intermitent

    {$IFDEF Windows}
confini  := ExtractFilePath(GetModuleName(0))+'\Myfile.ini';
{$ENDIF}
{$IFDEF Linux}
confini  := GetAppConfigDir(True)+'/callcollex.conf';
{$ENDIF}
   IniFile := TIniFile.Create(confini);

returns an error as follows
project raised exception class 'EFopenError' with message: Unable to open file "C:Program FilesMyApp\myfile.ini"

Reply by email

lloyd thomas

Need Help please "confini :=
ExtractFilePath(GetModuleName(0))+'\myfile.ini';" returns C:Program FilesMyApp\myfile.ini should be C:\Program Files\MyApp\myfile.ini . Am I doing something wrong?

The Problem is intermitent

    {$IFDEF Windows}
confini  := ExtractFilePath(GetModuleName(0))+'\Myfile.ini';
{$ENDIF}
{$IFDEF Linux}
confini  := GetAppConfigDir(True)+'/callcollex.conf';
{$ENDIF}
   IniFile := TIniFile.Create(confini);

returns an error as follows
project raised exception class 'EFopenError' with message: Unable to open file "C:Program FilesMyApp\myfile.ini"

Reply by email

Michael Van Canneyt
to lloyd thomas: Need Help please "confini := ExtractFilePath(GetModuleName(0))+'\myfile.ini';" returns…
lloyd thomas wrote 9 lines
Need Help please "confini := ExtractFilePath(GetModuleName(0))+'\myfile.ini';" returns C:Program FilesMyApp\myfile.ini should be C:\Program Files\MyApp\myfile.ini . Am I doing something wrong? The Problem is intermitent {$IFDEF Windows} confini := ExtractFilePath(GetModuleName(0))+'\Myfile.ini';

Another thing: Do not add a \ yourself. ExtractFilePath returns as the last character a \ , so you'll have MyApp\\MyFile.ini in the end, and I think windows doesn't like that.

Michael.

Reply by email

Michael Van Canneyt
to lloyd thomas: Need Help please "confini := ExtractFilePath(GetModuleName(0))+'\myfile.ini';" returns…
lloyd thomas wrote 19 lines
Need Help please "confini := ExtractFilePath(GetModuleName(0))+'\myfile.ini';" returns C:Program FilesMyApp\myfile.ini should be C:\Program Files\MyApp\myfile.ini . Am I doing something wrong? The Problem is intermitent {$IFDEF Windows} confini := ExtractFilePath(GetModuleName(0))+'\Myfile.ini'; {$ENDIF} {$IFDEF Linux} confini := GetAppConfigDir(True)+'/callcollex.conf'; {$ENDIF} IniFile := TIniFile.Create(confini); returns an error as follows project raised exception class 'EFopenError' with message: Unable to open file "C:Program FilesMyApp\myfile.ini"

Try using ParamStr(0) instead of GetModuleName()
I've never had any problems with that.

Michael.

Reply by email