我有2種形式。 Form1帶有一個面板和2個按鈕(pnl1,btnShowTree和btnAddItems)。還有Form2包含Treeview(tv1)。爲什麼Treeview.Clear在父窗體邊框樣式更改上失敗?
請參閱下面的短代碼,瞭解這個小演示:
procedure TForm1.btnShowTreeClick(Sender: TObject);
begin
with Form2 do
begin
tv1.Items.clear;
Tv1.Items.AddChild(nil, '1.');
Tv1.Items.AddChild(nil, '2.');
Tv1.Items.AddChild(nil, '3.');
Form2.Parent:=pnl1;
Form2.BorderStyle:=bsNone;
Form2.show;
end;
end;
procedure TForm1.btnAddItemsClick(Sender: TObject);
begin
with Form2 do
begin
BorderStyle:=bsSizeable; // here it works wrong
tv1.Items.clear;
Tv1.Items.AddChild(nil, 'A.');
Tv1.Items.AddChild(nil, 'B.');
Tv1.Items.AddChild(nil, 'C.');
// BorderStyle:=bsSizeable; here it works fine. WHY ?????
Form2.Show;
end;
end;
procedure TForm2.btnCloseForm2Click(Sender: TObject);
begin
Parent:=nil;
Hide;
// when I exchange instructions order like:
// Hide;
// Parent:=nil;
// I get the same problem with improperly nested BorderStyle:=bsSizeable; I have
// only blur idea why it is so...
end;
我所料,當我點擊btnAddItems我會看到3個項目(A. B. C.)。但它會顯示6個項目,因爲之前的項目不會被刪除!任何人都可以點亮它,因爲我在這裏呆了幾個小時才能使程序運行良好,但我仍然沒有最薄弱的想法,我做錯了什麼...
什麼版本的Delphi?我創建了一個程序,我的工作正常(表格只顯示A,B和C)。我正在使用D2007 – 2010-01-27 16:06:35
我使用德爾福7 – lyborko 2010-01-28 15:24:57