我的程序大体是这样的:
procedure TmainForm.FormCreate(Sender: TObject); //启动配置
var
filename,yhqx,autotime:string;
i:integer;
hour,minute,second:word;
newTime:TSystemTime;
begin
quit:=false;
//screen.cursor:=crsqlwait;
//=====================读取配置文件===================//
Filename:=ExtractFilePath(Paramstr(0))+'office.ini';
myinifile:=Tinifile.create(filename);
servername:=myinifile.Readstring('数据服务器','servername','mainSERVER');
Autotime:=myinifile.Readstring('时间调整','autotime','T');
//===================== 设置并建立连接 ===================//
ADOConnection1.Connectionstring:='Provider=SQLOLEDB.1;'+
'Persist Security Info=False;'+
'User ID=sa;'+
'Initial Catalog=office;'+
'Data Source='+servername+';'+
'Locale Identifier=2052;'+
'Connect Timeout=3;'+
'Use Procedure for Prepare=1;'+
'Auto Translate=True;'+
'Packet Size=4096;'+
'Workstation ID=sunyb';
try
ADOConnection1.connected:=true;
except
application.MessageBox(pchar('服务器 "'+servername+'" 连接失败!请检查服务器及数据库是否打开或网络是否正常。'),pchar(application.title),mb_ok+mb_iconhand);
application.Terminate; //这里有可能退出
end;
//=====================同步服务器时间===================//
IF AutoTime='T' then
begin
with adoquery1 do
begin
SQL.TEXT:='SELECT convert(varchar(19),getdate(),120)';
open;
year:=strtoint(copy(Fields[0].asstring,1,4));
month:=strtoint(copy(Fields[0].asstring,6,2));
day:= strtoint(copy(Fields[0].asstring,9,2));
hour:=strtoint(copy(Fields[0].asstring,12,2));
minute:=strtoint(copy(Fields[0].asstring,15,2));
second:=strtoint(copy(Fields[0].asstring,18,2));
Close;
end;
with newtime do
begin
wYear:=year;
wMonth:=month;
wDay:=day;
wHour:=hour;
wMinute:=minute;
wSecond:=second;
wMilliseconds:=0;
end;
SetLocalTime(newtime);
SendMessage(HWND_BROADCAST,WM_TIMECHANGE,0,0); //时间广播到当前运行各进程
end;
//===================== 程序有效期 ===================//
decodedate(date,year,month,day);
if 。。。。then
begin
application.MessageBox(pchar('程序已过测试期,请安装更新版本!'),pchar(''),mb_ok+mb_iconwarning);
application.Terminate; //这里有可能退出
end;
//===================== 登录并设置权限 ===================//
//screen.cursor:=crdefault;
try
logonform := tlogonform.create(self);
logonform.showmodal;
finally
logonform.free;
end;
////////////////////
if quit=true then //根据登录情况判断这里可能退出
Application.Terminate
else
begin
设置权限。。。
end;
end;