先將效果圖展示給大家
下面是實現代碼
Unit
type
//聲明自定義事件的類型(類似於C#中的委托)
TMyEventHandle = procedure (Sender: TObject; Content: string) of object;
TForm
ComboBox
Label
procedure ComboBox
private
FOnSelectionChanged: TMyEventHandle;
public
//聲明自定義事件
property OnSelectionChanged: TMyEventHandle
read FOnSelectionChanged write FOnSelectionChanged;
end;
procedure TForm
begin
//當選擇改變時
if Assigned(FOnSelectionChanged) then
FOnSelectionChanged(Self
end;
Unit
type
TForm
btnOpenForm
Edit
Label
procedure btnOpenForm
private
m_frm
procedure frm
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
end;
constructor TForm
begin
inherited Create(AOwner);
m_frm
//指定當m_frm
m_frm
end;
destructor TForm
begin
m_frm
inherited Destroy;
end;
procedure TForm
begin
Edit
end;
procedure TForm
begin
m_frm
end;
From:http://tw.wingwit.com/Article/program/Delphi/201311/24690.html