以下举例为:
窗体上创建的数据集,当Page页切换时候,只识别当前Page页上的数据集,而且处理识别数据集之外,可以增加一些自定义的动作
============================
unit MainForm;
interface
uses
Business.System, Business.Forms, Business.Data, Business.Model;
type
TMainForm = class(TForm)
ControlBar1: TControlBar;
DataNavigator1: TDataNavigator;
PageControl1: TPageControl;
TabSheet1: TTabSheet;
TabSheet2: TTabSheet;
DataGrid1: TDataGrid;
InfoBroker1: TInfoBroker;
DataSetBroker1: TDataSetBroker;
DataSource1: TDataSource;
DataGrid2: TDataGrid;
DataSetBZSJJ1: TSQLDataSet;
ActionList1: TActionList;
Action1: TAction;
FuncBroker1: TFuncBroker;
procedure BizFormShow(Sender: TObject);
procedure BizFormCreate(Sender: TObject);
procedure Action1Execute(Sender: TObject);
procedure PageControl1Change(Sender: TObject);
procedure BizFormDestroy(Sender: TObject);
private
{private declarations}
MsgHandler: TBizMessageHandler;
public
{public declarations}
end;
implementation
uses RelevancyLib;
var
NavBar: TRelevancyNavBar;
type
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.Clear;
//根据ActivePageIndex绑定不同的数据集
if FForm.PageControl1.ActivePageIndex=0 then
lMsg.RelevancyNavBar.BindDataSet(FForm.DataSetBroker1.DataSet as TBizDataSet)
else
lMsg.RelevancyNavBar.BindDataSet(FForm.DataSetBZSJJ1);
//根据上面指定的数据集,根据业务关联定义加载关联项
lMsg.RelevancyNavBar.ReloadRelevancies(FForm.Context, FForm.FuncBroker1.Func.BizClassURL.BizURL.URL);
//增加自定义的关联项
lMsg.RelevancyNavBar.AddAction('mytest', FForm.Action1);
//记录关联条对象,待会儿发消息时候要用到
if NavBar=nil then NavBar := lMsg.RelevancyNavBar;
Handled := True;
end;
end;
procedure TMainForm.BizFormCreate(Sender: TObject);
var
lmh: TRelevancyMsgHandle;
begin
lmh := TRelevancyMsgHandle.Create;
MsgHandler := lmh;
lmh.FForm := Self;
//在环境中注册关联条刷新消息处理对象,当关联条需要刷新时候就调用这个对象了
Context.AddMessageHandler(TRefreshRelevanciesMessage.GetName, lmh);
end;
procedure TMainForm.BizFormDestroy(Sender: TObject);
begin
//注销消息处理对象并且释放它
Context.RemoveMessageHandler(TRefreshRelevanciesMessage.GetName, MsgHandler);
MsgHandler.Free;
end;
procedure TMainForm.PageControl1Change(Sender: TObject);
var
lmsg: TRefreshRelevanciesMessage;
begin
//当Page页切换以后,发送一个刷新关联条的消息
//在消息处理函数中就可以根据当前Page页显示对应数据集的关联项了
lmsg := TRefreshRelevanciesMessage.Create(NavBar);
Context.SendMessage(lmsg);
end;
procedure TMainForm.BizFormShow(Sender: TObject);
begin
DataSetBroker1.DataSet.Open; //显示在Page页的第0页上
DataSetBZSJJ1.Open; //显示在Page页的第1页上
end;
procedure TMainForm.Action1Execute(Sender: TObject);
begin
Dialogs.ShowMessage('action1');
end;
end. |