我創建一個自定義Tpanel我在內心裏把各種自定義組件一TbitBtn ...我怎麼能釋放一個Tpanel這有一個調用來釋放Tpanel
procedure Panel_Comp(Location: TWinControl; NumOfComp: Integer;Left,Top,Height,width:Integer);
begin
MyPanel := TsPanel.Create(Conf);
MyPanel.Name := 'MyPanel' + IntToStr(NumOfComp);
MyPanel.Parent := Location;
MyPanel.Left := Left;
MyPanel.Top := Top;
MyPanel.Height := Height;
MyPanel.Width := width;
MyPanel.Caption := '';
end;
和我這樣稱呼它
Panel_Comp(Conf.ScrollBox1,1,8,10,70,322);
在相同的邏輯我把新的面板的其它自定義組件內側包括一個tBitbtn的具有onclick事件
..
procedure BitBtn_Comp(Location: TWinControl; NumOfComp: Integer; Left,Top,Height,Width,ImageNum: Integer);
begin
MyBitBtn := TBitBtn.Create(Conf);
......
MyBitBtn.tag := NumOfComp;
MyBitBtn.OnClick:= Conf.CloseCurrentPanel;
end;
主要Forn TConf.CloseCurrentPanel;
procedure TConf.CloseCurrentPanel(Sender: TObject);
var
panelComp: TComponent;
begin
panelComp := FindComponentEx('Conf.MyPanel'+ IntToStr(TBitBtn(Sender).tag);
TPanel(panelComp).Free;
Application.ProcessMessages;
end;
當我打電話,我得到的訪問衝突...... 我想的東西,我必須在自由的面板釋放面板裏面的所有組件,但我怎麼面板之前釋放BitBtn並繼續行動點擊事件?
這裏是FindComponetEx功能,而不是你需要它...
function FindComponentEx(const Name: string): TComponent;
var
FormName: string;
CompName: string;
P: Integer;
Found: Boolean;
Form: TForm;
I: Integer;
begin
// Split up in a valid form and a valid component name
P := Pos('.', Name);
if P = 0 then
begin
raise Exception.Create('No valid form name given');
end;
FormName := Copy(Name, 1, P - 1);
CompName := Copy(Name, P + 1, High(Integer));
Found := False;
// find the form
for I := 0 to Screen.FormCount - 1 do
begin
Form := Screen.Forms[I];
// case insensitive comparing
if AnsiSameText(Form.Name, FormName) then
begin
Found := True;
Break;
end;
end;
if Found then
begin
for I := 0 to Form.ComponentCount - 1 do
begin
Result := Form.Components[I];
if AnsiSameText(Result.Name, CompName) then Exit;
end;
end;
Result := nil;
end;
謝謝你這個很好的作品.... – azrael11 2012-08-10 01:07:24
還有一個關於這個問題...不是開始另一個話題。你能告訴我如何使用我的FindComponentEx找到特定的面板,所以我可以通過wParam或lParam刪除它...謝謝 – azrael11 2012-08-10 01:08:20
這很好...再次感謝您的幫助... – azrael11 2012-08-12 00:35:48