// Grundklasse
uses
Classes
,SysUtils
,Windows
,tiObject
,Generator_HCV
,Generator_BOM
;
....
// Beispielaufruf in CreateNew des eigentlichen Tabellenobjektes
constructor TPName.CreateNew(
const ADatabaseName,
APersistenceLayerName:
string);
var lGen: TPGenerator;
begin
inherited Create;
// Get an ID from Generator
lGen := TPGenerator.Create;
lGen.GeneratorName := '
GEN_TEST_ID';
lGen.ObjectState := posCreate;
lGen.
Read;
// Stösst Read in Generator_HCV an und belegt OID aus dem Generator
OID.AsVariant := lGen.OID.AsVariant;
lGen.Free;
end;
// Quelltext Generator_BOM.pas
unit Generator_BOM;
interface
uses
Classes
,SysUtils
,Windows
,tiObject
;
const
cErrorGeneratorNameMissing = '
Kein GeneratorName bekannt!';
type
TPGenerator =
class(TtiObject)
private
FGeneratorName:
string;
protected
public
function IsValid(
const AErrors: TtiObjectErrors): boolean;
override;
procedure Read;
overload;
published
property GeneratorName:
string read FGeneratorName
write FGeneratorName;
end;
implementation
uses
tiOPFManager
, tiOIDInteger
;
{ TPGenerator }
function TPGenerator.IsValid(
const AErrors: TtiObjectErrors): boolean;
begin
inherited IsValid(AErrors);
if Trim(GeneratorName) = '
'
then
AErrors.AddError('
GeneratorName', cErrorGeneratorNameMissing);
result := AErrors.Count = 0;
end;
procedure TPGenerator.
Read;
begin
inherited Read;
end;
end.
// Quelltext Generator_HCV.pas
unit Generator_HCV;
interface
uses
tiVisitorDB
;
type
TVisGenerator_Read =
class(TVisOwnedQrySelect)
protected
function AcceptVisitor: boolean;
override;
procedure Init;
override;
procedure SetupParams;
override;
procedure MapRowToObject;
override;
end;
procedure RegisterVisitors;
implementation
uses
Generator_BOM
, tiOPFManager
, tiObject
, tiLog
, tiCriteria
, tiVisitorCriteria
;
procedure RegisterVisitors;
begin
GTIOPFManager.RegReadVisitor(TVisGenerator_Read);
end;
{ TVisClient_Read }
procedure TVisGenerator_Read.MapRowToObject;
var
lGenerator: TPGenerator;
begin
lGenerator := TPGenerator(Visited);
lGenerator.OID.AsVariant :=
Query.FieldAsIntegerByIndex[0];
lGenerator.ObjectState := posClean;
end;
function TVisGenerator_Read.AcceptVisitor: boolean;
begin
result := (Visited
is TPGenerator)
and
(Visited.ObjectState = posCreate);
Log([ClassName, Visited.ClassName, Visited.ObjectStateAsString, Result]);
end;
procedure TVisGenerator_Read.Init;
var
lData: TPGenerator;
begin
lData := TPGenerator(Visited);
Query.SQLText := '
SELECT GEN_ID(' + lData.GeneratorName + '
,1) FROM RDB$DATABASE';
end;
procedure TVisGenerator_Read.SetupParams;
begin
;
end;
end.