Windows

io.Connect Windows

See the Delphi 10 and Delphi 7 examples on GitHub.

In order for form windows of Delphi apps to become io.Connect Windows, they must be registered as io.Connect Windows after the io.Connect COM library has been initialized.

Registering Delphi Forms

To enable registration as an io.Connect Window, the form class must implement the IGlueWindowEventHandler interface:

TMainForm = class(TForm, IGlueWindowEventHandler)
...
private
  G42: IGlue42;
  // The io.Connect Window handle.
  glueWin: IGlueWindow;
protected
  function HandleWindowReady(const glueWindow: IGlueWindow): HResult; stdcall;
  function HandleChannelData(const glueWindow: IGlueWindow; const channelUpdate: IGlueContextUpdate): HResult; stdcall;
  function HandleChannelChanged(const glueWindow: IGlueWindow; const channel: IGlueContext; prevChannel: GlueContext): HResult; stdcall;
  function HandleWindowDestroyed(const glueWindow: IGlueWindow) : HResult; stdcall;
  function HandleWindowEvent(const GlueWindow: IGlueWindow; eventType: GlueWindowEventType; eventData: GlueValue): HResult; stdcall;
  ...

You can register the form as an io.Connect Window using the RegisterGlueWindow method immediately after initializing io.Connect:

procedure TMainForm.InitializeGlue;
  ...
    G42.Start(inst);
    // Register the io.Connect Window.
    G42.RegisterGlueWindow(Self.Handle, Self);
  ...

Unregister the io.Connect Window when the form is closed:

procedure TMainForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  if Assigned(glueWin) then
  begin
    glueWin.Unregister;
  end;
  ...
end;

Window Events

You must provide implementations for the methods of the IGlueWindowEventHandler interface. The following example demonstrates a minimal implementation of the event handlers:

//  Handles the event when the io.Connect Window registration has completed.
function TMainForm.HandleWindowReady(const glueWindow: IGlueWindow): HResult;
begin
  glueWin := glueWindow;
  Result := S_OK;
end;

// Handles the event when the user changes the Channel via the Channel Selector in the window title bar.
function TMainForm.HandleChannelChanged(const glueWindow: IGlueWindow; const channel: IGlueContext; prevChannel: GlueContext): HResult;
begin
  Result := S_OK;
end;

// Handles the event when the data in the currently selected Channel has changed.
function TMainForm.HandleChannelData(const glueWindow: IGlueWindow; const channelUpdate: IGlueContextUpdate): HResult;
begin
  Result := S_OK;
end;

// Handles the event when the io.Connect Window is destroyed.
function TMainForm.HandleWindowDestroyed(const glueWindow: IGlueWindow): HResult;
begin
  Result := S_OK;
end;

// Handles additional window events.
function TMainForm.HandleWindowEvent(const GlueWindow: IGlueWindow; eventType: GlueWindowEventType; eventData: GlueValue): HResult;
begin
  Result := S_OK;
end;

For more information about using io.Connect Channels, see the Channels section.

Window Operations

Once an io.Connect Window has been registered, you can use the HandleWindowReady event to perform operations on it.

Title

To get the current window title, use the GetTitle method:

var
  winTitle: WideString;
...
  winTitle := glueWin.GetTitle();

To change the window title, use the SetTitle method:

glueWin.SetTitle('New Window Title');

Visibility

To check whether the window is visible, use IsVisible. To hide or show a window, use SetVisible and pass a WordBool value as an argument:

if glueWin.IsVisible() then
  glueWin.SetVisible(False)
else
  glueWin.SetVisible(True);

Activation

You can activate the window by using the Activate method:

glueWin.Activate();