App Management

Overview

See the Delphi 10 and Delphi 7 examples on GitHub.

Individual forms in a multi-form app can be registered as separate io.Connect apps. The forms to be registered as io.Connect apps must implement the IGlueApp interface and the main form must be registered as an io.Connect app factory in order to create and register the forms.

App Factories

To make a form a factory for io.Connect apps, implement the IAppFactory interface. The CreateApp method of the interface will be invoked by io.Connect whenever a new form is to be created as an io.Connect app:

TMainForm = class(TForm, IAppFactory)
  ...
protected
  function CreateApp(const appDefName: WideString; state: GlueValue; const announcer: IAppAnnouncer): HResult; stdcall;
  ...

The form acting as an io.Connect app factory may be invisible.

After initializing io.Connect, register the main form as an app factory. The following example demonstrates registering the main form as an app factory for two io.Connect apps:

procedure TMainForm.InitializeGlue;
var
  ...
  appDef: GlueAppDefinition;
begin
  ...
  G42.Start(inst);
  ...
  // Register an app.
  ZeroMemory(@appDef, sizeof(appDef));
  appDef.Name := 'DelpiFormApp01';
  appDef.title := 'Delphi Form App 01';
  appDef.Category := 'COM Apps';
  G42.AppFactoryRegistry.RegisterAppFactory(appDef, Self);

  // Register another app.
  ZeroMemory(@appDef, sizeof(appDef));
  appDef.Name := 'DelpiFormApp02';
  appDef.title := 'Delphi Form App 02';
  appDef.Category := 'COM Apps';
  G42.AppFactoryRegistry.RegisterAppFactory(appDef, Self);
  ...

Registering App Instances

After the main form has been registered as an app factory, it can create and register child forms as separate io.Connect apps. The forms that are to be registered as io.Connect apps must first implement the IGlueApp interface and its methods:

TApp01Form = class(TForm, IGlueApp)
  ...
protected
  function SaveState(const receiver: IGlueValueReceiver): HResult; stdcall;
  function Initialize(state: GlueValue; const glueWindow: IGlueWindow): HResult; stdcall;
  function Shutdown: HResult; stdcall;
  ...

The following is a sample minimal implementation of the interface methods:

function TApp01Form.Initialize(state: GlueValue;
  const glueWindow: IGlueWindow): HResult;
begin
  Result := S_OK;
end;

function TApp01Form.SaveState(const receiver: IGlueValueReceiver): HResult;
begin
  Result := S_OK;
end;

function TApp01Form.Shutdown: HResult;
begin
  Result := S_OK;
  Close;
end;

Now the forms can be created and registered as io.Connect apps with the CreateApp method of the IAppFactory interface implemented by main form:

function TMainForm.CreateApp(const appDefName: WideString; state: GlueValue; const announcer: IAppAnnouncer): HResult; stdcall;
var
  form01Inst: TApp01Form;
  form02Inst: TApp02Form;
begin
  if appDefName = 'DelphiFormApp01' then
  begin
    form01Inst := TApp01Form.Create(self);
    // Registering a form as an io.Connect app instance.
    announcer.RegisterAppInstance(form01Inst.Handle, form01Inst);
    Result := S_OK;
  end
  else if appDefName = 'DelphiFormApp02' then
  begin
    form02Inst := TApp02Form.Create(self);
    // Registering another form.
    announcer.RegisterAppInstance(form02Inst.Handle, form02Inst);
    Result := S_OK;
  end
  else
    Result := E_FAIL;
end;

⚠️ Note that the RegisterAppInstance method also registers the child form as an io.Connect Window.