Subject Re: [IBO] Global GainFocusEvent
Author Geoff Worboys
>> Then attach code to the OnReceiveFocus handler of the datalink, and
>> this handler will receive messages whenenver the focused datasource
>> changes.

> Exists something like OnLoseFocus ?

The OnReceiveFocus handler of TIB_DataLink is provided for controls
such as TIB_NavigationBar, so that they can dynamically alter the
datasource attached to the link.

The way I see it your implementation could go something like...

procedure TForm1.Form1Create( ... )
begin
FDataLink := TIB_DataLink.Create( Self );
FDataLink.OnReceiveFocus := ReceiveFocusEvent;
FDataLink.ReceiveFocus := true;
end;

procedure TForm1.Form1Destroy( ... )
begin
FDataLink.OnReceiveFocus := nil;
FreeAndNil( FDataLink );
end;

procedure TForm1.ReceiveFocusEvent( Sender: TIB_DataLink;
ADataSource: TIB_DataSource );
begin
// if datasource is changing
if ADataSource <> FDataLink.DataSource then
begin
if FDataLink.DataSource <> nil then
begin
// FDataLink.DataSource is losing focus
end;
// switch the linked datasource
FDataLink.DataSource := ADataSource;
if FDataLink.DataSource <> nil then
begin
// FDataLink.DataSource is gaining focus
end;
end;
end;

hth

--
Geoff Worboys
Telesis Computing