转载 Unit Name: AppLdr Author: tony Purpose: Application Loader History: 2004.07.08 create -----------------------------------------------------------------------------}unit AppLdr;interfaceuses Windows, Messages, SysUtils, Classes, Controls, Forms, SplashForm, TLMIniFilter, ActiveX, Common;type TAppLoader = class (TObject) private FSplashForm: TfrmSplash; FtlmIniFilter:TtlmIniFilter; procedure OnAppLoading(ASender:TObject;AEvent:String;ADelay:Integer=50); public constructor Create(); destructor Destroy();override; function DoLoad: Boolean; end;var GAppLoader:TAppLoader;implementationuses SkinMdl, ConfigMgr, CommMgr, ICDeviceMgr, HdgClient, C1;{ ********************************** TAppLoader ********************************** } constructor TAppLoader.Create(); begin inherited Create(); FtlmIniFilter:=TtlmIniFilter.Create(Application); FtlmIniFilter.LanguageFiles.Add('HDG2.chs'); FtlmIniFilter.LanguageExt:='.chs'; FtlmIniFilter.Active:=true; end;destructor TAppLoader.Destroy(); begin if Assigned(frmC1) then begin GCommManager.EndListen(); FreeAndNil(frmC1); end; if Assigned(GHdgClient) then begin FreeAndNil(GHdgClient); end; if Assigned(GCommManager) then begin FreeAndNil(GCommManager); end; if Assigned(GICDevice) then begin FreeAndNil(GICDevice); end; if Assigned(GSkinModule) then begin FreeAndNil(GSkinModule); end; if Assigned(GConfigManager) then begin FreeAndNil(GConfigManager); end; if Assigned(FtlmIniFilter) then begin FreeAndNil(FtlmIniFilter); end; inherited Destroy(); end;function TAppLoader.DoLoad: Boolean; begin Result:=false; Application.Title:='HDG2'; FSplashForm:=TfrmSplash.Create(nil); try try FSplashForm.Show; OnAppLoading(nil,'Starting...'); Sleep(200); GConfigManager:=TConfigManager.Create(); GSkinModule:=TSkinModule.Create(nil); GICDevice:=TICDeviceDecorator.Create(); GICDevice.OnAppLoading:=OnAppLoading; GICDevice.Initialize(); GICDevice.OnAppLoading:=nil;
GCommManager.BeginListen(frmC1); frmC1.SysCaption:=GConfigManager.SysCaption; {$IFNDEF HDGCLIENT} frmC1.SysLedCaption:=GConfigManager.SysLedCaption; {$ENDIF} Result:=true; except on E:Exception do begin MessageBox(Application.Handle,PChar(E.ClassName+':'+#13+#10+E.Message), PChar(Application.Title),MB_ICONERROR); end; end; finally FreeAndNil(FSplashForm); end; end;procedure TAppLoader.OnAppLoading(ASender:TObject;AEvent:String; ADelay:Integer); begin if Assigned(FSplashForm) then begin if Assigned(ASender) then begin FSplashForm.lbl1.Caption:=ASender.ClassName+': '+AEvent; end else begin FSplashForm.lbl1.Caption:=AEvent; end; FSplashForm.Update; if ADelay>0 then Sleep(ADelay); end; end;end.工程的dpr中这样用: begin Application.Initialize; GAppLoader:=TAppLoader.Create(); try if GAppLoader.DoLoad() then begin Application.Run; end; finally GAppLoader.Free; end; end.
------------------------------------
hoho
Unit Name: AppLdr
Author: tony
Purpose: Application Loader
History: 2004.07.08 create
-----------------------------------------------------------------------------}unit AppLdr;interfaceuses
Windows, Messages, SysUtils, Classes, Controls, Forms, SplashForm,
TLMIniFilter, ActiveX, Common;type
TAppLoader = class (TObject)
private
FSplashForm: TfrmSplash;
FtlmIniFilter:TtlmIniFilter;
procedure OnAppLoading(ASender:TObject;AEvent:String;ADelay:Integer=50);
public
constructor Create();
destructor Destroy();override;
function DoLoad: Boolean;
end;var
GAppLoader:TAppLoader;implementationuses
SkinMdl, ConfigMgr, CommMgr, ICDeviceMgr, HdgClient, C1;{
********************************** TAppLoader **********************************
}
constructor TAppLoader.Create();
begin
inherited Create();
FtlmIniFilter:=TtlmIniFilter.Create(Application);
FtlmIniFilter.LanguageFiles.Add('HDG2.chs');
FtlmIniFilter.LanguageExt:='.chs';
FtlmIniFilter.Active:=true;
end;destructor TAppLoader.Destroy();
begin
if Assigned(frmC1) then begin
GCommManager.EndListen();
FreeAndNil(frmC1);
end;
if Assigned(GHdgClient) then begin
FreeAndNil(GHdgClient);
end;
if Assigned(GCommManager) then begin
FreeAndNil(GCommManager);
end;
if Assigned(GICDevice) then begin
FreeAndNil(GICDevice);
end;
if Assigned(GSkinModule) then begin
FreeAndNil(GSkinModule);
end;
if Assigned(GConfigManager) then begin
FreeAndNil(GConfigManager);
end;
if Assigned(FtlmIniFilter) then begin
FreeAndNil(FtlmIniFilter);
end;
inherited Destroy();
end;function TAppLoader.DoLoad: Boolean;
begin
Result:=false;
Application.Title:='HDG2';
FSplashForm:=TfrmSplash.Create(nil);
try
try
FSplashForm.Show;
OnAppLoading(nil,'Starting...');
Sleep(200); GConfigManager:=TConfigManager.Create();
GSkinModule:=TSkinModule.Create(nil); GICDevice:=TICDeviceDecorator.Create();
GICDevice.OnAppLoading:=OnAppLoading;
GICDevice.Initialize();
GICDevice.OnAppLoading:=nil;
GCommManager:=TCommManagerDecorator.Create(nil);
GCommManager.ConfigManager:=GConfigManager;
GCommManager.ICDevice:=GICDevice;
GCommManager.OnAppLoading:=OnAppLoading;
GCommManager.Initialize(true,false,false);
GCommManager.OnAppLoading:=nil; GHdgClient:=THdgClient.Create();
GHdgClient.OnAppLoading:=OnAppLoading;
GHdgClient.Initialize();
GHdgClient.OnAppLoading:=nil;
OnAppLoading(nil,'Ending...'); Screen.Cursors[crNo]:=LoadCursor(hInstance,'None');
Application.CreateForm(TfrmC1, frmC1);
GCommManager.BeginListen(frmC1);
frmC1.SysCaption:=GConfigManager.SysCaption;
{$IFNDEF HDGCLIENT}
frmC1.SysLedCaption:=GConfigManager.SysLedCaption;
{$ENDIF} Result:=true;
except
on E:Exception do begin
MessageBox(Application.Handle,PChar(E.ClassName+':'+#13+#10+E.Message),
PChar(Application.Title),MB_ICONERROR);
end;
end;
finally
FreeAndNil(FSplashForm);
end;
end;procedure TAppLoader.OnAppLoading(ASender:TObject;AEvent:String;
ADelay:Integer);
begin
if Assigned(FSplashForm) then begin
if Assigned(ASender) then begin
FSplashForm.lbl1.Caption:=ASender.ClassName+': '+AEvent;
end
else begin
FSplashForm.lbl1.Caption:=AEvent;
end;
FSplashForm.Update;
if ADelay>0 then
Sleep(ADelay);
end;
end;end.工程的dpr中这样用:
begin
Application.Initialize;
GAppLoader:=TAppLoader.Create();
try
if GAppLoader.DoLoad() then begin
Application.Run;
end;
finally
GAppLoader.Free;
end;
end.
http://www.tonixsoft.com/ultraalbum
^_^