var ParntBitbtn: ^TBitBtn; begin ParntBitbtn:=Pointer(Panel1.Controls[0]); ShowMessage(TBitBtn(ParntBitbtn).Caption); end;
还是不行啊 指向的地址错位置了,你多放几个 button 看看
function TForm1.GetParntButton(menucaption:string):TBitBtn; var i:Integer; begin ShowMessage(menucaption); for i:=0 to pnl1.ComponentCount-1 do begin if (pnl1.Components[i] is TBitBtn) then if Trim(TBitBtn(pnl1.Components[i]).Caption)=trim(menucaption) then begin ParntBitbtn:=Pointer(TBitBtn(pnl1.Controls[i])) ; ShowMessage(TBitBtn(ParntBitbtn).Caption); end; end;end;
var
ParntBitbtn: ^TBitBtn;
begin
ParntBitbtn:=Pointer(Panel1.Controls[0]);
ShowMessage(TBitBtn(ParntBitbtn).Caption);
end;
var i:Integer;
begin
ShowMessage(menucaption);
for i:=0 to pnl1.ComponentCount-1 do
begin if (pnl1.Components[i] is TBitBtn) then
if Trim(TBitBtn(pnl1.Components[i]).Caption)=trim(menucaption) then
begin
ParntBitbtn:=Pointer(TBitBtn(pnl1.Controls[i])) ;
ShowMessage(TBitBtn(ParntBitbtn).Caption); end; end;end;