Delphi 5. "Container component" based on TCustomControl contains a speed
button and an edit box.

Does not match the behaviour of Delphi controls when it comes to an
application getting/setting ActiveControl.

Stripped-down code as follows:

constructor TImsCustomEFinder.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  // An edit control
  FEdit        := TImsCustomMaskEdit.Create(Self);
  // A button
  FSpeedButton := TSpeedButton.Create(Self);
  etc
end;

procedure TImsCustomEFinder.SetFocus;
begin
  FEdit.SetFocus;
end;
function TImsCustomEFinder.Focused:Boolean;
begin
  Result := FEdit.Focused;
end;

procedure TImsCustomEFinder.SetName(const Value:TComponentName);
begin
  inherited SetName(Value);
  FEdit.Name:=Value;
end;

procedure TImsCustomEFinder.SetEnabled(Value: Boolean);
begin
  FEdit.Enabled        := Value;
  FSpeedButton.Enabled := Value;
  inherited SetEnabled(Value);
end;

===

So far so good. Other properties and methods surfaced or overridden
according to OOP/Delphi paradigm.

But. This control does not behave the same way as standard Delphi
components when it comes to being the ActiveControl.

ActiveControl is simply a pointer stored in the form class.

As far as I can tell, when you set the ActiveControl, Delphi will set the
pointer in the form object, then call SetWindowFocus:

  Windows.SetFocus(FocusControl.Handle);
  if GetFocus = FocusControl.Handle then
    FocusControl.Perform(CM_UIACTIVATE, 0, 0);

The first statement wil succeed, as it ends up in my component SetFocus
method, which transfers focus to the edit control (which is the intended
behaviour).

But the second statement bypasses Delphi logic altogether and compares the
handle returned by Windows.GetFocus (the edit control) with FocusControl
(which is the container component).

I have no (easy) way to override FocusControl.Handle: that value is buried
in my ancestors plot and I cannot fake it.

I ought to be able to read the code for Delphi's combobox and sort out
what to do. But frankly I get lost.

My aim here is keep this control simple: not clutter the code with windows
focus messages and handles.

===

I have spent way too much time chasing my tail on this, and suspect the
problem is very simple. Once you know the magic trick. But darned if I can
find it.

Appreciate  any suggestions. Please and thank you.


Reply via email to