好了
我的這個類叫做TAppLoader
將工程dpr文件中的啟動代碼寫成這樣
var
GAppLoader:TAppLoader;
begin
Application
GAppLoader:=TAppLoader
try
if GAppLoader
Application
end;
finally
GAppLoader
end;
end
可以看到
接下來
TAppLoader = class (TObject)
private
FSplashForm: TfrmSplash;
FManagerList:TList;
protected
procedure InitializeManager(var AManager;AManagerClass:TCustomManagerClass);
procedure OnAppLoading(ASender:TObject;AEvent:String;ADelay:Integer=
public
constructor Create();
destructor Destroy(); override;
function DoLoad: Boolean;
end;
除了剛才說到的DoLoad()函數外
在說明InitializeManager()函數前
TCustomManagerClass = class of TCustomManager;
TCustomManager = class(TObject)
private
FOnAppLoading:TAppLoadingEvent;
protected
procedure Initialize();virtual;abstract;
procedure Finalize();virtual;abstract;
procedure DoAppLoading(AEvent:String);
property OnAppLoading:TAppLoadingEvent read FOnAppLoading write FOnAppLoading;
public
constructor Create();virtual;
end;
在我的程序中
這個基類定義了Initialize()和Finalize()兩個虛方法
接著
TAppLoader
procedure TAppLoader
ADelay:Integer);
begin
if Assigned(FSplashForm) then begin
if Assigned(ASender) then begin
FSplashForm
end
else begin
FSplashForm
end;
FSplashForm
if ADelay>
Sleep(ADelay);
end;
end;
其中FSplashForm就是啟動畫面了
實際的Manager類中只要調用DoAppLoading()方法
procedure TFileImageManager
var
Directory:String;
FindHandle:THandle;
FindFileData:TWin
begin
Directory:=ExtractFilePath(ParamStr(
FindHandle:=FindFirstFile(PChar(Directory+
if FindHandle = INVALID_HANDLE_VALUE then
exit;
repeat
if (FindFileData
DoAppLoading(
AddDecoder(Directory+FindFileData
end;
until not FindNextFile(FindHandle
Windows
end;
TAppLoader中還有這麼一個函數
procedure TAppLoader
var
Instance: TCustomManager;
begin
Instance := TCustomManager(AManagerClass
TCustomManager(AManager) := Instance;
try
Instance
FManagerList
Instance
Instance
Instance
except
TCustomManager(AManager):= nil;
raise;
end;
end;
它用來啟動一個Manager
在Manager的Initialize()結束後
最後
function TAppLoader
begin
Result:=false;
Application
FSplashForm:=TfrmSplash
try
try
FSplashForm
OnAppLoading(nil
Sleep(
InitializeManager(GOptionManager
InitializeManager(GRdItemClassManager
InitializeManager(GImageManager
InitializeManager(GThemeManager
InitializeManager(GMaskManager
OnAppLoading(nil
Application
if ParamCount>=
FSplashForm
frmMain
frmMain
end;
Result:=true;
except
on E:Exception do begin
MessageBox(Application
PChar(Application
end;
end;
finally
FreeAndNil(FSplashForm);
end;
end;
這個函數是我的一個軟件中的代碼
最後
From:http://tw.wingwit.com/Article/program/Delphi/201311/25015.html