Solved

Reading a log file without locking it

Posted on 2004-03-30
7
326 Views
Last Modified: 2010-04-05
Hello,

I have a problem reading a text file.
I'm trying to read a log file, that is often written by an application. I'm tryin to make a sort of real-time-log-viewer.

I tried to open and read it with readln and with readfromfile but when the software reads the log, the writing application fails to write some rows and then the log is incomplete.

Can someone help me??

Thank you very much

Roberto
0
Comment
Question by:roburobe
7 Comments
 
LVL 17

Expert Comment

by:mokule
ID: 10711784
What procedure do You use for reading?
0
 
LVL 4

Expert Comment

by:k4hvd77
ID: 10711785
hi,
don't know if it Could work, but just an idea!
make a copy from the File, open the copy, do your Operation and than delete it. "copyfile(PChar('SourcePathFileNameHere'),PChar('TargetPath[FileName]Here'),True)"


k4hvd77
0
 
LVL 27

Accepted Solution

by:
kretzschmar earned 500 total points
ID: 10711797
if u use reset()

then set before

filemode := 0;  //open file for read


if you use a tfilestream use

fmOpenread or fmShareDenyNone

just from head

meikl ;-)
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Author Comment

by:roburobe
ID: 10711976
Meikl, thank you very much and sorry for earlier mistake....

Roburobe
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 10711992
glad to helped you :-))

meikl ;-)
0
 

Author Comment

by:roburobe
ID: 10712876
and what about the .loadfromfile???

Is there a way to execute this method in read-only mode?
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 10712902
>Is there a way to execute this method in read-only mode?

no, not direct,
you could use something like this

var
  f : TFileStream;
begin
  f := TFileStream.Create('YourLogFileNameHere',fmOpenRead or fmShareDenyNone);
  memo1.lines.loadfromStream(f);
  f.free;
end;


meikl ;-)
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now