Forum > General

unable to load ... textfile

(1/2) > >>

FDitsche:
Hello

i just got a small problem (nothing like this found in the forum):

I want to load textfile content (but other endings (.log, .err ...)) into a Memo (memo.lines.loadfromfile).

--- Code: ---Memo.Lines.LoadFromFile(....\Error.log);
--- End code ---
but i can only load ".txt" files otherwise i get an error while loading the file:

Unable to open file "......"  OK / Ignore

after renaming the files to ".txt" and changing the code i can load them.

--- Code: ---Memo.Lines.LoadFromFile(....\Error.txt);
--- End code ---
Same file other name!

after renaming the files back to ".log ..." i can not load them.

--- Code: ---Memo.Lines.LoadFromFile(....\Error.log);
--- End code ---
Same file other name!

i also tried
--- Code: ---listbox1.items.loadfromfile
--- End code ---
- same problem.

".ini"-files seem to load without problems.

so what is wrong ?

Lazarus 0.9.28.2 B
WinXP SP3
I'm coming from delphi 7

hopefully

FD

Bart:
Please quote the exact error.
You can also query GetLastOSError, it will give you an errorcode (integer), which may tell more about the problem.

Just a thought.
If your Windows Explorer has the option "Do not show extension for known filetypes" (don't know how it is called in English) tuned on, and you did the renaming in Explorer (as opposed to on the commandline), beware that the filename you see in Explorer may not actually be the filename on disk.

You may want to do a quick:


--- Code: ---  if FileExistst('bla') then Memo.Lines.LoadfromFile('bla')
  else ShowMessage('File "bla" does not exists');

--- End code ---

Bart

FDitsche:
Hi

Thanx for soon reply!

The ErrorMessage is:

Unable to open file "c:\xa....\error.log".
Press OK to ignore and risk of data corruption.
Press Cancel to kill the program.

The real code now:

--- Code: ---   if fileexists(ApacheErrorLog) then begin
      try
         ApacheErrorLogMemo.Lines.LoadFromFile(ApacheErrorLog);
      except
         showmessage(inttostr(GetLastOSError));
      end;  
   end;

--- End code ---

showmessage says 6


--- Quote ---"Do not show extension for known filetypes"
--- End quote ---

explorer shows all endings

could it be something like mimetypes?

Thanx

FD

FDitsche:
Hello

this way fails/notfails the same way by editing the extension:


--- Code: ---      slist := TStringlist.Create;
         slist.LoadFromFile(ApacheErrorLog);
         ApacheErrorLogMemo.lines.assign(slist);
      slist.Free;

--- End code ---

Martin_fr:
Just a random guess..

Are you sure the file is not locked by another process?

I don't know which flags (read/readwrite/exclusive, etc) are used by LoadFromFile.
But if for example the logfile is still in use by Apache, then it may be locked.


Navigation

[0] Message Index

[#] Next page

Go to full version