Link to home
Start Free TrialLog in
Avatar of eugene3000
eugene3000

asked on

Delphi newbee: Invalid Filename error when writing to text file

Hello,

I am getting an error "Invalid Filename" when calling tis procedure. The error happens on this line:
  CloseFile(txt);
The file name path is ok, it exists and is well formatted. Could there be something else?
Thank you!
procedure TIWForm1.Punch(Name: string; PunchIn: Boolean);
var
  txt: TextFile;
  I  : Integer;
  strAction: string;
  AppPath: string;
begin
  AppPath:=ExtractFileDir(IWApplication.GGetAppPath);
  if PunchIn = true then
    strAction := 'IN '
  else
    strAction := 'OUT';
 
  AssignFile(txt, AppPath + '\timefiles\' + Name + '.dat');
  Append(txt);
  //OUT   11/26/2001        11:47
  WriteLn(txt, strAction + '   ' + FormatDateTime('mm/dd/yyyy',now) + '        ' + FormatDateTime('hh:nn', now));
  CloseFile(txt);
 
end;

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of dinilud
dinilud
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>>AppPath:=ExtractFileDir(IWApplication.GGetAppPath);


what is the value of AppPath
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of eugene3000
eugene3000

ASKER

to clarify:
I am using this code in Delphi 2007, in an IntraWeb application, if that makes any difference.

what is the value of AppPath
D:\My Code\Everything PunchClock\LionClock Web\program_data\timefiles

guess the content of the parameter name contains invalid chars .
no, it's just a neme of a person like:
Bob Smith

Any ideas?
guess you have to enclose the filename with doubleQuotes " like

"D:\My Code\Everything PunchClock\LionClock Web\program_data\timefiles\Bob Smith.dat"

meikl ;-)
to kretzschmar

The Watch indicates that the entire filename string is indeed enclosed in double quotes. So, that is not the issue. Any other ideas?
try this
procedure TIWForm1.Punch(Name: string; PunchIn: Boolean);
var
  txt: TextFile;
  I  : Integer;
  strAction: string;
  AppPath: string;
  FileName:String;
begin
  AppPath:=ExtractFileDir(IWApplication.GGetAppPath);
  if PunchIn = true then
    strAction := 'IN '
  else
    strAction := 'OUT';
 
  FileName:=AppPath + '\timefiles\' + Name + '.dat';
  WebApplication.ShowMessage(FileName);
  AssignFile(txt, FileName);
  Append(txt);
  //OUT   11/26/2001        11:47
  WriteLn(txt, strAction + '   ' + FormatDateTime('mm/dd/yyyy',now) + '        ' + FormatDateTime('hh:nn', now));
  CloseFile(txt);
 
end;

Open in new window

or try like this

  FileName:=AppPath + '\' + Name + '.dat';
  IWMemo1.Lines.LoadFromFile(FileName);


Is that file is loaded to IWMemo1 component?