diff --git a/Forms/MainFrm.dfm b/Forms/MainFrm.dfm index 82afc81..63fd5c7 100644 Binary files a/Forms/MainFrm.dfm and b/Forms/MainFrm.dfm differ 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