ysai程序如下,红色部分为指定单击事件,他程序里面写得很完整了
---------------------------------------------
procedure TDBMDIChildForm.MasterAfterOpen(DataSet: TDataSet);
//主表打开后生成排序菜单
var
i:integer;
mi:TMenuItem;
begin
inherited;
for i:=0 to adsMaster.FieldCount -1 do
begin
mi:=TMenuItem.Create(self);
with mi do
begin
Caption := adsMaster.Fields.FieldName;
Hint := adsMaster.Fields.FieldName;
Tag := i;
[red]OnClick := SortFields; //指定菜单事件[/red]
end;
pmSortField.Items.Add(mi);
end;
end;
procedure TDBMDIChildForm.[red]SortFields[/red](Sender: TObject);
//菜单事件,按字段排序
begin
inherited;
if TComponent(sender).Tag=-1 then
SortField(ADSMaster,sMasterSortFields,'')
else
SortField(ADSMaster,sMasterSortFields,TMenuItem(sender).Hint);
end;