We have found something is seems to be a bug(?), and cause bug in our code.
Delphi XE3, Win32. Two forms, the main have button:
procedure TForm4.Button1Click(Sender: TObject); begin with TForm1.Create(Application) do begin ShowModal; Release; end; end;
The Form1 is doing this:
procedure TForm1.FormCreate(Sender: TObject); var i, j: integer; mn: TTreeNode; begin for i := 1 to 10 do begin mn := TreeView1.Items.Add(nil, 'M' + IntToStr(i)); for j := 1 to 10 do begin TreeView1.Items.AddChild(mn, 'C' + IntToStr(j)); end; end; Position := poDesigned; beep; Caption := IntToStr(TreeView1.Items.Count); end;
After this I get 0 elements in caption.
But when I have a button in that form with this code...
procedure TForm1.Button1Click(Sender: TObject); begin Caption := IntToStr(TreeView1.Items.Count); end;
Then I can see the good number (110 elements).
If I write TreeView1.Handleneeded after Position changing, the count is also good.
The problem is based on RecreateWnd, which calls DestroyHandles. But they will be repaired only in Show (in the Activate event I can see good result too).
TreeView is a special control, because the tree elements are children, and the count is calculated by on them, no matter it have real sub-object list.
The main problem that ReCreateWnd called often by another methods to, so it can cause problems in another sections too, and I cannot put HandleNeeded before all .Count calculation.
(We have special base form that correct the Position to poDesigned if it was poScreenCenter to it can be positionable later. This happens after FormCreate call, in an inner method. We found this problem only with these kind of forms, but later we could reproduce it in a simple code too)
So the question is - what is the global solution to this problem?
(Did you experience this in XE5 too?)
Thank you for all help, info, doc.