From 0d63424104d341ef447f4ce1e9dbcd32993f8547 Mon Sep 17 00:00:00 2001 From: Mark van Renswoude Date: Mon, 21 Apr 2008 13:04:19 +0000 Subject: [PATCH] Fixed: elements which are part of a choice compositor are treated as being optional Fixed: xs:string properties use IXMLNode.Text property instead of NodeValue Changed: GUI uses DevEx components --- Forms/MainFrm.dfm | Bin 4284 -> 2840 bytes Forms/MainFrm.pas | 72 ++++++++++++++++----- Units/DelphiXMLDataBindingGenerator.pas | 17 +++-- Units/DelphiXMLDataBindingResources.pas | 80 ++++++------------------ Units/XMLDataBindingGenerator.pas | 3 +- X2XMLDataBinding.cfg | 11 ++-- 6 files changed, 89 insertions(+), 94 deletions(-) diff --git a/Forms/MainFrm.dfm b/Forms/MainFrm.dfm index 82afc81e146d461d2ef7b02ad97a9d98cd26e699..63fd5c798834d866f81f758544098b244bd7c2ee 100644 GIT binary patch literal 2840 zcmb_eU2o$=6rDJ&?ZipiT>)Z+7Fj$LD5zR##n)z<9=vz0In8J|(ti&OP^>d+*F2Rpj-XkDv4gCw+8p zciTb88}{y1ygnvjkHrf+`?GZn6H)#Zl|2?2pE)fS2M|B@S;(E*n2fHtfJGm|WpzyY zBqR&+C7^WGNL*2{>@n{UOxe_G<46z|zVbFg=2!O|r^nuT`>=U3>UvfERqd(y^i+mpmmaKyqdw>;#%~q%^aL-!G(9|H3#>P)d>qsm z(4ZXy7BEP(uqMA@j$<&eQ9pf?33LVptKZ6BUju^Hw#MxF-7!S;BeWtQm)2rPHq3}Qk z@%&Y5DFh3<0TK2DieSD1v#q9#&tmSFc%In4jpx#J3(rpy`O)oR%p!;d0e+yNc%!s+ zBvrJk<9U}-5^=&2dcCl25bBlEH-B#3&BEp@3ZHEckCmhb(rJ~CN(fcFM=@JQEw-|! z#jGQYu0D2lVnhY&>r9I@In@aGUz^2o@N`HuvPDwZr9rPq$$ z>|I5mUR+~hOD2rU8Y~L(ek#bq_n95Wd9~>aaskOs%jS`0{Bn!3Qp>H{)Tm=af} zQI*f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TV^V?K4b8Y3Y{0R!kVA5N{@rHRC$D1J zY#9lo+AE%6SA^fe*NPmK&`qEdq3j$RQ00oHcPxX%&x(yHLp(BKY0~3ti8hTeUI}$6 zczOr>t)tmP&WyzpaCwcXD*<)?BzadszQSySLkM2o&5qOl_meMKP7CNd7Ge$8sw8C9B7&S=ZWB#qMvDxw z`jbNxf|h(7B7@Iu6o@FhRVac}=+Ul>q7IEJ3GRZ9&}IuML=;WlWw%=)jeOdPfD7@j z3SYyO6bi|aGn2W@MbKi;Bq_S1^j2CiihgThaRi8_V0FzubKhe_S<1P zq1R{U!eIp)6vZ-aNe4w8!gp_qn)MzSBvm&@J*B2V{C5EQVPm%zpP$KBg+1u&0Px+t zQ|MsuQI?`E7#`h&`*HnduH}0s8Qz4TgyXBH8$+$0t5tvTbRqIZ+jFzBimfx$WU~Lh z5RK3ykHQ6d#1?cTF#Of!GRl*qT3t3H9^tn6i0M$M@*6bUe&+utG-b*}jY`bipmMY$ Pif-1|D4L~peum`VmkB;d diff --git a/Forms/MainFrm.pas b/Forms/MainFrm.pas index ee284c2..3748e01 100644 --- a/Forms/MainFrm.pas +++ b/Forms/MainFrm.pas @@ -1,45 +1,58 @@ unit MainFrm; +{$WARN UNIT_PLATFORM OFF} + interface uses Classes, + ComCtrls, Controls, + Dialogs, Forms, Mask, StdCtrls, - JvComponent, - JvExControls, - JvExMask, - JvPageList, - JvToolEdit; + cxButtonEdit, + cxContainer, + cxControls, + cxEdit, + cxLookAndFeels, + cxMaskEdit, + cxTextEdit; type TMainForm = class(TForm) btnClose: TButton; btnGenerate: TButton; - deFolder: TJvDirectoryEdit; - edtFolderPostfix: TEdit; - edtFolderPrefix: TEdit; - feFile: TJvFilenameEdit; - feSchema: TJvFilenameEdit; + DefaultEditStyle: TcxDefaultEditStyleController; + deFolder: TcxButtonEdit; + dlgOutputFile: TSaveDialog; + dlgSchema: TOpenDialog; + edtFolderPostfix: TcxTextEdit; + edtFolderPrefix: TcxTextEdit; + feFile: TcxButtonEdit; + feSchema: TcxButtonEdit; gbOutput: TGroupBox; lblFile: TLabel; lblFolder: TLabel; lblFolderPostfix: TLabel; lblFolderPrefix: TLabel; lblSchema: TLabel; - plOutput: TJvPageList; + LookAndFeel: TcxLookAndFeelController; + plOutput: TPageControl; rbFile: TRadioButton; rbFolder: TRadioButton; - spFile: TJvStandardPage; - spFolder: TJvStandardPage; + spFile: TTabSheet; + spFolder: TTabSheet; procedure btnCloseClick(Sender: TObject); procedure btnGenerateClick(Sender: TObject); procedure FormCreate(Sender: TObject); procedure OutputTypeClick(Sender: TObject); + procedure feFilePropertiesButtonClick(Sender: TObject; AButtonIndex: Integer); + procedure deFolderPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer); + procedure feSchemaPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer); private procedure GetFileName(Sender: TObject; const SchemaName: String; var Path, FileName: String); end; @@ -47,6 +60,7 @@ type implementation uses + FileCtrl, SysUtils, Windows, @@ -92,7 +106,7 @@ end; procedure TMainForm.btnGenerateClick(Sender: TObject); begin - if not FileExists(feSchema.FileName) then + if not FileExists(feSchema.Text) then begin MessageBox(Self.Handle, 'Please specify a valid schema file.', 'Schema file does not exist', MB_OK or MB_ICONERROR); @@ -106,7 +120,7 @@ begin if rbFile.Checked then begin OutputType := otSingle; - OutputPath := feFile.FileName; + OutputPath := feFile.Text; end else if rbFolder.Checked then begin OutputType := otMultiple; @@ -114,7 +128,9 @@ begin end; OnGetFileName := GetFileName; - Execute(feSchema.FileName); + Execute(feSchema.Text); + + ShowMessage('The data binding has been generated.'); finally Free(); end; @@ -134,4 +150,28 @@ begin CheckValidFileName(FileName); end; + +procedure TMainForm.feFilePropertiesButtonClick(Sender: TObject; AButtonIndex: Integer); +begin + if dlgOutputFile.Execute() then + feFile.Text := dlgOutputFile.FileName; +end; + + +procedure TMainForm.deFolderPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer); +var + directory: String; + +begin + if SelectDirectory('Select output folder', '', directory) then + deFolder.Text := directory; +end; + + +procedure TMainForm.feSchemaPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer); +begin + if dlgSchema.Execute() then + feSchema.Text := dlgSchema.FileName; +end; + end. diff --git a/Units/DelphiXMLDataBindingGenerator.pas b/Units/DelphiXMLDataBindingGenerator.pas index 0af3613..2c73dd6 100644 --- a/Units/DelphiXMLDataBindingGenerator.pas +++ b/Units/DelphiXMLDataBindingGenerator.pas @@ -921,6 +921,7 @@ var collectionItem: TXMLDataBindingItem; sourceCode: TNamedFormatStringList; typeDef: IXMLTypeDef; + typeMapping: TTypeMapping; begin Result := False; @@ -984,9 +985,13 @@ begin begin typeDef := TXMLDataBindingSimpleProperty(AItem.CollectionItem).DataType; - // #ToDo3 (MvR) 19-3-2008: use Text for strings ? sourceCode.Add('function TXML%:s.Get_%:s(Index: Integer): %:s;'); - sourceCode.Add(XMLToNativeDataType('Result', 'List[Index].NodeValue', typeDef, dntCustom)); + + if GetDataTypeMapping(typeDef, typeMapping) and (typeMapping.Conversion = tcString) then + sourceCode.Add(XMLToNativeDataType('Result', 'List[Index].Text', typeDef, dntCustom)) + else + sourceCode.Add(XMLToNativeDataType('Result', 'List[Index].NodeValue', typeDef, dntCustom)); + sourceCode.AddLn; sourceCode.Add('function TXML%:s.Add(%:s: %:s): %:s;'); @@ -1366,14 +1371,6 @@ begin typeMapping.Conversion := tcNone; - (* - if Length(TypeConversionVariables[AAccessor, ANodeType, typeMapping.Conversion]) > 0 then - begin - Add('var'); - Add(TypeConversionVariables[AAccessor, ANodeType, typeMapping.Conversion]); - end; - *) - Add('begin'); if Length(ALinesBefore) > 0 then diff --git a/Units/DelphiXMLDataBindingResources.pas b/Units/DelphiXMLDataBindingResources.pas index 8d2d252..ee0f204 100644 --- a/Units/DelphiXMLDataBindingResources.pas +++ b/Units/DelphiXMLDataBindingResources.pas @@ -162,7 +162,7 @@ const type - TTypeConversion = (tcNone, tcBoolean, tcFloat, tcDateTime); + TTypeConversion = (tcNone, tcBoolean, tcFloat, tcDateTime, tcString); TTypeConversions = set of TTypeConversion; TTypeMapping = record @@ -185,7 +185,7 @@ const (SchemaName: 'float'; DelphiName: 'Double'; Conversion: tcFloat), (SchemaName: 'double'; DelphiName: 'Double'; Conversion: tcFloat), (SchemaName: 'boolean'; DelphiName: 'Boolean'; Conversion: tcBoolean), - (SchemaName: 'string'; DelphiName: 'WideString'; Conversion: tcNone) + (SchemaName: 'string'; DelphiName: 'WideString'; Conversion: tcString) ); @@ -255,7 +255,10 @@ const ' Result := 0;' + CrLf + ' end;' + CrLf + 'end;' + CrLf + - '' + CrLf + '' + CrLf, + + { tcString } + '' ); @@ -268,21 +271,24 @@ const { tcNone } '', { tcBoolean } '', { tcFloat } ' %:s := XMLToFloat(ChildNodes[''%:s''].NodeValue);', - { tcDateTime } ' %:s := XMLToDate(ChildNodes[''%:s''].NodeValue);' + { tcDateTime } ' %:s := XMLToDate(ChildNodes[''%:s''].NodeValue);', + { tcString } ' %:s := ChildNodes[''%:s''].Text;' ), { dntAttribute } ( { tcNone } '', { tcBoolean } '', { tcFloat } ' %:s := XMLToFloat(AttributeNodes[''%:s''].NodeValue);', - { tcDateTime } ' %:s := XMLToDate(AttributeNodes[''%:s''].NodeValue);' + { tcDateTime } ' %:s := XMLToDate(AttributeNodes[''%:s''].NodeValue);', + { tcString } ' %:s := AttributeNodes[''%:s''].Text;' ), { dntCustom} ( { tcNone } '', { tcBoolean } '', { tcFloat } ' %:s := XMLToFloat(%:s);', - { tcDateTime } ' %:s := XMLToDate(%:s);' + { tcDateTime } ' %:s := XMLToDate(%:s);', + { tcString } '' ) ), { daSet } @@ -292,78 +298,28 @@ const { tcNone } '', { tcBoolean } ' ChildNodes[''%:s''].NodeValue := BoolToXML(%:s);', { tcFloat } ' ChildNodes[''%:s''].NodeValue := FloatToXML(%:s);', - { tcDateTime } ' ChildNodes[''%:s''].NodeValue := DateToXML(%:s);' + { tcDateTime } ' ChildNodes[''%:s''].NodeValue := DateToXML(%:s);', + { tcString } '' ), { dntAttribute } ( { tcNone } '', { tcBoolean } ' SetAttribute(''%:s'', BoolToXML(%:s));', { tcFloat } ' SetAttribute(''%:s'', FloatToXML(%:s));', - { tcDateTime } ' SetAttribute(''%:s'', DateToXML(%:s));' + { tcDateTime } ' SetAttribute(''%:s'', DateToXML(%:s));', + { tcString } '' ), { dntCustom} ( { tcNone } '', { tcBoolean } ' %:s := BoolToXML(%:s);', { tcFloat } ' %:s := FloatToXML(%:s);', - { tcDateTime } ' %:s := DateToXML(%:s);' + { tcDateTime } ' %:s := DateToXML(%:s);', + { tcString } '' ) ) ); - (* - TypeConversionVariables: array[TDelphiAccessor, TDelphiNodeType, TTypeConversion] of String = - ( - { daGet } - ( - { dntElement } - ( - { tcNone } '', - { tcBoolean } '', - { tcFloat } '', - { tcDateTime } '' - ), - { dntAttribute } - ( - { tcNone } '', - { tcBoolean } '', - { tcFloat } '', - { tcDateTime } '' - ), - { dntCustom} - ( - { tcNone } '', - { tcBoolean } '', - { tcFloat } '', - { tcDateTime } '' - ) - ), - { daSet } - ( - { dntElement } - ( - { tcNone } '', - { tcBoolean } '', - { tcFloat } '', - { tcDateTime } '' - ), - { dntAttribute } - ( - { tcNone } '', - { tcBoolean } '', - { tcFloat } '', - { tcDateTime } '' - ), - { dntCustom} - ( - { tcNone } '', - { tcBoolean } '', - { tcFloat } '', - { tcDateTime } '' - ) - ) - ); - *) implementation end. diff --git a/Units/XMLDataBindingGenerator.pas b/Units/XMLDataBindingGenerator.pas index d22d6a0..a3e511d 100644 --- a/Units/XMLDataBindingGenerator.pas +++ b/Units/XMLDataBindingGenerator.pas @@ -624,7 +624,8 @@ function TXMLDataBindingGenerator.CheckElementOccurance(AElement: IXMLElementDef if Supports(ANode, IXMLElementCompositor, compositor) then begin case AOccurance of - boMinOccurs: Result := (compositor.MinOccurs = 0); + boMinOccurs: Result := (compositor.MinOccurs = 0) or + (compositor.CompositorType = ctChoice); boMaxOccurs: Result := (compositor.MaxOccurs = MaxOccursUnbounded) or (compositor.MaxOccurs > 1); end; diff --git a/X2XMLDataBinding.cfg b/X2XMLDataBinding.cfg index 2125801..5ea2a42 100644 --- a/X2XMLDataBinding.cfg +++ b/X2XMLDataBinding.cfg @@ -1,6 +1,6 @@ -$A8 -$B- --$C+ +-$C- -$D+ -$E- -$F- @@ -12,7 +12,7 @@ -$L+ -$M- -$N+ --$O+ +-$O- -$P+ -$Q- -$R- @@ -22,7 +22,7 @@ -$V+ -$W- -$X+ --$YD +-$Y+ -$Z1 -GD -cg @@ -32,8 +32,9 @@ -M -$M16384,1048576 -K$00400000 --LE"C:\Documents and Settings\PsychoMark\My Documents\Borland Studio Projects\Bpl" --LN"C:\Documents and Settings\PsychoMark\My Documents\Borland Studio Projects\Bpl" +-N"lib" +-LE"c:\program files\borland\delphi7\Projects\Bpl" +-LN"c:\program files\borland\delphi7\Projects\Bpl" -w-UNSAFE_TYPE -w-UNSAFE_CODE -w-UNSAFE_CAST