delphi之完美Splash方案

2021-08-24 21:49:27 字數 2404 閱讀 4762

前言:網上有很多介紹delphi建立閃屏的**,大多只是在程式開啟前顯示乙個閃屏,但是卻沒有說如何在閃屏上顯示程式載入的進度,於是筆者有意思介紹一下這種閃屏方式。

1.建立乙個窗體(tfrmsplash),放入乙個timagebox,載入一幅,調整好timagebox與的大小,然後在其上放入乙個tlabel,name=lblstatus,用於顯示載入進度文字。然後將tfrmsplash設定為不自動建立。

2.加入如下**(**很簡單,就不用解釋太多)

unit untformsplash;

inte***ce

uses

windows, messages, sysutils, variants, classes, graphics, controls, forms,

dialogs, extctrls, stdctrls;

type

tfrmsplash = class(tform)

image1: timage;

lblstatus: tlabel;

private

fparam:pointer;

public

class function execute(aparam:pointer):boolean;

procedure setstatustext(value: string);

published

property statustext : string write setstatustext;

end;

var splashform: tfrmsplash;

implementation

class function tfrmsplash.execute(aparam:pointer): boolean;

begin

with tfrmsplash.create(nil) do

tryfparam := aparam;

result := showmodal = mrok;

finally

free;

end;

end;

procedure tfrmsplash.setstatustext(value: string);

begin

lblstatus.caption := value;

update; //這句非常重要,不加的話,介面會阻塞,文字也就不會更新顯示

sleep(1000); //這句根據自己實際情況來調整,主要是怕閃屏太快關閉,達不到效果

end;

end.

3. 在專案的.dpr檔案中加入如下**:

begin

splashform.show;

splashform.update;

splashform.statustext := '準備啟動...';

splashform.update;

splashform.hide;

splashform.free;

end.

4.這一步就是主窗體載入資料的時候,邊載入邊更新閃屏的進度文字了:

procedure tfrmmain.formcreate(sender: tobject);

begin

with splashform do

trystatustext := ('開始初始化記憶體...');

fcachehash := tstringhashmap.create(caseinsensitivetraits, 255);

fcurrentclients := tlist.create;

:= sizeof(ttagcustomlistitem);

:= 2;

vst.nodedatasize := sizeof(tmytreenodedate);

statustext :=('初始化記憶體完成');

statustext :=('開始載入客戶端列表...');

buildgrouptree;

statustext :=('載入客戶端列表完成');

statustext :=('開始載入分組資訊...');

addelvdefaultgroup;

statustext :=('開始初始化記憶體');

statustext :=('開始初始化資料...');

g_defnetimpl := tdefnetimpl.create();

g_defnetimpl.registerobserver(self);

statustext :=('全部資料載入完畢,程式即將啟動...');

finally

end;

end;

收功,試著執行一下吧,乙個漂亮的splash誕生了.

delphi之完美Splash方案

1.建立乙個窗體 tfrmsplash 放入乙個timagebox,載入一幅,調整好timagebox與的大小,然後在其上放入乙個tlabel,name lblstatus,用於顯示載入進度文字。然後將tfrmsplash設定為不自動建立。2.加入如下 很簡單,就不用解釋太多 unit untfor...

Ant內建任務之splash

splash是ant內建任務,用於建立乙個初始螢幕,在構建期間顯示初始螢幕並且包括乙個簡單的進度條。與sound任務結合使用可以使等待完成期間不再枯燥的等待。imageurl 提供顯示的的url,預設為classpath的antlogo.gif。showduration 在構建多少毫秒後展示初始螢幕...

Delphi之指標使用

以下內容分為八部分,分別是 一 型別指標的定義 二 無型別指標的定義 三 指標的解除引用 四 取位址 指標賦值 五 指標運算 六 動態記憶體分配 七 字元陣列的運算 八 函式指標 一 型別指標的定義。對於指向特定型別的指標,在c中是這樣定義的 int ptr char ptr 與之等價的object...