Glue42 Enterprise is now io.Connect Desktop! The new documentation site for all interop.io products is located at docs.interop.io.

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 Glue42 apps. The forms to be registered as Glue42 apps must implement the IGlueApp interface and the main form must be registered as a Glue42 app factory in order to create and register the forms.

App Factories

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

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

The form acting as a Glue42 app factory may be invisible.

After initializing Glue42, register the main form as an app factory. The following example demonstrates registering the main form as an app factory for two Glue42 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 Glue42 apps. The forms that are to be registered as Glue42 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 Glue42 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 a Glue42 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 a Glue42 Window.