Recent

Author Topic: unable to load ... textfile  (Read 8760 times)

FDitsche

  • Newbie
  • Posts: 5
unable to load ... textfile
« on: June 21, 2010, 03:12:05 am »
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: [Select]
Memo.Lines.LoadFromFile(....\Error.log);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: [Select]
Memo.Lines.LoadFromFile(....\Error.txt); Same file other name!

after renaming the files back to ".log ..." i can not load them.
Code: [Select]
Memo.Lines.LoadFromFile(....\Error.log); Same file other name!

i also tried
Code: [Select]
listbox1.items.loadfromfile - 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
Von Zeit zu Zeit seh ich den Alten gern, Und hüte mich, mit ihm zu brechen.
Es ist gar hübsch von einem großen Herrn, So menschlich mit dem Teufel selbst zu sprechen.

Bart

  • Hero Member
  • *****
  • Posts: 5297
    • Bart en Mariska's Webstek
Re: unable to load ... textfile
« Reply #1 on: June 21, 2010, 03:49:36 am »
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: [Select]
  if FileExistst('bla') then Memo.Lines.LoadfromFile('bla')
  else ShowMessage('File "bla" does not exists');

Bart

FDitsche

  • Newbie
  • Posts: 5
Re: unable to load ... textfile
« Reply #2 on: June 21, 2010, 04:08:10 am »
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: [Select]
  if fileexists(ApacheErrorLog) then begin
      try
         ApacheErrorLogMemo.Lines.LoadFromFile(ApacheErrorLog);
      except
         showmessage(inttostr(GetLastOSError));
      end;  
   end;

showmessage says 6

Quote
"Do not show extension for known filetypes"

explorer shows all endings

could it be something like mimetypes?

Thanx

FD
« Last Edit: June 21, 2010, 04:24:31 am by FDitsche »
Von Zeit zu Zeit seh ich den Alten gern, Und hüte mich, mit ihm zu brechen.
Es ist gar hübsch von einem großen Herrn, So menschlich mit dem Teufel selbst zu sprechen.

FDitsche

  • Newbie
  • Posts: 5
Re: unable to load ... textfile
« Reply #3 on: June 21, 2010, 04:29:56 am »
Hello

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

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

Von Zeit zu Zeit seh ich den Alten gern, Und hüte mich, mit ihm zu brechen.
Es ist gar hübsch von einem großen Herrn, So menschlich mit dem Teufel selbst zu sprechen.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9987
  • Debugger - SynEdit - and more
    • wiki
Re: unable to load ... textfile
« Reply #4 on: June 21, 2010, 04:37:51 am »
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.



FDitsche

  • Newbie
  • Posts: 5
Re: unable to load ... textfile
« Reply #5 on: June 21, 2010, 04:47:07 am »
hi

same second you replied i tested it while apache is off and it works!

this is good, but...

my next job ist to find the way without stopping apache.

a big thank you

FD
Von Zeit zu Zeit seh ich den Alten gern, Und hüte mich, mit ihm zu brechen.
Es ist gar hübsch von einem großen Herrn, So menschlich mit dem Teufel selbst zu sprechen.

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1927
Re: unable to load ... textfile
« Reply #6 on: June 21, 2010, 04:56:46 am »
You could try different Share Modes like:

  TheStream:=TFileStream.Create(FileName,fmOpenRead or fmShareDenyNone);
  Memo1.Lines.LoadFromStream(TheStream);
  TheStream.Free;


Not sure..

FDitsche

  • Newbie
  • Posts: 5
Re: unable to load ... textfile
« Reply #7 on: June 21, 2010, 08:27:27 am »
Hi

sorry for my late reply (sometimes i got to work  ;) )

your code does it

Code: [Select]
var TheStream : TFileStream;
....
   TheStream:=TFileStream.Create(ApacheErrorLog,fmOpenRead or fmShareDenyNone);
   ApacheErrorlogMemo.Lines.LoadFromStream(TheStream);
   TheStream.Free;

many many thanx

FD
Von Zeit zu Zeit seh ich den Alten gern, Und hüte mich, mit ihm zu brechen.
Es ist gar hübsch von einem großen Herrn, So menschlich mit dem Teufel selbst zu sprechen.

 

TinyPortal © 2005-2018