mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-18 15:29:11 +02:00
* Domains and sequences are now also written to .ini
git-svn-id: trunk@11607 -
This commit is contained in:
parent
8aa9dc6d0e
commit
3d3c85dd4a
@ -33,6 +33,7 @@ Type
|
|||||||
TDDTableDef = Class;
|
TDDTableDef = Class;
|
||||||
TDDTableDefs = Class;
|
TDDTableDefs = Class;
|
||||||
TDDFieldDefs = Class;
|
TDDFieldDefs = Class;
|
||||||
|
TDDDomainDef = Class;
|
||||||
TFPDataDictionary = Class;
|
TFPDataDictionary = Class;
|
||||||
|
|
||||||
{ TDDFieldDef }
|
{ TDDFieldDef }
|
||||||
@ -47,6 +48,7 @@ Type
|
|||||||
FDefaultExpression: string;
|
FDefaultExpression: string;
|
||||||
FDisplayLabel: string;
|
FDisplayLabel: string;
|
||||||
FDisplayWidth: Longint;
|
FDisplayWidth: Longint;
|
||||||
|
FDomain: TDDDomainDef;
|
||||||
FDomainName: string;
|
FDomainName: string;
|
||||||
FFieldName: string;
|
FFieldName: string;
|
||||||
FFieldType: TFieldType;
|
FFieldType: TFieldType;
|
||||||
@ -57,19 +59,25 @@ Type
|
|||||||
FRequired: Boolean;
|
FRequired: Boolean;
|
||||||
FSize: Integer;
|
FSize: Integer;
|
||||||
FVisible: Boolean;
|
FVisible: Boolean;
|
||||||
|
function GetDomainName: string;
|
||||||
Function IsSizeStored : Boolean;
|
Function IsSizeStored : Boolean;
|
||||||
Function IsPrecisionStored : Boolean;
|
Function IsPrecisionStored : Boolean;
|
||||||
|
procedure SetDomain(const AValue: TDDDomainDef);
|
||||||
|
procedure SetDomainName(const AValue: string);
|
||||||
protected
|
protected
|
||||||
function GetSectionName: String; override;
|
function GetSectionName: String; override;
|
||||||
procedure SetSectionName(const Value: String); override;
|
procedure SetSectionName(const Value: String); override;
|
||||||
Public
|
Public
|
||||||
Constructor Create(ACollection : TCollection); override;
|
Constructor Create(ACollection : TCollection); override;
|
||||||
Function FieldDefs : TDDFieldDefs;
|
Function FieldDefs : TDDFieldDefs;
|
||||||
|
Function DataDictionary : TFPDataDictionary;
|
||||||
|
Procedure ResolveDomain(ErrorOnFail : Boolean);
|
||||||
Procedure ImportFromField(F: TField; Existing : Boolean = True);
|
Procedure ImportFromField(F: TField; Existing : Boolean = True);
|
||||||
Procedure ApplyToField(F : TField);
|
Procedure ApplyToField(F : TField);
|
||||||
Procedure Assign(Source : TPersistent); override;
|
Procedure Assign(Source : TPersistent); override;
|
||||||
Procedure SaveToIni(Ini: TCustomInifile; ASection : String); override;
|
Procedure SaveToIni(Ini: TCustomInifile; ASection : String); override;
|
||||||
Procedure LoadFromIni(Ini: TCustomInifile; ASection : String); override;
|
Procedure LoadFromIni(Ini: TCustomInifile; ASection : String); override;
|
||||||
|
Property Domain : TDDDomainDef Read FDomain Write SetDomain;
|
||||||
Published
|
Published
|
||||||
property FieldType : TFieldType Read FFieldType Write FFieldType;
|
property FieldType : TFieldType Read FFieldType Write FFieldType;
|
||||||
property AlignMent : TAlignMent Read FAlignMent write FAlignment default taLeftJustify;
|
property AlignMent : TAlignMent Read FAlignMent write FAlignment default taLeftJustify;
|
||||||
@ -80,7 +88,7 @@ Type
|
|||||||
property DisplayLabel : string read FDisplayLabel write FDisplayLabel;
|
property DisplayLabel : string read FDisplayLabel write FDisplayLabel;
|
||||||
property DisplayWidth: Longint read FDisplayWidth write FDisplayWidth;
|
property DisplayWidth: Longint read FDisplayWidth write FDisplayWidth;
|
||||||
property FieldName: string read FFieldName write FFieldName;
|
property FieldName: string read FFieldName write FFieldName;
|
||||||
property DomainName: string read FDomainName write FDomainName;
|
property DomainName: string read GetDomainName write SetDomainName;
|
||||||
property Constraint: string read FConstraint write FConstraint;
|
property Constraint: string read FConstraint write FConstraint;
|
||||||
property ReadOnly: Boolean read FReadOnly write FReadOnly;
|
property ReadOnly: Boolean read FReadOnly write FReadOnly;
|
||||||
property Required: Boolean read FRequired write FRequired;
|
property Required: Boolean read FRequired write FRequired;
|
||||||
@ -287,6 +295,7 @@ Type
|
|||||||
|
|
||||||
TDDSequenceDefs = Class(TIniCollection)
|
TDDSequenceDefs = Class(TIniCollection)
|
||||||
private
|
private
|
||||||
|
FDataDictionary: TFPDataDictionary;
|
||||||
FOnProgress: TDDProgressEvent;
|
FOnProgress: TDDProgressEvent;
|
||||||
function GetSequence(Index : Integer): TDDSequenceDef;
|
function GetSequence(Index : Integer): TDDSequenceDef;
|
||||||
procedure SetSequence(Index : Integer; const AValue: TDDSequenceDef);
|
procedure SetSequence(Index : Integer; const AValue: TDDSequenceDef);
|
||||||
@ -296,6 +305,7 @@ Type
|
|||||||
Function IndexOfSequence(ASequenceName : String) : Integer;
|
Function IndexOfSequence(ASequenceName : String) : Integer;
|
||||||
Function FindSequence(ASequenceName : String) : TDDSequenceDef;
|
Function FindSequence(ASequenceName : String) : TDDSequenceDef;
|
||||||
Function SequenceByName(ASequenceName : String) : TDDSequenceDef;
|
Function SequenceByName(ASequenceName : String) : TDDSequenceDef;
|
||||||
|
Property DataDictionary : TFPDataDictionary Read FDataDictionary;
|
||||||
Property Sequences[Index : Integer] : TDDSequenceDef Read GetSequence Write SetSequence; default;
|
Property Sequences[Index : Integer] : TDDSequenceDef Read GetSequence Write SetSequence; default;
|
||||||
Property OnProgress : TDDProgressEvent Read FOnProgress Write FOnProgress;
|
Property OnProgress : TDDProgressEvent Read FOnProgress Write FOnProgress;
|
||||||
end;
|
end;
|
||||||
@ -331,11 +341,13 @@ Type
|
|||||||
|
|
||||||
TDDDomainDefs = Class(TIniCollection)
|
TDDDomainDefs = Class(TIniCollection)
|
||||||
private
|
private
|
||||||
|
FDataDictionary: TFPDataDictionary;
|
||||||
FOnProgress: TDDProgressEvent;
|
FOnProgress: TDDProgressEvent;
|
||||||
function GetDomain(Index : Integer): TDDDomainDef;
|
function GetDomain(Index : Integer): TDDDomainDef;
|
||||||
procedure SetDomain(Index : Integer; const AValue: TDDDomainDef);
|
procedure SetDomain(Index : Integer; const AValue: TDDDomainDef);
|
||||||
Public
|
Public
|
||||||
Constructor Create;
|
Constructor Create;
|
||||||
|
Property DataDictionary : TFPDataDictionary Read FDataDictionary;
|
||||||
Function AddDomain(ADomainName : String = '') : TDDDomainDef;
|
Function AddDomain(ADomainName : String = '') : TDDDomainDef;
|
||||||
Function IndexOfDomain(ADomainName : String) : Integer;
|
Function IndexOfDomain(ADomainName : String) : Integer;
|
||||||
Function FindDomain(ADomainName : String) : TDDDomainDef;
|
Function FindDomain(ADomainName : String) : TDDDomainDef;
|
||||||
@ -350,6 +362,7 @@ Type
|
|||||||
TFPDataDictionary = Class(TPersistent)
|
TFPDataDictionary = Class(TPersistent)
|
||||||
private
|
private
|
||||||
FDDName: String;
|
FDDName: String;
|
||||||
|
FDomains: TDDDomainDefs;
|
||||||
FFileName: String;
|
FFileName: String;
|
||||||
FOnApplyDataDictEvent: TOnApplyDataDictEvent;
|
FOnApplyDataDictEvent: TOnApplyDataDictEvent;
|
||||||
FOnProgress: TDDProgressEvent;
|
FOnProgress: TDDProgressEvent;
|
||||||
@ -373,6 +386,7 @@ Type
|
|||||||
function CanonicalizeFieldName(const InFN: String; Out TableDef : TDDTableDef; Out FN: String): Boolean;
|
function CanonicalizeFieldName(const InFN: String; Out TableDef : TDDTableDef; Out FN: String): Boolean;
|
||||||
Property Tables : TDDTableDefs Read FTables;
|
Property Tables : TDDTableDefs Read FTables;
|
||||||
Property Sequences : TDDSequenceDefs Read FSequences;
|
Property Sequences : TDDSequenceDefs Read FSequences;
|
||||||
|
Property Domains : TDDDomainDefs Read FDomains;
|
||||||
Property FileName : String Read FFileName;
|
Property FileName : String Read FFileName;
|
||||||
Property Name : String Read FDDName Write FDDName;
|
Property Name : String Read FDDName Write FDDName;
|
||||||
Property OnProgress : TDDProgressEvent Read FOnProgress Write SetOnProgress;
|
Property OnProgress : TDDProgressEvent Read FOnProgress Write SetOnProgress;
|
||||||
@ -717,6 +731,8 @@ Resourcestring
|
|||||||
SErrDuplicateSequence = 'Duplicate sequence name: "%s"';
|
SErrDuplicateSequence = 'Duplicate sequence name: "%s"';
|
||||||
SErrDuplicateDomain = 'Duplicate domain name: "%s"';
|
SErrDuplicateDomain = 'Duplicate domain name: "%s"';
|
||||||
SErrDomainNotFound = 'Domain "%s" not found.';
|
SErrDomainNotFound = 'Domain "%s" not found.';
|
||||||
|
SErrNoDataDict = '%s : No data dictionary available';
|
||||||
|
SErrResolveDomain = 'Cannot resolve domain';
|
||||||
|
|
||||||
Const
|
Const
|
||||||
IndexOptionNames : Array [TIndexOption] of String
|
IndexOptionNames : Array [TIndexOption] of String
|
||||||
@ -929,11 +945,34 @@ begin
|
|||||||
ftWideString,ftArray, ftOraBlob, ftOraClob, ftFMTBcd];
|
ftWideString,ftArray, ftOraBlob, ftOraClob, ftFMTBcd];
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TDDFieldDef.GetDomainName: string;
|
||||||
|
begin
|
||||||
|
If Assigned(FDomain) then
|
||||||
|
Result:=FDomain.DomainName
|
||||||
|
else // Not resolved yet
|
||||||
|
Result:=FDomainName;
|
||||||
|
end;
|
||||||
|
|
||||||
function TDDFieldDef.IsPrecisionStored: Boolean;
|
function TDDFieldDef.IsPrecisionStored: Boolean;
|
||||||
begin
|
begin
|
||||||
Result:=FieldType in [ftFloat,ftBCD,ftFMTBCD];
|
Result:=FieldType in [ftFloat,ftBCD,ftFMTBCD];
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TDDFieldDef.SetDomain(const AValue: TDDDomainDef);
|
||||||
|
begin
|
||||||
|
if FDomain=AValue then exit;
|
||||||
|
FDomain:=AValue;
|
||||||
|
If Assigned(FDomain) then
|
||||||
|
FDomainName:=FDomain.DomainName;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TDDFieldDef.SetDomainName(const AValue: string);
|
||||||
|
begin
|
||||||
|
FDomainName:=AValue;
|
||||||
|
If (AValue<>'') then
|
||||||
|
ResolveDomain(False);
|
||||||
|
end;
|
||||||
|
|
||||||
function TDDFieldDef.GetSectionName: String;
|
function TDDFieldDef.GetSectionName: String;
|
||||||
begin
|
begin
|
||||||
Result:=FFieldName;
|
Result:=FFieldName;
|
||||||
@ -956,6 +995,37 @@ begin
|
|||||||
Result:=(Collection as TDDFieldDefs)
|
Result:=(Collection as TDDFieldDefs)
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TDDFieldDef.DataDictionary: TFPDataDictionary;
|
||||||
|
begin
|
||||||
|
If Assigned(FieldDefs) then
|
||||||
|
Result:=FieldDefs.DataDictionary
|
||||||
|
else
|
||||||
|
Result:=Nil;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TDDFieldDef.ResolveDomain(ErrorOnFail : Boolean);
|
||||||
|
|
||||||
|
Var
|
||||||
|
DD : TFPDataDictionary;
|
||||||
|
|
||||||
|
begin
|
||||||
|
If (FDomainName<>'') then
|
||||||
|
Exit;
|
||||||
|
DD:=DataDictionary;
|
||||||
|
If Not Assigned(DD) then
|
||||||
|
begin
|
||||||
|
If ErrorOnFail then
|
||||||
|
Raise EDataDict.CreateFmt(SErrNoDataDict,[SErrResolveDomain]);
|
||||||
|
end
|
||||||
|
else if (Not Assigned(FDomain)) or (CompareText(FDomain.DomainName,FDomainName)<>0) then
|
||||||
|
begin
|
||||||
|
If ErrorOnFail then
|
||||||
|
FDomain:=DD.Domains.DomainByName(FDomainName)
|
||||||
|
else
|
||||||
|
FDomain:=DD.Domains.FindDomain(FDomainName);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TDDFieldDef.ImportFromField(F: TField; Existing : Boolean = True);
|
procedure TDDFieldDef.ImportFromField(F: TField; Existing : Boolean = True);
|
||||||
begin
|
begin
|
||||||
FieldName:=F.FieldName;
|
FieldName:=F.FieldName;
|
||||||
@ -1435,7 +1505,11 @@ end;
|
|||||||
constructor TFPDataDictionary.Create;
|
constructor TFPDataDictionary.Create;
|
||||||
begin
|
begin
|
||||||
FTables:=TDDTableDefs.Create(TDDTableDef);
|
FTables:=TDDTableDefs.Create(TDDTableDef);
|
||||||
|
FTables.FDataDictionary:=Self;
|
||||||
FSequences:=TDDSequenceDefs.Create;
|
FSequences:=TDDSequenceDefs.Create;
|
||||||
|
FSequences.FDataDictionary:=Self;
|
||||||
|
FDomains:=TDDDomainDefs.Create;
|
||||||
|
FDomains.FDataDictionary:=Self;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
destructor TFPDataDictionary.Destroy;
|
destructor TFPDataDictionary.Destroy;
|
||||||
@ -1475,8 +1549,9 @@ end;
|
|||||||
procedure TFPDataDictionary.SaveToIni(Ini: TCustomIniFile; ASection: String);
|
procedure TFPDataDictionary.SaveToIni(Ini: TCustomIniFile; ASection: String);
|
||||||
begin
|
begin
|
||||||
Ini.WriteString(ASection,KeyDataDictName,Name);
|
Ini.WriteString(ASection,KeyDataDictName,Name);
|
||||||
FTables.SaveToIni(Ini,SDatadictTables);
|
FDomains.SaveToIni(Ini,SDatadictDomains);
|
||||||
FSequences.SaveToIni(Ini,SDatadictSequences);
|
FSequences.SaveToIni(Ini,SDatadictSequences);
|
||||||
|
FTables.SaveToIni(Ini,SDatadictTables);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TFPDataDictionary.LoadFromFile(AFileName: String);
|
procedure TFPDataDictionary.LoadFromFile(AFileName: String);
|
||||||
@ -1502,6 +1577,10 @@ end;
|
|||||||
procedure TFPDataDictionary.LoadFromIni(Ini: TCustomIniFile; ASection: String);
|
procedure TFPDataDictionary.LoadFromIni(Ini: TCustomIniFile; ASection: String);
|
||||||
begin
|
begin
|
||||||
FDDName:=Ini.ReadString(ASection,KeyDataDictName,'');
|
FDDName:=Ini.ReadString(ASection,KeyDataDictName,'');
|
||||||
|
FDomains.Clear;
|
||||||
|
FDomains.LoadFromIni(Ini,SDataDictDomains);
|
||||||
|
FSequences.Clear;
|
||||||
|
FSequences.LoadFromIni(Ini,SDataDictSequences);
|
||||||
FTables.Clear;
|
FTables.Clear;
|
||||||
FTables.LoadFromIni(Ini,SDataDictTables);
|
FTables.LoadFromIni(Ini,SDataDictTables);
|
||||||
end;
|
end;
|
||||||
|
Loading…
Reference in New Issue
Block a user