//Splash.DFM
object SplashForm: TSplashForm
Left = 308
Top = 134
Cursor = crHourGlass
AutoSize = True
BorderIcons = []
BorderStyle = bsNone
ClientHeight = 308
ClientWidth = 400
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
FormStyle = fsStayOnTop
OldCreateOrder = False
Position = poDesktopCenter
PixelsPerInch = 96
TextHeight = 13
object imgBack: TImage
Left = 0
Top = 0
Width = 400
Height = 308
AutoSize = True
IncrementalDisplay = True
Proportional = True
end
object dlgOpen: TOpenDialog
Filter = 'Microsoft Access 文件 (*.mdb)|*.mdb|所有文件 (*.*)|*.*'
Options = [ofHideReadOnly, ofPathMustExist, ofFileMustExist, ofEnableSizing]
Left = 104
Top = 120
end
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}
const
SConnectionString = 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=%s;'
+'Jet OLEDB
atabase Password=%s;';
function ShowSplashForm:boolean;
//显示闪现窗口,同时连接数据库,如果失败则选择其它数据库
function OpenDBFile:boolean;
//选择数据库
begin
result:=true;
SplashForm.dlgopen.FileName:=sDataBaseName;
if SplashForm.dlgopen.Execute then
//sDataBaseName是一个全局变量,为数据库完整路径及名称
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;//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]);
//SConnectionString连接字符串,GetPassWord取得密码函数
CNMain.Open;
end; //with
except
msgbox(SEOpenDBFile,SAppName,mb_iconstop);
//msgbox在共享模块声明,SEOpenDBFile,SAppName是资源字符串
result:=OpenDBFile;
end; //try
if not result then exit;
Application.ProcessMessages;
// Sleep(3000);//延时
Screen.Cursor:=crDefault;
SplashForm.Close;
SplashForm.Free;
end;
end.
//------------------------------------------------------------------------------
//工程文件
//------------------------------------------------------------------------------
program StockManage;
uses
Forms,
Windows,
Messages,
MDIMain in 'MDIMain.pas' {MDIMainForm},
MainDM in 'MainDM.pas' {MainDMForm: TDataModule},
Splash in 'Splash.pas' {SplashForm},
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;
AddAboutMenu(application.Handle);
//{
LoadSetting;
//显示闪现窗体并检查密码
if not (
ShowSplashForm and CheckPassWord) then
begin
ReleaseMutex(hMutex);
application.Terminate;
exit;
end;
//}
Application.CreateForm(TMDIMainForm, MDIMainForm);
Application.Run;
//释放互斥对象
ReleaseMutex(hMutex);
end.