Software Development Kit
to the Delphi-Win32 and Free Pascal compilers
Home > Wiki > Persistence

Persistence

english (en) | português (br)

Contents

PressObjects OPF

To use the PressObjects persistence framework, include at least one of it's connection brokers in the uses clause of a project file. Currently PressObjects has brokers for IBX, UIB, DOA, ZeosDBO, FBLib and SQLdb.

The OPF article provides more information about the PressOPF framework.

The following example uses a project unit 'Broker.pas' to manage database-specific tasks.

unit Broker;

uses
  PressIBXBroker;

This declaration registers the IBX broker service, but doesn't configure the database name, username, password and any other required information. To do so, the connection brokers give you read access to the database connection component that can be reached using one of the following approaches:

Using a configuration file

See Configuration file for details.

Creating the connection service

initialization
  with TPressIBXBroker.Create.Connector.Database do
  begin
    DatabaseName               := 'servername:c:\path\to\database';
    Params.Values['user_name'] := 'sysdba';
    Params.Values['password']  := 'masterkey';
    // any other TIBDatabase property
  end;

Don't worry about destroying the service, the PressObjects SDK will do it for you.

Overriding the default IBX connection service

interface

type
  TMyConnectionBroker = class(TPressIBXBroker)
  protected
    procedure InitService; override;
    // any other TPressIBXBroker or TPressOPFBroker virtual method
  end;

implementation

procedure TMyConnectionBroker.InitService;
begin
  inherited;
  with Connector.Database do
  begin
    DatabaseName               := 'servername:c:\path\to\database';
    Params.Values['user_name'] := 'sysdba';
    Params.Values['password']  := 'masterkey';
    // any other TIBDatabase property
  end;
end;

initialization
  TMyConnectionBroker.RegisterService(True);

Don't worry about creating or destroying the service, the PressObjects SDK will do it for you when necessary. The initialization section declaration is mandatory, it registers your customized service as the default OPF broker service.

InstantObjects

To use InstantObjects (IO), at least two units must be added to the uses clause of any project file. One must be 'PressInstantObjectsBroker', the other one must be one of the IO broker units (eg 'InstantIBX') for database access.

IO Notes:

  • Navigational brokers (like InstantBDE) aren't supported.
  • If using IO version 2.1 (or IO from SourceForge repository SVN revision 702) or higher then ensure that the compiler conditional symbol 'IO2.1' is defined in the PressInstantObjectsBroker.pas unit.

To use InstantObjects persistence, create an IO model with the same class names used in the PressObjects' model.