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

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
This commit is contained in:
Mark van Renswoude 2008-04-21 13:04:19 +00:00
parent 0c38a497f9
commit 0d63424104
6 changed files with 89 additions and 94 deletions

Binary file not shown.

View File

@ -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.

View File

@ -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%<Name>:s.Get_%<ItemName>:s(Index: Integer): %<DataType>:s;');
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%<Name>:s.Add(%<ItemName>:s: %<DataType>:s): %<DataInterface>: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

View File

@ -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 } ' %<Destination>:s := XMLToFloat(ChildNodes[''%<Source>:s''].NodeValue);',
{ tcDateTime } ' %<Destination>:s := XMLToDate(ChildNodes[''%<Source>:s''].NodeValue);'
{ tcDateTime } ' %<Destination>:s := XMLToDate(ChildNodes[''%<Source>:s''].NodeValue);',
{ tcString } ' %<Destination>:s := ChildNodes[''%<Source>:s''].Text;'
),
{ dntAttribute }
(
{ tcNone } '',
{ tcBoolean } '',
{ tcFloat } ' %<Destination>:s := XMLToFloat(AttributeNodes[''%<Source>:s''].NodeValue);',
{ tcDateTime } ' %<Destination>:s := XMLToDate(AttributeNodes[''%<Source>:s''].NodeValue);'
{ tcDateTime } ' %<Destination>:s := XMLToDate(AttributeNodes[''%<Source>:s''].NodeValue);',
{ tcString } ' %<Destination>:s := AttributeNodes[''%<Source>:s''].Text;'
),
{ dntCustom}
(
{ tcNone } '',
{ tcBoolean } '',
{ tcFloat } ' %<Destination>:s := XMLToFloat(%<Source>:s);',
{ tcDateTime } ' %<Destination>:s := XMLToDate(%<Source>:s);'
{ tcDateTime } ' %<Destination>:s := XMLToDate(%<Source>:s);',
{ tcString } ''
)
),
{ daSet }
@ -292,78 +298,28 @@ const
{ tcNone } '',
{ tcBoolean } ' ChildNodes[''%<Destination>:s''].NodeValue := BoolToXML(%<Source>:s);',
{ tcFloat } ' ChildNodes[''%<Destination>:s''].NodeValue := FloatToXML(%<Source>:s);',
{ tcDateTime } ' ChildNodes[''%<Destination>:s''].NodeValue := DateToXML(%<Source>:s);'
{ tcDateTime } ' ChildNodes[''%<Destination>:s''].NodeValue := DateToXML(%<Source>:s);',
{ tcString } ''
),
{ dntAttribute }
(
{ tcNone } '',
{ tcBoolean } ' SetAttribute(''%<Destination>:s'', BoolToXML(%<Source>:s));',
{ tcFloat } ' SetAttribute(''%<Destination>:s'', FloatToXML(%<Source>:s));',
{ tcDateTime } ' SetAttribute(''%<Destination>:s'', DateToXML(%<Source>:s));'
{ tcDateTime } ' SetAttribute(''%<Destination>:s'', DateToXML(%<Source>:s));',
{ tcString } ''
),
{ dntCustom}
(
{ tcNone } '',
{ tcBoolean } ' %<Destination>:s := BoolToXML(%<Source>:s);',
{ tcFloat } ' %<Destination>:s := FloatToXML(%<Source>:s);',
{ tcDateTime } ' %<Destination>:s := DateToXML(%<Source>:s);'
{ tcDateTime } ' %<Destination>:s := DateToXML(%<Source>: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.

View File

@ -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;

View File

@ -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