//------------------------------------------------------------------------------
//工程文件
//------------------------------------------------------------------------------
program StockManage;
uses
Forms,
Windows,
Messages,
MDIMain in 'MDIMain.pas' {MDIMainForm},
MainDM in 'MainDM.pas' {MainDMForm: TDataModule},
Splash in 'Splash.pas' {SplashForm},
LogIn in 'LogIn.pas' {LogInForm},
Global in 'Global.pas';
{$R *.res}
var
hMutex,hApp:HWND;
begin
Application.Initialize;
//建立互斥对象
hMutex:=CreateMutex(nil,False,PChar(SAppName));
If GetLastError=ERROR_ALREADY_EXISTS Then
begin
//已经运行,找到句柄
hApp:=FindWindow('TApplication',PChar(SAppName));
//激活
if IsIconic(hApp) then
PostMessage(hApp,WM_SYSCOMMAND,SC_RESTORE,0);
SetForegroundWindow(hApp);
//释放互斥对象
ReleaseMutex(hMutex);
Application.Terminate;
exit;
end;
Application.HintPause :=500;
Application.HintHidePause :=10000;
Application.ShowMainForm :=False;
Application.OnMessage := MDIMainForm.AppMessageHandler;
//{
//显示闪现窗体并检查密码
if not (ShowSplashForm and CheckPassWord) then
begin
ReleaseMutex(hMutex);
application.Terminate;
exit;
end;
//}
Application.CreateForm(TMDIMainForm, MDIMainForm);
Application.Run;
//释放互斥对象
ReleaseMutex(hMutex);
end.
//------------------------------------------------------------------------------
//Splash.pas,Splash.dfm
//闪现窗体,并联接数据库
//------------------------------------------------------------------------------
unit Splash;
interface
uses
Windows, Messages, SysUtils, Classes, Controls, Forms,
Dialogs, ExtCtrls,Global,ADODB, MainDM, Graphics, StdCtrls;
type
TSplashForm = class(TForm)
dlgOpen: TOpenDialog;
imgBack: TImage;
private
{ Private declarations }
public
{ Public declarations }
end;
function ShowSplashForm:boolean;
var
SplashForm: TSplashForm;
implementation
{$R *.dfm}
function ShowSplashForm:boolean;
//显示闪现窗口,同时连接数据库,如果失败则选择其它数据库
function OpenDBFile:boolean;
//选择数据库
begin
result:=true;
SplashForm.dlgopen.FileName:=sDataBaseName;
if SplashForm.dlgopen.Execute then
sDataBaseName:=SplashForm.dlgopen.FileName
else
result:=false;
Application.ProcessMessages;
end;
begin
Screen.Cursor:=crHourGlass;
result:=true;
SplashForm:=TSplashForm.Create(Application);
SplashForm.Show;
SplashForm.Refresh;
if length(sDataBaseName)=0 then
sDataBaseName:=ExtractFilePath(application.ExeName)
+SDefDataBaseName;
if not FileExists(sDataBaseName) then
result:=OpenDBFile;
while result do
try
MainDMForm:=TMainDMForm.Create(Application);
with MainDMForm do
begin
if CNMain.Connected then CNMain.Close;
CNMain.ConnectionString:=format(
SConnectionString,[sDataBaseName,GetPassWord]);
CNMain.Open;
end; //with
except
msgbox(SEOpenDBFile,SAppName,mb_iconstop);
result:=OpenDBFile;
end; //try
if not result then exit;
Application.ProcessMessages;
// Sleep(3000); //延时修改这里
Screen.Cursor:=crDefault;
SplashForm.Close;
SplashForm.Free;
end;
end.