//以下是核心代码.
type
PRSActionList=^TRSActionList;
TRSActionList=array of TAction;procedure TMainform.Button1Click(Sender: TObject);
var
RSActionList:TRSActionList;
begin
SetLength(RSActionList,4);
RSActionList[0]:=acOpen;
RSActionList[1]:=acEdit;
RSActionList[2]:=acSave;
RSActionList[3]:=acCancel;
//ShowMessage('Low='+IntToStr(Low(RSActionList))+ 'High='+IntToStr(High(rsActionList)));
PostMessage(Application.Handle,rsMsg,rs_ToolCaption,Integer(@RSActionList));
end;procedure TMainform.apevt1Message(var Msg: tagMSG; var Handled: Boolean);begin
if Msg.message=rsMsg then
case Msg.wParam of
rs_ToolCaption:begin
SetToolBar(PRSActionList(Msg.lParam)^);
Handled:=True;
end;
end;
end;
procedure TMainform.SetToolBar(RSActionList:TRSActionList);
{功能:这个过程用来设置 Toobar
}
var
SI:SmallInt;
strTB:string;
Comp:TComponent;
begin
Comp:=nil;
ShowMessage('Low='+IntToStr(Low(RSActionList))+ ' High='+IntToStr(High(rsActionList)));
//显示Low=0,High=-1为什么???????????
for SI:=Low(RSActionList) to High(rsActionList) do begin
strTB:='tb'+trim(IntToStr(SI+1));
Comp:=FindComponent(strTB);
if Comp<>nil then begin
(Comp as TToolButton).Action:=rsActionList[SI];
(Comp as TToolButton).Visible:=True;
end;
end;end;
type
PRSActionList=^TRSActionList;
TRSActionList=array of TAction;procedure TMainform.Button1Click(Sender: TObject);
var
RSActionList:TRSActionList;
begin
SetLength(RSActionList,4);
RSActionList[0]:=acOpen;
RSActionList[1]:=acEdit;
RSActionList[2]:=acSave;
RSActionList[3]:=acCancel;
//ShowMessage('Low='+IntToStr(Low(RSActionList))+ 'High='+IntToStr(High(rsActionList)));
PostMessage(Application.Handle,rsMsg,rs_ToolCaption,Integer(@RSActionList));
end;procedure TMainform.apevt1Message(var Msg: tagMSG; var Handled: Boolean);begin
if Msg.message=rsMsg then
case Msg.wParam of
rs_ToolCaption:begin
SetToolBar(PRSActionList(Msg.lParam)^);
Handled:=True;
end;
end;
end;
procedure TMainform.SetToolBar(RSActionList:TRSActionList);
{功能:这个过程用来设置 Toobar
}
var
SI:SmallInt;
strTB:string;
Comp:TComponent;
begin
Comp:=nil;
ShowMessage('Low='+IntToStr(Low(RSActionList))+ ' High='+IntToStr(High(rsActionList)));
//显示Low=0,High=-1为什么???????????
for SI:=Low(RSActionList) to High(rsActionList) do begin
strTB:='tb'+trim(IntToStr(SI+1));
Comp:=FindComponent(strTB);
if Comp<>nil then begin
(Comp as TToolButton).Action:=rsActionList[SI];
(Comp as TToolButton).Visible:=True;
end;
end;end;
解决方案 »
- 怎么把Delphi、rave、SQL Server 2005做成一个应用软件
- quickreport的主从报表如何sum
- 一个小循环语句的写法 [ 求助]
- error $2108是什么意思?如何解决?
- 如何处理大数组?例如超过100万长度的数组?
- 如何在stringGrid中,实现如文本编辑器一样的区域选择,在线等
- 在Access中进行数据导入/导出的问题
- dbgrid中双击某一行高亮显示的问题
- 版主,拜托了,俺帮人家回答了问题,人家要另开贴给300分,那帖子是不是被您删除了?又不是倒分!300分啊~~~~,兄弟得分也不容易啊。兄弟
- 在vc中如何调用delphi创建的动态库!
- Ehlib3.4+Delphi6,导入Execl的函数怎么没反应啊,具体请看正文,谢谢!
- 可以调整大小的无标题的窗口怎么做的?
都没有得到答案,就连回复的人都没有,晕了.
2 PostMessage(Application.Handle,rsMsg,rs_ToolCaption,Integer(@RSActionList));
中的Application.Handle是否应该改为Handle,因为你要向主窗体发送消息而不是向应用程序窗体发送消息.3 你的错误发生在哪一行给多点信息吗.
//显示Low=0,High=-1为什么???????????
for SI:=Low(RSActionList) to High(rsActionList) do begin
这里来就不错了.
我的目的每一个Toolbar上的btn都动态的对一个Action,因此我
觉得我的思路是没有问题的.
RSActionList:TRSActionList;我想这里
当Button1Click(Sender: TObject);
RSActionList为一局部变量
当它离开作用域,就被释放
而PostMessage是发送完消息就返回而apevt1Message
取得的只是那个被释放的局部变量1.
把你的RSActionList声明为TMainForm的成员变量2.或者用SendMessage
但就不能用OnMessage;直接写消息处理句柄
procedure OnRsMessage(var Msg: TMessage); message rsMessage;很久不用delphi了,错了别怪我,呵
procedure OnRsMessage(var Msg: TMessage); message rsMsg;
var
RSActionList:TRSActionList;
begin
SetLength(RSActionList,4);
RSActionList[0]:=acOpen;
RSActionList[1]:=acEdit;
RSActionList[2]:=acSave;
RSActionList[3]:=acCancel;
//ShowMessage('Low='+IntToStr(Low(RSActionList))+ 'High='+IntToStr(High(rsActionList)));
PostMessage(Application.Handle,rsMsg,rs_ToolCaption,Integer(@RSActionList));
ShowMessage('Low='+IntToStr(Low(RSActionList))+ 'High='+IntToStr(High(rsActionList)));
//加上這個看看結果
end;
PRSActionList=^TRSActionList;
TRSActionList=array of TAction;是全局的,要不都编译不过.
PostMessage(Application.Handle,rsMsg,rs_ToolCaption,Integer(@RSActionList));
加上这一句 ShowMessage('Low='+IntToStr(Low(RSActionList))+ 'High='+IntToStr(High(rsActionList)));
就OK了,再照你的
var
RSActionList:TRSActionList;我想这里
当Button1Click(Sender: TObject);
RSActionList为一局部变量
当它离开作用域,就被释放
而PostMessage是发送完消息就返回而apevt1Message
取得的只是那个被释放的局部变量1.
把你的RSActionList声明为TMainForm的成员变量就完全OK了,看你对消息还是有很消息的理解的,非常大哥马上埋单
只是还一问题Toolbar上的btn可以显示图标不能显示Caption而我已把
Toolbar.ShowCaption:=true;设计期间是可以看得的Caption的.
显示Caption,晕……
這就已經直接復制過去了,如果再(Comp as TToolButton).Caption:=RSActionList[SI].caption屬於多余操作.
非常 Randomize() 顶力支持.