本文共 1199 字,大约阅读时间需要 3 分钟。
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;
type
TForm1 = class(TForm)
tmrl: TTimer;
mmo1: TMemo;
edtT1: TEdit;
edtT3: TEdit;
procedure tmrlTimer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function CovFileDate(Fd:_FileTime):TDateTime;
var
Tct:_SystemTime;
Temp:_FileTime;
begin
FileTimeToLocalFileTime(Fd,Temp);
FileTimeToSystemTime(Temp,Tct);
CovFileDate:=SystemTimeToDateTime(Tct);
end;
procedure TForm1.tmrlTimer(Sender: TObject);
const
Model='HH:mm:ss';
var
SysTime: Windows.TSystemTime;
Tp:TSearchRec;
T1,T2,T3:String;
Result:TDateTime;
begin
if FileExists('js.txt') then
begin
FindFirst('js.txt',faAnyFile,Tp);
T2:=FormatDateTime(Model,CovFileDate(Tp.FindData.ftLastWriteTime));
mmo1.Lines.Append(T2);
FindClose(Tp);
T1:=T2;
edtT1.Text:=T1;
mmo1.Lines.Append('循环中T1=T2='+T1);
if(T1<>edtT3.Text) then //T3=''
begin
mmo1.Lines.Append(T1+'变更一次!'); //
T3:=T1;
edtT3.Text:=T3;
end;
end;
end;
end.
算法:
1.定义一个timer每隔几秒自动执行一次;
2.检查文件是否存在,如果存在
3.每隔几秒就获取一次修改时间
4.和初始变量对比,如果值已经发生变化,作出相应处理,并将当前值计入新的edit中
5.将重新获取的值与edit.text值进行对比
转载地址:https://blog.csdn.net/weixin_33102135/article/details/117240934 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!