|Delphi Clinic||C++Builder Gate||Training & Consultancy||Delphi Notes Weblog||Dr.Bob's Webshop|
For this Tip-Of-The-Hat I take you to one of the components that can be found on the Win 3.1 tab. In fact, the problem I want to identify (and solve) today is only a problem introduced at the TCustomOutline component inside file outline.pas of Delphi 1.0x (it was fixed in later versions of Delphi and C++Builder).
Here are the steps to reproduce the problem:
The error is due by the fact that the KeyDown method of TCustomOutline does not check if an expanded nodes has actual child nodes; it just moves to the last child node (and if there are no children, then last will return something that is "out of bounds" indeed).
In file outline.pas, find procedure TCustomOutline.KeyDown(var Key: Word; Shift: TShiftState); and change the code for VK_END to the following (one line added):
VK_END: begin Node := TOutlineNode(FRootNode.List.Last); while (Node.Expanded) and (Node.List.Count > 0) do // Dr.Bob's fix Node := TOutlineNode(Node.List.Last); SelectedItem := Node.Index; Exit end;Delphi 2 and higher (and C++Builder) no longer have this problem, although my suggested test for (Node.List.Count > 0) was actually implemented by a test for Node.HasItems