constructor TMyMessage.Create(AMsg: String);
begin
inherited Create(TMyMessage.Name);
FMsg := AMsg;
end;
static function TMyMessage.Name: String;
begin
Result := 'MyMessage.Test';
end;
2. 定义消息接收类TMyMessageHandler,重载DoExecute方法,在这个方法中处理消息
type
TMyMessageHandler = class(TBizMessageHandler)
private
FMemo: TMemo;
public
procedure DoExecute(AMessage: TBizMessage; const AParam: THandleParam;
var Handled: Boolean); override;
end;
procedure TMyMessageHandler.DoExecute(AMessage: TBizMessage; const AParam: THandleParam;
var Handled: Boolean);
begin
if AMessage is TMyMessage then
begin
FMemo.Lines.Add((AMessage as TMyMessage).msg);
Handled := True;
end;
end;
3. 创建一个消息接收类的对象,在全局环境中注册这个对象
procedure TMainForm.AddMsgHandler;
begin
lmh := TMyMessageHandler.Create;
TMyMessageHandler(lmh).FMemo := Memo1;
Memo1.Clear;
BizSys.GlobalContext.AddMessageHandler(TMyMessage.Name, lmh);
end;
4. 创建消息的实例,往全局环境中发送这个消息实例
var
lMsg: TMyMessage;
begin
lMsg := TMyMessage.Create(Edit1.Text);
BizSys.GlobalContext.SendMessage(lMsg);
lMsg.Free;
end;
TRelevancyMsgHandle = class(TBizMessageHandler)
private
FForm: TMainForm;
public
procedure DoExecute(AMessage: TBizMessage; const AParam: THandleParam;
var Handled: Boolean); override;
end;
procedure TRelevancyMsgHandle.DoExecute(AMessage: TBizMessage; const AParam: THandleParam;
var Handled: Boolean);
var
lMsg: TRefreshRelevanciesMessage;
begin
if AMessage is TRefreshRelevanciesMessage then
begin
lMsg := AMessage as TRefreshRelevanciesMessage;
lMsg.RelevancyNavBar.AddAction('mytest', FForm.Action1);
Handled := True;
end;
end;
3. 在功能创建这个消息处理类的对象,注册到当前功能环境上
//在主窗体上注册这个消息处理对象
var
lmh: TRelevancyMsgHandle;
begin
lmh := TRelevancyMsgHandle.Create;
TRelevancyMsgHandle(lmh).FForm := Self;
Context.AddMessageHandler(TRefreshRelevanciesMessage.Name, lmh);
end;
4. 在系统空间\简洁风格\界面库\窗体库\标准风格主窗体中,在需要刷新业务关联栏的地方,创建消息实例,向当前功能发送业务关联刷新消息对象