delphi - I am trying to create a simple chat program by writing to a shared file on my network -


i trying use timer check the timestamp of file check if has been modified, if true must add line text file richedit. problem continually adds line richedit every 1/4 second (timer interval). have tried different methods can't right.

procedure tform1.timer1timer(sender: tobject); var filet : textfile; filename, readtxt : string; filedate1, filedate2 : integer; begin  assignfile(filet, 's:\share.talk'); filename := 's:\share.talk'; filedate1 := fileage(filename);  if filedate1 <> filedate2 begin reset(filet); readln(filet, readtxt); richedit1.lines.add(readtxt); closefile(filet); filedate2 := filedate1; end;//if end; 

thanks help.

in code

if filedate1 <> filedate2 begin reset(filet); readln(filet, readtxt); richedit1.lines.add(readtxt); closefile(filet); filedate2 := filedate1; end; 

the comparison between filedate , filedate2 assumes these retain values between calls timer1timer. not, because declared local timer1timer , therefore 'forgotten' between calls because stored on stack.

to them retain values, remove declaration on them local timer1timer , declare them fields of tform1 instead.

btw, aware design, going run other issues, how handle concurrent access network textfile, etc, not related specific point asked about.


Comments

Popular posts from this blog

serialization - Convert Any type in scala to Array[Byte] and back -

matplotlib support failed in PyCharm on OSX -

python - Matplotlib: TypeError: 'AxesSubplot' object is not callable -