1
0
mirror of synced 2024-11-14 19:13:50 +00:00

Make generation of 'Def' getter method configurable.\nSkip generation of 'Def' getter method for Variants

This commit is contained in:
Bert Herngreen 2017-09-06 17:12:15 +02:00
parent 5451a52cd2
commit a30ef97eb3
6 changed files with 64 additions and 25 deletions

View File

@ -4,7 +4,7 @@ object MainForm: TMainForm
BorderIcons = [biSystemMenu, biMinimize] BorderIcons = [biSystemMenu, biMinimize]
BorderStyle = bsDialog BorderStyle = bsDialog
Caption = 'X'#178'Software XML Data Binding for Delphi' Caption = 'X'#178'Software XML Data Binding for Delphi'
ClientHeight = 291 ClientHeight = 312
ClientWidth = 438 ClientWidth = 438
Color = clBtnFace Color = clBtnFace
Font.Charset = DEFAULT_CHARSET Font.Charset = DEFAULT_CHARSET
@ -17,7 +17,7 @@ object MainForm: TMainForm
OnCreate = FormCreate OnCreate = FormCreate
DesignSize = ( DesignSize = (
438 438
291) 312)
PixelsPerInch = 96 PixelsPerInch = 96
TextHeight = 13 TextHeight = 13
object lblSchema: TLabel object lblSchema: TLabel
@ -44,14 +44,14 @@ object MainForm: TMainForm
Left = 8 Left = 8
Top = 43 Top = 43
Width = 422 Width = 422
Height = 204 Height = 225
Anchors = [akLeft, akTop, akBottom] Anchors = [akLeft, akTop, akBottom]
Caption = ' Output ' Caption = ' Output '
TabOrder = 1 TabOrder = 1
ExplicitHeight = 167 ExplicitHeight = 204
DesignSize = ( DesignSize = (
422 422
204) 225)
object rbFile: TRadioButton object rbFile: TRadioButton
Left = 11 Left = 11
Top = 21 Top = 21
@ -83,7 +83,6 @@ object MainForm: TMainForm
TabOrder = 2 TabOrder = 2
object spFile: TTabSheet object spFile: TTabSheet
TabVisible = False TabVisible = False
ExplicitHeight = 85
object lblFile: TLabel object lblFile: TLabel
Left = 4 Left = 4
Top = 7 Top = 7
@ -105,8 +104,6 @@ object MainForm: TMainForm
end end
object spFolder: TTabSheet object spFolder: TTabSheet
TabVisible = False TabVisible = False
ExplicitLeft = 8
ExplicitHeight = 195
DesignSize = ( DesignSize = (
408 408
83) 83)
@ -171,10 +168,19 @@ object MainForm: TMainForm
'perties' 'perties'
TabOrder = 3 TabOrder = 3
end end
object cbGenerateGetOptionalOrDefault: TCheckBox
Left = 11
Top = 198
Width = 401
Height = 17
Hint = ' Generate a "Def" method for optional elements'
Caption = ' Generate a "Def" method for optional elements'
TabOrder = 4
end
end end
object btnGenerate: TButton object btnGenerate: TButton
Left = 274 Left = 274
Top = 258 Top = 279
Width = 75 Width = 75
Height = 25 Height = 25
Anchors = [akRight, akBottom] Anchors = [akRight, akBottom]
@ -182,11 +188,11 @@ object MainForm: TMainForm
Default = True Default = True
TabOrder = 3 TabOrder = 3
OnClick = btnGenerateClick OnClick = btnGenerateClick
ExplicitTop = 221 ExplicitTop = 258
end end
object btnClose: TButton object btnClose: TButton
Left = 355 Left = 355
Top = 258 Top = 279
Width = 75 Width = 75
Height = 25 Height = 25
Anchors = [akRight, akBottom] Anchors = [akRight, akBottom]
@ -194,11 +200,11 @@ object MainForm: TMainForm
Caption = '&Close' Caption = '&Close'
TabOrder = 4 TabOrder = 4
OnClick = btnCloseClick OnClick = btnCloseClick
ExplicitTop = 221 ExplicitTop = 258
end end
object btnHints: TButton object btnHints: TButton
Left = 7 Left = 7
Top = 258 Top = 279
Width = 142 Width = 142
Height = 25 Height = 25
Anchors = [akRight, akBottom] Anchors = [akRight, akBottom]
@ -206,7 +212,7 @@ object MainForm: TMainForm
Caption = 'Generate blank &Hints file' Caption = 'Generate blank &Hints file'
TabOrder = 2 TabOrder = 2
OnClick = btnHintsClick OnClick = btnHintsClick
ExplicitTop = 221 ExplicitTop = 258
end end
object DefaultEditStyle: TcxDefaultEditStyleController object DefaultEditStyle: TcxDefaultEditStyleController
Style.HotTrack = False Style.HotTrack = False

View File

@ -52,6 +52,7 @@ type
spFile: TTabSheet; spFile: TTabSheet;
spFolder: TTabSheet; spFolder: TTabSheet;
cbHasChecksEmpty: TCheckBox; cbHasChecksEmpty: TCheckBox;
cbGenerateGetOptionalOrDefault: TCheckBox;
procedure btnCloseClick(Sender: TObject); procedure btnCloseClick(Sender: TObject);
procedure btnGenerateClick(Sender: TObject); procedure btnGenerateClick(Sender: TObject);
@ -183,6 +184,7 @@ begin
end; end;
generator.HasChecksEmpty := cbHasChecksEmpty.Checked; generator.HasChecksEmpty := cbHasChecksEmpty.Checked;
generator.HasGenerateGetOptionalOrDefault := cbGenerateGetOptionalOrDefault.Checked;
generator.OnGetFileName := GetFileName; generator.OnGetFileName := GetFileName;
generator.Execute(feSchema.Text); generator.Execute(feSchema.Text);
@ -283,6 +285,7 @@ begin
end; end;
cbHasChecksEmpty.Checked := settings.Output.HasHasChecksEmpty and settings.Output.HasChecksEmpty; cbHasChecksEmpty.Checked := settings.Output.HasHasChecksEmpty and settings.Output.HasChecksEmpty;
cbGenerateGetOptionalOrDefault.Checked := settings.Output.HasGenerateGetOptionalOrDefault and settings.Output.GenerateGetOptionalOrDefault;
end; end;
end; end;
end; end;
@ -319,6 +322,7 @@ begin
end; end;
settings.Output.HasChecksEmpty := cbHasChecksEmpty.Checked; settings.Output.HasChecksEmpty := cbHasChecksEmpty.Checked;
settings.Output.GetOptionalOrDefault := cbGenerateGetOptionalOrDefault.Checked;
settings.OwnerDocument.SaveToFile(fileName); settings.OwnerDocument.SaveToFile(fileName);
end; end;

View File

@ -1,7 +1,7 @@
{ {
X2Software XML Data Binding X2Software XML Data Binding
Generated on: 21-7-2017 9:19:46 Generated on: 6-9-2017 16:58:58
Generated from: P:\x2xmldatabinding\XSD\DataBindingSettings.xsd Generated from: P:\x2xmldatabinding\XSD\DataBindingSettings.xsd
} }
unit DataBindingSettingsXML; unit DataBindingSettingsXML;
@ -28,7 +28,7 @@ type
Contains the settings and hints for the Delphi XML Data Binding. Contains the settings and hints for the Delphi XML Data Binding.
} }
IXMLDataBindingSettings = interface(IXMLNode) IXMLDataBindingSettings = interface(IXMLNode)
['{0407CBCB-B49B-4ED3-A2F6-CCDDFE46F334}'] ['{90C0CA10-A7AD-4418-98B6-D03469DB8913}']
procedure XSDValidateDocument(AStrict: Boolean = False); procedure XSDValidateDocument(AStrict: Boolean = False);
function GetHasOutput: Boolean; function GetHasOutput: Boolean;
function GetOutput: IXMLDataBindingOutput; function GetOutput: IXMLDataBindingOutput;
@ -41,7 +41,7 @@ type
Contains the user-defined output settings last used Contains the user-defined output settings last used
} }
IXMLDataBindingOutput = interface(IXMLNode) IXMLDataBindingOutput = interface(IXMLNode)
['{21821EFA-C7D8-4299-BF44-8122FBF2BC2E}'] ['{166F0975-2D2F-4CDB-B911-005163A0761F}']
procedure XSDValidate; procedure XSDValidate;
procedure XSDValidateStrict(AResult: IXSDValidateStrictResult); procedure XSDValidateStrict(AResult: IXSDValidateStrictResult);
@ -53,10 +53,13 @@ type
function GetOutputMultiple: IXMLOutputMultiple; function GetOutputMultiple: IXMLOutputMultiple;
function GetHasHasChecksEmpty: Boolean; function GetHasHasChecksEmpty: Boolean;
function GetHasChecksEmpty: Boolean; function GetHasChecksEmpty: Boolean;
function GetHasGenerateGetOptionalOrDefault: Boolean;
function GetGenerateGetOptionalOrDefault: Boolean;
procedure SetOutputTypeText(const Value: WideString); procedure SetOutputTypeText(const Value: WideString);
procedure SetOutputType(const Value: TXMLDataBindingOutputType); procedure SetOutputType(const Value: TXMLDataBindingOutputType);
procedure SetHasChecksEmpty(const Value: Boolean); procedure SetHasChecksEmpty(const Value: Boolean);
procedure SetGenerateGetOptionalOrDefault(const Value: Boolean);
property OutputTypeText: WideString read GetOutputTypeText write SetOutputTypeText; property OutputTypeText: WideString read GetOutputTypeText write SetOutputTypeText;
property OutputType: TXMLDataBindingOutputType read GetOutputType write SetOutputType; property OutputType: TXMLDataBindingOutputType read GetOutputType write SetOutputType;
@ -66,10 +69,12 @@ type
property OutputMultiple: IXMLOutputMultiple read GetOutputMultiple; property OutputMultiple: IXMLOutputMultiple read GetOutputMultiple;
property HasHasChecksEmpty: Boolean read GetHasHasChecksEmpty; property HasHasChecksEmpty: Boolean read GetHasHasChecksEmpty;
property HasChecksEmpty: Boolean read GetHasChecksEmpty write SetHasChecksEmpty; property HasChecksEmpty: Boolean read GetHasChecksEmpty write SetHasChecksEmpty;
property HasGenerateGetOptionalOrDefault: Boolean read GetHasGenerateGetOptionalOrDefault;
property GenerateGetOptionalOrDefault: Boolean read GetGenerateGetOptionalOrDefault write SetGenerateGetOptionalOrDefault;
end; end;
IXMLOutputSingle = interface(IXMLNode) IXMLOutputSingle = interface(IXMLNode)
['{ABB2D62A-0B4D-4E4B-8835-ED8AFE7564EA}'] ['{77AE2C19-333F-4335-872E-659AE17C4701}']
procedure XSDValidate; procedure XSDValidate;
procedure XSDValidateStrict(AResult: IXSDValidateStrictResult); procedure XSDValidateStrict(AResult: IXSDValidateStrictResult);
@ -81,7 +86,7 @@ type
end; end;
IXMLOutputMultiple = interface(IXMLNode) IXMLOutputMultiple = interface(IXMLNode)
['{2F4918D6-EE9C-4986-9052-285A8B4D58C5}'] ['{8C1E7817-DBF1-4125-B29A-F7279006C7FB}']
procedure XSDValidate; procedure XSDValidate;
procedure XSDValidateStrict(AResult: IXSDValidateStrictResult); procedure XSDValidateStrict(AResult: IXSDValidateStrictResult);
@ -124,10 +129,13 @@ type
function GetOutputMultiple: IXMLOutputMultiple; function GetOutputMultiple: IXMLOutputMultiple;
function GetHasHasChecksEmpty: Boolean; function GetHasHasChecksEmpty: Boolean;
function GetHasChecksEmpty: Boolean; function GetHasChecksEmpty: Boolean;
function GetHasGenerateGetOptionalOrDefault: Boolean;
function GetGenerateGetOptionalOrDefault: Boolean;
procedure SetOutputTypeText(const Value: WideString); procedure SetOutputTypeText(const Value: WideString);
procedure SetOutputType(const Value: TXMLDataBindingOutputType); procedure SetOutputType(const Value: TXMLDataBindingOutputType);
procedure SetHasChecksEmpty(const Value: Boolean); procedure SetHasChecksEmpty(const Value: Boolean);
procedure SetGenerateGetOptionalOrDefault(const Value: Boolean);
end; end;
TXMLOutputSingle = class(TX2XMLNode, IXSDValidate, IXSDValidateStrict, IXMLOutputSingle) TXMLOutputSingle = class(TX2XMLNode, IXSDValidate, IXSDValidateStrict, IXMLOutputSingle)
@ -279,13 +287,13 @@ end;
procedure TXMLDataBindingOutput.XSDValidate; procedure TXMLDataBindingOutput.XSDValidate;
begin begin
GetOutputType; GetOutputType;
SortChildNodes(Self, ['OutputType', 'OutputSingle', 'OutputMultiple', 'HasChecksEmpty']); SortChildNodes(Self, ['OutputType', 'OutputSingle', 'OutputMultiple', 'HasChecksEmpty', 'GenerateGetOptionalOrDefault']);
end; end;
procedure TXMLDataBindingOutput.XSDValidateStrict(AResult: IXSDValidateStrictResult); procedure TXMLDataBindingOutput.XSDValidateStrict(AResult: IXSDValidateStrictResult);
begin begin
GetOutputType; GetOutputType;
SortChildNodes(Self, ['OutputType', 'OutputSingle', 'OutputMultiple', 'HasChecksEmpty']); SortChildNodes(Self, ['OutputType', 'OutputSingle', 'OutputMultiple', 'HasChecksEmpty', 'GenerateGetOptionalOrDefault']);
end; end;
function TXMLDataBindingOutput.GetOutputTypeText: WideString; function TXMLDataBindingOutput.GetOutputTypeText: WideString;
@ -332,6 +340,17 @@ begin
Result := ChildNodes['HasChecksEmpty'].NodeValue; Result := ChildNodes['HasChecksEmpty'].NodeValue;
end; end;
function TXMLDataBindingOutput.GetHasGenerateGetOptionalOrDefault: Boolean;
begin
Result := Assigned(ChildNodes.FindNode('GenerateGetOptionalOrDefault'));
end;
function TXMLDataBindingOutput.GetGenerateGetOptionalOrDefault: Boolean;
begin
Result := ChildNodes['GenerateGetOptionalOrDefault'].NodeValue;
end;
procedure TXMLDataBindingOutput.SetOutputTypeText(const Value: WideString); procedure TXMLDataBindingOutput.SetOutputTypeText(const Value: WideString);
begin begin
ChildNodes['OutputType'].NodeValue := Value; ChildNodes['OutputType'].NodeValue := Value;
@ -348,6 +367,11 @@ begin
ChildNodes['HasChecksEmpty'].NodeValue := BoolToXML(Value); ChildNodes['HasChecksEmpty'].NodeValue := BoolToXML(Value);
end; end;
procedure TXMLDataBindingOutput.SetGenerateGetOptionalOrDefault(const Value: Boolean);
begin
ChildNodes['GenerateGetOptionalOrDefault'].NodeValue := BoolToXML(Value);
end;
procedure TXMLOutputSingle.XSDValidate; procedure TXMLOutputSingle.XSDValidate;
begin begin
CreateRequiredElements(Self, ['FileName']); CreateRequiredElements(Self, ['FileName']);

View File

@ -23,6 +23,7 @@ type
FHasChecksEmpty: Boolean; FHasChecksEmpty: Boolean;
FOnGetFileName: TGetFileNameEvent; FOnGetFileName: TGetFileNameEvent;
FHasGenerateGetOptionalOrDefault: Boolean;
protected protected
procedure GenerateDataBinding; override; procedure GenerateDataBinding; override;
procedure GenerateOutputFile(ASchemaList: TXMLSchemaList; const ASourceFileName, AUnitName: String); procedure GenerateOutputFile(ASchemaList: TXMLSchemaList; const ASourceFileName, AUnitName: String);
@ -72,6 +73,7 @@ type
property UnitNames: TDictionary<TXMLDataBindingSchema, String> read FUnitNames; property UnitNames: TDictionary<TXMLDataBindingSchema, String> read FUnitNames;
public public
property HasChecksEmpty: Boolean read FHasChecksEmpty write FHasChecksEmpty; property HasChecksEmpty: Boolean read FHasChecksEmpty write FHasChecksEmpty;
property HasGenerateGetOptionalOrDefault: Boolean read FHasGenerateGetOptionalOrDefault write FHasGenerateGetOptionalOrDefault;
property OnGetFileName: TGetFileNameEvent read FOnGetFileName write FOnGetFileName; property OnGetFileName: TGetFileNameEvent read FOnGetFileName write FOnGetFileName;
end; end;
@ -86,6 +88,8 @@ uses
X2Log.Global; X2Log.Global;
const
VariantText = 'Variant';
{ TDelphiXMLDataBindingGenerator } { TDelphiXMLDataBindingGenerator }
@ -314,7 +318,7 @@ var
typeMapping: TTypeMapping; typeMapping: TTypeMapping;
begin begin
Result := 'Variant'; Result := VariantText;
if GetDataTypeMapping(ADataType, typeMapping) then if GetDataTypeMapping(ADataType, typeMapping) then
Result := typeMapping.DelphiName; Result := typeMapping.DelphiName;
end; end;
@ -1225,7 +1229,7 @@ begin
if writeOptional then if writeOptional then
begin begin
sourceCode.Add(PropertyIntfMethodGetOptional); sourceCode.Add(PropertyIntfMethodGetOptional);
if AProperty.PropertyType = ptSimple then if HasGenerateGetOptionalOrDefault and (AProperty.PropertyType = ptSimple) and (dataTypeName <> VariantText) then
sourceCode.Add(PropertyIntfMethodGetOptionalOrDefault); sourceCode.Add(PropertyIntfMethodGetOptionalOrDefault);
end; end;
@ -1316,7 +1320,7 @@ begin
sourceCode.Add(PropertyImplMethodGetOptional[GetDelphiElementType(nodeType)]); sourceCode.Add(PropertyImplMethodGetOptional[GetDelphiElementType(nodeType)]);
end; end;
if AProperty.PropertyType = ptSimple then if HasGenerateGetOptionalOrDefault and (AProperty.PropertyType = ptSimple) and (dataTypeName <> VariantText) then
sourceCode.Add(PropertyImplMethodGetOptionalOrDefault); sourceCode.Add(PropertyImplMethodGetOptionalOrDefault);
end; end;

View File

@ -1,2 +1,2 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<DataBindingSettings xmlns="http://www.x2software.net/xsd/databinding/DataBindingSettings.xsd"><Output><OutputType>Single</OutputType><OutputSingle><FileName>..\Units\DataBindingSettingsXML.pas</FileName></OutputSingle></Output></DataBindingSettings> <DataBindingSettings xmlns="http://www.x2software.net/xsd/databinding/DataBindingSettings.xsd"><Output><OutputType>Single</OutputType><OutputSingle><FileName>..\Units\DataBindingSettingsXML.pas</FileName></OutputSingle><HasChecksEmpty>false</HasChecksEmpty><GenerateGetOptionalOrDefault>false</GenerateGetOptionalOrDefault></Output></DataBindingSettings>

View File

@ -35,6 +35,7 @@
</xs:element> </xs:element>
</xs:choice> </xs:choice>
<xs:element name="HasChecksEmpty" type="xs:boolean" minOccurs="0"/> <xs:element name="HasChecksEmpty" type="xs:boolean" minOccurs="0"/>
<xs:element name="GenerateGetOptionalOrDefault" type="xs:boolean" minOccurs="0"/>
</xs:sequence> </xs:sequence>
</xs:complexType> </xs:complexType>
<xs:simpleType name="DataBindingOutputType"> <xs:simpleType name="DataBindingOutputType">