Detect file changePosted by james on December 30, 2004 at 03:59:50: I have a non delphi application that grabs news from internet and dumps it in a text file. I'm trying to code something that grabs the last line from the text file and dumps it in a TMemo. I'm using a timer for this. So far I have managed to grab the text but the problem is that it keeps showing in Tmemo the same line over and over till new text comes in. I just want to grab the text only when file changes. Any thoughts on how I could do this? Working code sample would be appreciated. function ReadFile(YourFileName:string):string; var F:TextFile; S:string; begin if FileExists('C:\Changes.txt') then begin AssignFile(F, 'C:\Changes.txt'); Reset(F); while not EOF(F) do begin ReadLn(F, S); Result:=S; end; CloseFile(F); end; end; procedure TForm1.Timer1Timer(Sender: TObject); begin Memo1.lines.add( ReadFile('C:\Changes.txt')); end; procedure TForm1.Button1Click(Sender: TObject); begin Timer1.Enabled :=True end; procedure TForm1.Button2Click(Sender: TObject); begin Timer1.Enabled :=False end; end. Related Articles and Replies
|