Kapusta
asked on
Open a text file in WRITE-ONLY mode
Is it possible to open a Text file for WRITE-ONLY access. I do NOT want READ and WRITE access, but rather just WRITE-ONLY access. I am using Delphi 1.
I normally use the following routine for creating/appending text files:
var
LogFileHandle : System.Text;
Path , Logfilename : String;
...
begin
...
if LogfileName = '' then LogfileName := 'RECORD.LOG';
System.Assign(LogFileHandl e, Path + LogFileName);
try
if FileExists(Path + LogfileName) then
Append(LogFileHandle)
else
Rewrite(LogFileHandle);
{end if}
except
on E:Exception do begin
ShowMessage(E.Message); {show the user what the error was}
System.Close(LogFileHandle );
end;
end;
The file in the example above will be written/created on a Novell network where the directory (Path) will NOT have READ access rights...only WRITE privileges.
I normally use the following routine for creating/appending text files:
var
LogFileHandle : System.Text;
Path , Logfilename : String;
...
begin
...
if LogfileName = '' then LogfileName := 'RECORD.LOG';
System.Assign(LogFileHandl
try
if FileExists(Path + LogfileName) then
Append(LogFileHandle)
else
Rewrite(LogFileHandle);
{end if}
except
on E:Exception do begin
ShowMessage(E.Message); {show the user what the error was}
System.Close(LogFileHandle
end;
end;
The file in the example above will be written/created on a Novell network where the directory (Path) will NOT have READ access rights...only WRITE privileges.
ASKER
Sorry, but your solution does not work. It does not allow me to write text to ASCII text files.
This function --> Append(LogFileHandle) will generate an ERROR 77 (File variable expected).
Here's the modified code based upon your suggestion:
var
MyPChar : array[0..255] of Char;
LogFileHandle : THandle;
Path, LogFileName : String
begin
...
if LogfileName = '' then LogfileName := 'RECORD.LOG';
{System.Assign(LogFileHand le, ReadFromAlternatePath + LogFileName);}
LogFileHandle := _lopen(StrPCopy(MyPChar,Pa th + LogFileName), OF_WRITE);
try
if FileExists(Path + LogfileName) then
Append(LogFileHandle)
else
Rewrite(LogFileHandle);
{end if}
except
on E:Exception do begin
ShowMessage(E.Message); {show the user what the error was}
{System.Close(LogFileHandl e);}
_lclose(LogFileHandle);
end;
This function --> Append(LogFileHandle) will generate an ERROR 77 (File variable expected).
Here's the modified code based upon your suggestion:
var
MyPChar : array[0..255] of Char;
LogFileHandle : THandle;
Path, LogFileName : String
begin
...
if LogfileName = '' then LogfileName := 'RECORD.LOG';
{System.Assign(LogFileHand
LogFileHandle := _lopen(StrPCopy(MyPChar,Pa
try
if FileExists(Path + LogfileName) then
Append(LogFileHandle)
else
Rewrite(LogFileHandle);
{end if}
except
on E:Exception do begin
ShowMessage(E.Message); {show the user what the error was}
{System.Close(LogFileHandl
_lclose(LogFileHandle);
end;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
var FileHandle: THandle;
begin
FileHandle:=_lopen('Some path', OF_WRITE);
{ ... do something}
_lclose(FileHandle);
end;
{for more information see the File Functions in API help.}