代码如下,单击button,根据数据库服务器时间来限制软件使用时间!程序可以运行!但是结束的时候报错!请高手帮忙看看错在哪里?感谢!!
procedure TForm1.Button1Click(Sender: TObject);
function DateNow:TDateTime;
begin
with
ADOQuery1.Create(nil)dotryconnection:=ADOconnection1;
SQL.Text:='select GetDate() as FDate';
Open;
Result:= FieldValues['FDate'];
finallyend;
end;
begin
if DateNow>strtodatetime('2013-05-04 22:21:00') then
begin
showmessage('程序错误!');
application.Terminate;
end;
end;
end. 报错内容图片
procedure TForm1.Button1Click(Sender: TObject);
function DateNow:TDateTime;
begin
with
ADOQuery1.Create(nil)dotryconnection:=ADOconnection1;
SQL.Text:='select GetDate() as FDate';
Open;
Result:= FieldValues['FDate'];
finallyend;
end;
begin
if DateNow>strtodatetime('2013-05-04 22:21:00') then
begin
showmessage('程序错误!');
application.Terminate;
end;
end;
end. 报错内容图片
还是DateNow合格,然后正常关闭报错。
从你代码来看,DateNow这个函数中 时间比较,格式可能有问题,跟踪查一下
两次以上则会出现你说的错误,因为重复ADOQuery1.Create(nil),所以将代码改为如下:procedure TForm1.Button1Click(Sender: TObject);
function DateNow:TDateTime;
begin
with ADOQuery1 do
try
Close;
connection:=ADOconnection1;
SQL.Text:='select GetDate() as FDate';
Open;
Result:= FieldValues['FDate'];
finally
end;
end;begin
if DateNow>strtodatetime('2013-05-08 22:21:00') then
begin
showmessage('程序错误!');
application.Terminate;
end;
end;