此元件 繼承TEdit
目的 :
獲得焦點時,改變顏色
失去焦點時,顏色還原
新增屬性 Version 控制顏色 <<不知道為什麼老師教的時候要用這個單字..
unit MzEdit;
interface
uses
SysUtils, Classes, Controls, StdCtrls, Graphics;
type
col = (aqua,blue,red,yellow,green);
TMzEdit = class(TEdit)
private
F_color: col;
procedure Setcolor(const Value: col);
public
procedure doEnter; override;
procedure doexit; override;
published
property Version: col read F_color write setcolor;
end;
procedure Register;
implementation
function ccc(c:col):tcolor;
begin
case c of
aqua: ccc:=claqua;
blue: ccc:=clblue;
red: ccc:=clred;
yellow: ccc:=clyellow;
green: ccc:=clgreen;
end;
end;
procedure Register;
begin
RegisterComponents('Standard', [TMzEdit]);
end;
procedure TMzEdit.doEnter;
begin
inherited;
Self.Color := ccc(F_color); // 黃色
end;
procedure TMzEdit.doExit;
begin
inherited;
Self.Color := -16777211; // 黃色
end;
procedure TMzEdit.Setcolor(const Value: col);
begin
F_color:=value;
end;
end.
存成PAS檔
在另外開一個dpk檔 加入PAS檔
然後右方專案視窗 Package1.bpl 點右鍵 install 就安裝完成
然後每次要使用此元件時 需要引用PAS檔
也可以放在lib裡(就不用每次都要找那個檔案)
自訂create事件
public
constructor Create(AOwner: TComponent);
Destructor Destroy;
///////////////
constructor Tfrm_SelDept.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FAddBlank:=True;
end;
destructor Tfrm_SelDept.Destroy;
begin
// Release memory, if obtained
if wordsStart <> nil
then FreeMem(wordsStart);
// Always call the parent destructor after running your own code
inherited;
end;
begin
// Release memory, if obtained
if wordsStart <> nil
then FreeMem(wordsStart);
// Always call the parent destructor after running your own code
inherited;
end;
全站熱搜
留言列表