Component for Delphi palette
TfrxIBXComponents is the first component we should create; it will be placed into FastReport component palette when registering engine (in the Delphi environment). As soon as this component is placed into a project, Delphi automatically adds link to our engine unit into “Uses” list. One should assign one more task in this component, i.e. to define DefaultDatabase property in it, which refers to existing connection to DB. By default, all TfrxIBXTable and TfrxIBXQuery components will refer to this connection. It is necessary to inherit component from TfrxDBComponents class:
TfrxDBComponents = class(TComponent)
public
function GetDescription: String; virtual; abstract;
end;
Description should be returned by one function only, for example ”IBX Components”. TfrxIBXComponents component implementation is as follows:
type
TfrxIBXComponents = class(TfrxDBComponents)
private
FDefaultDatabase: TIBDatabase;
FOldComponents: TfrxIBXComponents;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
function GetDescription: String; override;
published
property DefaultDatabase: TIBDatabase read FDefaultDatabase write FDefaultDatabase;
end;
var
IBXComponents: TfrxIBXComponents;
constructor TfrxIBXComponents.Create(AOwner: TComponent);
begin
inherited;
FOldComponents := IBXComponents;
IBXComponents := Self;
end;
destructor TfrxIBXComponents.Destroy;
begin
if IBXComponents = Self then
IBXComponents := FOldComponents;
inherited;
end;
function TfrxIBXComponents.GetDescription: String;
begin
Result := 'IBX';
end;
We define IBXComponents global variable, which will refer to TfrxIBXComponents component copy. If you place component into project several times (though it is senseless), you will nevertheless be able to save link to previous component and restore it after deleting component.
A link to connection to DB, which already exists in project, can be placed into DefaultDatabase property. The way we will write TfrxIBXTable, TfrxIBXQuery components allows them to use this connection by default (actually, this is what we need IBXComponents global variable for).