怎么也找不出错误原因,消息机制的问题(csdn/盒子都没有人回答),这是我在大富翁的处女提问希望高手回答…… ( 积分: 50 )

  • 主题发起人 主题发起人 cncharles
  • 开始时间 开始时间
C

cncharles

Unregistered / Unconfirmed
GUEST, unregistred user!
//以下是核心代码.<br>type<br> &nbsp;PRSAction_List=^TRSActionList;<br> &nbsp;TRSAction_List=array of TAction;<br><br>procedure TMainform.Button1Click(Sender: TObject);<br>var<br> &nbsp;RSActionList:TRSActionList;<br>begin<br> &nbsp;SetLength(RSActionList,4);<br> &nbsp;RSActionList[0]:=acOpen;<br> &nbsp;RSActionList[1]:=acEdit;<br> &nbsp;RSActionList[2]:=acSave;<br> &nbsp;RSActionList[3]:=acCancel;<br> &nbsp;//ShowMessage('Low='+IntToStr(Low(RSActionList))+ 'High='+IntToStr(High(rsActionList)));<br> &nbsp;PostMessage(Application.Handle,rsMsg,rs_ToolCaption,Integer(@RSActionList));<br>end;<br><br>procedure TMainform.apevt1Message(var Msg: tagMSG; var Handled: Boolean);<br><br>begin<br> &nbsp;if Msg.message=rsMsg then<br> &nbsp; &nbsp;case Msg.wParam of<br> &nbsp; &nbsp; &nbsp;rs_ToolCaption:begin<br> &nbsp; &nbsp; &nbsp; &nbsp;SetToolBar(PRSActionList(Msg.lParam)^);<br> &nbsp; &nbsp; &nbsp; &nbsp;Handled:=True;<br> &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp;end;<br>end;<br><br><br>procedure TMainform.SetToolBar(RSActionList:TRSActionList);<br>{功能:这个过程用来设置 Toobar<br>}<br>var<br> &nbsp;SI:SmallInt;<br> &nbsp;strTB:string;<br> &nbsp;Comp:TComponent;<br>begin<br> &nbsp;Comp:=nil;<br> &nbsp;ShowMessage('Low='+IntToStr(Low(RSActionList))+ ' High='+IntToStr(High(rsActionList)));<br> &nbsp;//显示Low=0,High=-1为什么??????????<br> &nbsp;for SI:=Low(RSActionList) to High(rsActionList) do begin<br> &nbsp; &nbsp;strTB:='tb'+trim(IntToStr(SI+1));<br> &nbsp; &nbsp;Comp:=FindComponent(strTB);<br> &nbsp; &nbsp;if Comp&lt;&gt;nil then begin<br> &nbsp; &nbsp; &nbsp;(Comp as TToolButton).Action:=rsActionList[SI];<br> &nbsp; &nbsp; &nbsp;(Comp as TToolButton).Visible:=True;<br> &nbsp; &nbsp;end;<br> &nbsp;end;<br><br>end;
 
//以下是核心代码.<br>type<br> &nbsp;PRSAction_List=^TRSActionList;<br> &nbsp;TRSAction_List=array of TAction;<br><br>procedure TMainform.Button1Click(Sender: TObject);<br>var<br> &nbsp;RSActionList:TRSActionList;<br>begin<br> &nbsp;SetLength(RSActionList,4);<br> &nbsp;RSActionList[0]:=acOpen;<br> &nbsp;RSActionList[1]:=acEdit;<br> &nbsp;RSActionList[2]:=acSave;<br> &nbsp;RSActionList[3]:=acCancel;<br> &nbsp;//ShowMessage('Low='+IntToStr(Low(RSActionList))+ 'High='+IntToStr(High(rsActionList)));<br> &nbsp;PostMessage(Application.Handle,rsMsg,rs_ToolCaption,Integer(@RSActionList));<br>end;<br><br>procedure TMainform.apevt1Message(var Msg: tagMSG; var Handled: Boolean);<br><br>begin<br> &nbsp;if Msg.message=rsMsg then<br> &nbsp; &nbsp;case Msg.wParam of<br> &nbsp; &nbsp; &nbsp;rs_ToolCaption:begin<br> &nbsp; &nbsp; &nbsp; &nbsp;SetToolBar(PRSActionList(Msg.lParam)^);<br> &nbsp; &nbsp; &nbsp; &nbsp;Handled:=True;<br> &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp;end;<br>end;<br><br><br>procedure TMainform.SetToolBar(RSActionList:TRSActionList);<br>{功能:这个过程用来设置 Toobar<br>}<br>var<br> &nbsp;SI:SmallInt;<br> &nbsp;strTB:string;<br> &nbsp;Comp:TComponent;<br>begin<br> &nbsp;Comp:=nil;<br> &nbsp;ShowMessage('Low='+IntToStr(Low(RSActionList))+ ' High='+IntToStr(High(rsActionList)));<br> &nbsp;//显示Low=0,High=-1为什么??????????<br> &nbsp;for SI:=Low(RSActionList) to High(rsActionList) do begin<br> &nbsp; &nbsp;strTB:='tb'+trim(IntToStr(SI+1));<br> &nbsp; &nbsp;Comp:=FindComponent(strTB);<br> &nbsp; &nbsp;if Comp&lt;&gt;nil then begin<br> &nbsp; &nbsp; &nbsp;(Comp as TToolButton).Action:=rsActionList[SI];<br> &nbsp; &nbsp; &nbsp;(Comp as TToolButton).Visible:=True;<br> &nbsp; &nbsp;end;<br> &nbsp;end;<br><br>end;
 
有没有搞错都也没有回答!!!!!!
 
很简单,<br>procedure TMainform.Button1Click(Sender: TObject);<br>var<br> &nbsp;RSActionList:TRSActionList;<br><br>你这里的rsActionList是局部变量,离开了button1click之后就是未定义的。
 
TRSAction_List改成静态数组,postmessage换成sendmessage
 
江南草兄说得对,我早已在csdn得到正确答案,看来csdn高手要乐于助人些,<br>答的人也比delphibbs要多.
 
多人接受答案了。
 
后退
顶部