Главная страница | назад





Article #19536: Workaround for TComboBox::Focused bug in BCB1 and BCB3

 Question and Answer Database
FAQ4536C.txt — Workaround for TComboBox::Focused bug in BCB1 and BCB3
Category :VCL
Platform :All-32Bit
Product :C++Builder1.0, C++Builder3.x,
Question:
I've found a bug in C++Builder 1 and 3, in the component
TCustomComboBox and descendants. The Focused() method
doesn't work, and it can't be fixed, because Focused()
is not a virtual method.
How can I work around this?
Answer:
This bug is adressed in BCB4 but here is an easy way to
workaround it.
First the issue:
The Focused method is declared as dynamic,
and it's overridden in TCustomComboBox:
function TCustomComboBox.Focused: Boolean;
var
FocusedWnd: HWND;
begin
Result := False;
if HandleAllocated then
begin
FocusedWnd := GetFocus;
Result := (FocusedWnd = FEditHandle) or (FocusedWnd = FListHandle);
end;
end;
The problem in C++Builder 1 and 3 is that the
TWinControl::Focused() doesn't work for TCustomComboBox:
function TWinControl.Focused: Boolean;
begin
Result := (FHandle <> 0) and (GetFocus = FHandle);
end;
If you would like to use the TComboBox::Focused method,
I suggest that you subclass the component and add a
new member function like this:
bool __fastcall TMyComboBox::IsFocused()
{
if(HandleAllocated())
{
HWND FocusedWnd = GetFocus();
return FocusedWnd == EditHandle || FocusedWnd == ListHandle;
}
else return false;
}
5/25/99 11:46:13 AM

Last Modified: 01-SEP-99