diff --git a/Forms/MainFrm.dfm b/Forms/MainFrm.dfm index a00b3b5..61c2b0a 100644 --- a/Forms/MainFrm.dfm +++ b/Forms/MainFrm.dfm @@ -35,7 +35,6 @@ object MainForm: TMainForm AddQuotes = False Anchors = [akLeft, akTop, akRight] TabOrder = 0 - Text = 'F:\XTxXSD\Dealer.xsd' end object gbOutput: TGroupBox Left = 8 @@ -94,8 +93,9 @@ object MainForm: TMainForm Width = 321 Height = 21 AddQuotes = False + DialogKind = dkSave + DialogOptions = [ofOverwritePrompt, ofHideReadOnly] TabOrder = 0 - Text = 'F:\XTxXSD\Output\xml_Offerte.pas' end end object spFolder: TJvStandardPage diff --git a/Forms/MainFrm.pas b/Forms/MainFrm.pas index 5708ae0..54f03d9 100644 --- a/Forms/MainFrm.pas +++ b/Forms/MainFrm.pas @@ -58,8 +58,6 @@ uses procedure TMainForm.FormCreate(Sender: TObject); begin plOutput.ActivePageIndex := 0; - btnGenerate.Click; - ModalResult := mrCancel; end; diff --git a/Tests/Data/01. Basic simple and complex types.xsd b/Tests/Data/01. Basic simple and complex types.xsd new file mode 100644 index 0000000..7bd9b0d --- /dev/null +++ b/Tests/Data/01. Basic simple and complex types.xsd @@ -0,0 +1,20 @@ + + + + + + Simple test element + + + + + + + + + + + + + + diff --git a/Tests/Data/01. Basic simple and complex types_expected.xml b/Tests/Data/01. Basic simple and complex types_expected.xml new file mode 100644 index 0000000..2029d8b --- /dev/null +++ b/Tests/Data/01. Basic simple and complex types_expected.xml @@ -0,0 +1,24 @@ + + + + + 01. Basic simple and complex types + + + Interface + TestElement + + Interface + + + + Interface + TestComplexType + + ComplexType + + + + + + diff --git a/Tests/Source/DataBindingResultXML.pas b/Tests/Source/DataBindingResultXML.pas new file mode 100644 index 0000000..ab449ad --- /dev/null +++ b/Tests/Source/DataBindingResultXML.pas @@ -0,0 +1,391 @@ + +{****************************************************************************************} +{ } +{ XML Data Binding } +{ } +{ Generated on: 10-3-2008 20:12:45 } +{ Generated from: F:\Archive\2007\XMLDataBinding\Tests\XSD\DataBindingResult.xsd } +{ } +{****************************************************************************************} + +unit DataBindingResultXML; + +interface + +uses xmldom, XMLDoc, XMLIntf; + +type + +{ Forward Decls } + + IXMLDataBindingResult = interface; + IXMLSchemas = interface; + IXMLSchema = interface; + IXMLItems = interface; + IXMLItem = interface; + IXMLInterface_ = interface; + IXMLCollection = interface; + IXMLEnumeration = interface; + +{ IXMLDataBindingResult } + + IXMLDataBindingResult = interface(IXMLNode) + ['{B62DB507-8C4B-4966-BE94-F862B6546389}'] + { Property Accessors } + function Get_Schemas: IXMLSchemas; + { Methods & Properties } + property Schemas: IXMLSchemas read Get_Schemas; + end; + +{ IXMLSchemas } + + IXMLSchemas = interface(IXMLNodeCollection) + ['{EBDC76EA-3887-4479-8359-2D8038878707}'] + { Property Accessors } + function Get_Schema(Index: Integer): IXMLSchema; + { Methods & Properties } + function Add: IXMLSchema; + function Insert(const Index: Integer): IXMLSchema; + property Schema[Index: Integer]: IXMLSchema read Get_Schema; default; + end; + +{ IXMLSchema } + + IXMLSchema = interface(IXMLNode) + ['{6C82BA3F-537E-4112-BE1E-85B50482D4C1}'] + { Property Accessors } + function Get_Name: WideString; + function Get_Items: IXMLItems; + procedure Set_Name(Value: WideString); + { Methods & Properties } + property Name: WideString read Get_Name write Set_Name; + property Items: IXMLItems read Get_Items; + end; + +{ IXMLItems } + + IXMLItems = interface(IXMLNodeCollection) + ['{4A1633BF-D402-4A8B-8DA2-0C7E06EE899F}'] + { Property Accessors } + function Get_Item(Index: Integer): IXMLItem; + { Methods & Properties } + function Add: IXMLItem; + function Insert(const Index: Integer): IXMLItem; + property Item[Index: Integer]: IXMLItem read Get_Item; default; + end; + +{ IXMLItem } + + IXMLItem = interface(IXMLNode) + ['{934648C4-4E29-4F45-B2AF-2BDC0B82A80A}'] + { Property Accessors } + function Get_ItemType: WideString; + function Get_Name: WideString; + function Get_Interface_: IXMLInterface_; + function Get_Collection: IXMLCollection; + function Get_Enumeration: IXMLEnumeration; + procedure Set_ItemType(Value: WideString); + procedure Set_Name(Value: WideString); + { Methods & Properties } + property ItemType: WideString read Get_ItemType write Set_ItemType; + property Name: WideString read Get_Name write Set_Name; + property Interface_: IXMLInterface_ read Get_Interface_; + property Collection: IXMLCollection read Get_Collection; + property Enumeration: IXMLEnumeration read Get_Enumeration; + end; + +{ IXMLInterface_ } + + IXMLInterface_ = interface(IXMLNode) + ['{F480A9C8-0B74-4CB7-A26C-C66A9ACA533B}'] + end; + +{ IXMLCollection } + + IXMLCollection = interface(IXMLNode) + ['{0D31D0E8-EE5F-4804-86F3-C3B3CA271F79}'] + { Property Accessors } + function Get_ItemName: WideString; + procedure Set_ItemName(Value: WideString); + { Methods & Properties } + property ItemName: WideString read Get_ItemName write Set_ItemName; + end; + +{ IXMLEnumeration } + + IXMLEnumeration = interface(IXMLNode) + ['{3E1E8C1C-073B-4860-AC03-23EF7954C13D}'] + end; + +{ Forward Decls } + + TXMLDataBindingResult = class; + TXMLSchemas = class; + TXMLSchema = class; + TXMLItems = class; + TXMLItem = class; + TXMLInterface_ = class; + TXMLCollection = class; + TXMLEnumeration = class; + +{ TXMLDataBindingResult } + + TXMLDataBindingResult = class(TXMLNode, IXMLDataBindingResult) + protected + { IXMLDataBindingResult } + function Get_Schemas: IXMLSchemas; + public + procedure AfterConstruction; override; + end; + +{ TXMLSchemas } + + TXMLSchemas = class(TXMLNodeCollection, IXMLSchemas) + protected + { IXMLSchemas } + function Get_Schema(Index: Integer): IXMLSchema; + function Add: IXMLSchema; + function Insert(const Index: Integer): IXMLSchema; + public + procedure AfterConstruction; override; + end; + +{ TXMLSchema } + + TXMLSchema = class(TXMLNode, IXMLSchema) + protected + { IXMLSchema } + function Get_Name: WideString; + function Get_Items: IXMLItems; + procedure Set_Name(Value: WideString); + public + procedure AfterConstruction; override; + end; + +{ TXMLItems } + + TXMLItems = class(TXMLNodeCollection, IXMLItems) + protected + { IXMLItems } + function Get_Item(Index: Integer): IXMLItem; + function Add: IXMLItem; + function Insert(const Index: Integer): IXMLItem; + public + procedure AfterConstruction; override; + end; + +{ TXMLItem } + + TXMLItem = class(TXMLNode, IXMLItem) + protected + { IXMLItem } + function Get_ItemType: WideString; + function Get_Name: WideString; + function Get_Interface_: IXMLInterface_; + function Get_Collection: IXMLCollection; + function Get_Enumeration: IXMLEnumeration; + procedure Set_ItemType(Value: WideString); + procedure Set_Name(Value: WideString); + public + procedure AfterConstruction; override; + end; + +{ TXMLInterface_ } + + TXMLInterface_ = class(TXMLNode, IXMLInterface_) + protected + { IXMLInterface_ } + end; + +{ TXMLCollection } + + TXMLCollection = class(TXMLNode, IXMLCollection) + protected + { IXMLCollection } + function Get_ItemName: WideString; + procedure Set_ItemName(Value: WideString); + end; + +{ TXMLEnumeration } + + TXMLEnumeration = class(TXMLNode, IXMLEnumeration) + protected + { IXMLEnumeration } + end; + +{ Global Functions } + +function GetDataBindingResult(Doc: IXMLDocument): IXMLDataBindingResult; +function LoadDataBindingResult(const FileName: WideString): IXMLDataBindingResult; +function NewDataBindingResult: IXMLDataBindingResult; + +const + TargetNamespace = ''; + +implementation + +{ Global Functions } + +function GetDataBindingResult(Doc: IXMLDocument): IXMLDataBindingResult; +begin + Result := Doc.GetDocBinding('DataBindingResult', TXMLDataBindingResult, TargetNamespace) as IXMLDataBindingResult; +end; + +function LoadDataBindingResult(const FileName: WideString): IXMLDataBindingResult; +begin + Result := LoadXMLDocument(FileName).GetDocBinding('DataBindingResult', TXMLDataBindingResult, TargetNamespace) as IXMLDataBindingResult; +end; + +function NewDataBindingResult: IXMLDataBindingResult; +begin + Result := NewXMLDocument.GetDocBinding('DataBindingResult', TXMLDataBindingResult, TargetNamespace) as IXMLDataBindingResult; +end; + +{ TXMLDataBindingResult } + +procedure TXMLDataBindingResult.AfterConstruction; +begin + RegisterChildNode('Schemas', TXMLSchemas); + inherited; +end; + +function TXMLDataBindingResult.Get_Schemas: IXMLSchemas; +begin + Result := ChildNodes['Schemas'] as IXMLSchemas; +end; + +{ TXMLSchemas } + +procedure TXMLSchemas.AfterConstruction; +begin + RegisterChildNode('Schema', TXMLSchema); + ItemTag := 'Schema'; + ItemInterface := IXMLSchema; + inherited; +end; + +function TXMLSchemas.Get_Schema(Index: Integer): IXMLSchema; +begin + Result := List[Index] as IXMLSchema; +end; + +function TXMLSchemas.Add: IXMLSchema; +begin + Result := AddItem(-1) as IXMLSchema; +end; + +function TXMLSchemas.Insert(const Index: Integer): IXMLSchema; +begin + Result := AddItem(Index) as IXMLSchema; +end; + +{ TXMLSchema } + +procedure TXMLSchema.AfterConstruction; +begin + RegisterChildNode('Items', TXMLItems); + inherited; +end; + +function TXMLSchema.Get_Name: WideString; +begin + Result := ChildNodes['Name'].Text; +end; + +procedure TXMLSchema.Set_Name(Value: WideString); +begin + ChildNodes['Name'].NodeValue := Value; +end; + +function TXMLSchema.Get_Items: IXMLItems; +begin + Result := ChildNodes['Items'] as IXMLItems; +end; + +{ TXMLItems } + +procedure TXMLItems.AfterConstruction; +begin + RegisterChildNode('Item', TXMLItem); + ItemTag := 'Item'; + ItemInterface := IXMLItem; + inherited; +end; + +function TXMLItems.Get_Item(Index: Integer): IXMLItem; +begin + Result := List[Index] as IXMLItem; +end; + +function TXMLItems.Add: IXMLItem; +begin + Result := AddItem(-1) as IXMLItem; +end; + +function TXMLItems.Insert(const Index: Integer): IXMLItem; +begin + Result := AddItem(Index) as IXMLItem; +end; + +{ TXMLItem } + +procedure TXMLItem.AfterConstruction; +begin + RegisterChildNode('Interface', TXMLInterface_); + RegisterChildNode('Collection', TXMLCollection); + RegisterChildNode('Enumeration', TXMLEnumeration); + inherited; +end; + +function TXMLItem.Get_ItemType: WideString; +begin + Result := ChildNodes['ItemType'].Text; +end; + +procedure TXMLItem.Set_ItemType(Value: WideString); +begin + ChildNodes['ItemType'].NodeValue := Value; +end; + +function TXMLItem.Get_Name: WideString; +begin + Result := ChildNodes['Name'].Text; +end; + +procedure TXMLItem.Set_Name(Value: WideString); +begin + ChildNodes['Name'].NodeValue := Value; +end; + +function TXMLItem.Get_Interface_: IXMLInterface_; +begin + Result := ChildNodes['Interface'] as IXMLInterface_; +end; + +function TXMLItem.Get_Collection: IXMLCollection; +begin + Result := ChildNodes['Collection'] as IXMLCollection; +end; + +function TXMLItem.Get_Enumeration: IXMLEnumeration; +begin + Result := ChildNodes['Enumeration'] as IXMLEnumeration; +end; + +{ TXMLInterface_ } + +{ TXMLCollection } + +function TXMLCollection.Get_ItemName: WideString; +begin + Result := ChildNodes['ItemName'].Text; +end; + +procedure TXMLCollection.Set_ItemName(Value: WideString); +begin + ChildNodes['ItemName'].NodeValue := Value; +end; + +{ TXMLEnumeration } + +end. diff --git a/Tests/Source/ObjectMappingTests.pas b/Tests/Source/ObjectMappingTests.pas index 55c3927..5e8079e 100644 --- a/Tests/Source/ObjectMappingTests.pas +++ b/Tests/Source/ObjectMappingTests.pas @@ -2,36 +2,205 @@ unit ObjectMappingTests; interface uses - TestFramework; + TestFramework, + + DataBindingResultXML, + XMLDataBindingGenerator; type + TTestXMLDataBindingGenerator = class(TXMLDataBindingGenerator) + protected + procedure GenerateDataBinding(); override; + end; + + TObjectMappingTests = class(TAbstractTest, ITest) + private + FFileName: String; protected procedure RunTest(testResult: TTestResult); override; + + procedure CompareSchemas(ATestResult: TTestResult; AGenerator: TTestXMLDataBindingGenerator; AResult: IXMLDataBindingResult); + procedure CompareItems(ATestResult: TTestResult; AGeneratorSchema: TXMLDataBindingSchema; AResultSchema: IXMLSchema); + + property FileName: String read FFileName; public - class function Suite: ITestSuite; + constructor Create(const AFileName: String); + + class function Suite(): ITestSuite; end; implementation +uses + Contnrs, + SysUtils, + + X2UtApp; + + +const + ExpectedExtension = '_expected.xml'; + { TObjectMappingTests } -class function TObjectMappingTests.Suite: ITestSuite; +class function TObjectMappingTests.Suite(): ITestSuite; +var + basePath: String; + fileInfo: TSearchRec; + begin Result := TTestSuite.Create(Self.ClassName); - { Add tests for all .xsd files which have a corresponding .expected file } - Result.AddTest(Self.Create('Test')); + { Add tests for all .xsd files which have a corresponding .expected file } + basePath := App.Path + 'Tests\Data\'; + + if FindFirst(basePath + '*.xsd', faAnyFile, fileInfo) = 0 then + begin + repeat + if FileExists(basePath + ChangeFileExt(fileInfo.Name, ExpectedExtension)) then + begin + Result.AddTest(Self.Create(basePath + fileInfo.Name)); + end; + until FindNext(fileInfo) <> 0; + + SysUtils.FindClose(fileInfo); + end; +end; + + +constructor TObjectMappingTests.Create(const AFileName: String); +begin + inherited Create(ChangeFileExt(ExtractFileName(AFileName), '')); + + FFileName := AFileName; end; procedure TObjectMappingTests.RunTest(testResult: TTestResult); +var + generator: TTestXMLDataBindingGenerator; + expectedResult: IXMLDataBindingResult; + begin - testResult.AddFailure(Self, nil, 'Oeps!'); + generator := TTestXMLDataBindingGenerator.Create(); + try + generator.Execute(FileName); + + expectedResult := LoadDataBindingResult(ChangeFileExt(FileName, ExpectedExtension)); + CompareSchemas(testResult, generator, expectedResult); + finally + FreeAndNil(generator); + end; end; +procedure TObjectMappingTests.CompareSchemas(ATestResult: TTestResult; AGenerator: TTestXMLDataBindingGenerator; AResult: IXMLDataBindingResult); +var + handled: TObjectList; + schemaIndex: Integer; + resultSchema: IXMLSchema; + bindingSchema: TXMLDataBindingSchema; + +begin + handled := TObjectList.Create(False); + try + { Iterate expected schemas } + for schemaIndex := 0 to Pred(AResult.Schemas.Count) do + begin + resultSchema := AResult.Schemas[schemaIndex]; + bindingSchema := AGenerator.FindSchema(resultSchema.Name); + + if Assigned(bindingSchema) then + begin + handled.Add(bindingSchema); + CompareItems(ATestResult, bindingSchema, resultSchema); + end else + ATestResult.AddFailure(Self, nil, Format('Schema "%s" expected', [resultSchema.Name])); + end; + + { Find unexpected schemas } + for schemaIndex := 0 to Pred(AGenerator.SchemaCount) do + if handled.IndexOf(AGenerator.Schemas[schemaIndex]) = -1 then + begin + ATestResult.AddFailure(Self, nil, Format('Schema "%s" not expected', [AGenerator.Schemas[schemaIndex].SchemaName])); + end; + finally + FreeAndNil(handled); + end; +end; + + +procedure TObjectMappingTests.CompareItems(ATestResult: TTestResult; AGeneratorSchema: TXMLDataBindingSchema; AResultSchema: IXMLSchema); + + function FindItem(const AName: String): TXMLDataBindingItem; + var + itemIndex: Integer; + + begin + Result := nil; + + for itemIndex := 0 to Pred(AGeneratorSchema.ItemCount) do + if (AGeneratorSchema.Items[itemIndex].Name = AName) and + (AGeneratorSchema.Items[itemIndex].ItemType <> itForward) then + begin + Result := AGeneratorSchema.Items[itemIndex]; + break; + end; + end; + + +var + handled: TObjectList; + itemIndex: Integer; + resultItem: IXMLItem; + bindingItem: TXMLDataBindingItem; + +begin + handled := TObjectList.Create(False); + try + { Iterate expected schemas } + for itemIndex := 0 to Pred(AResultSchema.Items.Count) do + begin + resultItem := AResultSchema.Items[itemIndex]; + bindingItem := FindItem(resultItem.Name); + + if Assigned(bindingItem) then + begin + handled.Add(bindingItem); +// CompareItems(ATestResult, bindingSchema, resultSchema); + end else + ATestResult.AddFailure(Self, nil, Format('Schema "%s": item "%s" expected', + [AGeneratorSchema.SchemaName, resultItem.Name])); + end; + + { Find unexpected schemas } + for itemIndex := 0 to Pred(AGeneratorSchema.ItemCount) do + begin + bindingItem := AGeneratorSchema.Items[itemIndex]; + + if bindingItem.ItemType <> itForward then + begin + if handled.IndexOf(bindingItem) = -1 then + begin + ATestResult.AddFailure(Self, nil, Format('Schema "%s": item "%s" not expected', + [AGeneratorSchema.SchemaName, + AGeneratorSchema.Items[itemIndex].Name])); + end; + end; + end; + finally + FreeAndNil(handled); + end; +end; + + +{ TTestXMLDataBindingGenerator } +procedure TTestXMLDataBindingGenerator.GenerateDataBinding(); +begin +end; + initialization RegisterTest(TObjectMappingTests.Suite); diff --git a/Tests/X2XMLDataBindingTests.bdsproj b/Tests/X2XMLDataBindingTests.bdsproj new file mode 100644 index 0000000..4d54d8e --- /dev/null +++ b/Tests/X2XMLDataBindingTests.bdsproj @@ -0,0 +1,170 @@ + + + + + + + + + + + + X2XMLDataBindingTests.dpr + + + 7.0 + + + 8 + 0 + 0 + 1 + 0 + 0 + 1 + 1 + 1 + 0 + 0 + 1 + 0 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 1 + 2 + 1 + True + True + WinTypes=Windows;WinProcs=Windows;DbiTypes=BDE;DbiProcs=BDE;DbiErrs=BDE; + + False + + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + False + False + False + True + True + True + True + True + True + + + + 3 + 0 + False + 1 + False + False + False + 16384 + 1048576 + 4194304 + + + + ..\ + ..\Lib + + + + vcl;rtl;vclx;inet;xmlrtl;vclie;inetdbbde;inetdbxpress;dbrtl;dsnap;vcldb;dsnapcon;soaprtl;VclSmp;dbexpress;dbxcds;inetdb;bdertl;vcldbx;webdsnap;websnap;adortl;CLXIB;ibxpress;VCLIB;teeui;teedb;tee;dss;vclactnband;vclshlctrls;dclOfficeXP;Indy70;cxLibraryVCLD7;dxBarD7;dxComnD7;dxBarDBNavD7;dxBarExtDBItemsD7;dxBarExtItemsD7;dxDockingD7;dxsbD7;cxEditorsVCLD7;dxThemeD7;cxDataD7;cxExtEditorsVCLD7;cxPageControlVCLD7;cxGridVCLD7;cxSchedulerVCLD7;cxTreeListVCLD7;cxVerticalGridVCLD7;cxSpreadSheetVCLD7;dxNavBarD7;cxWebD7;cxWebPascalScriptD7;cxWebSnapD7;cxWebTeeChartD7;dxMasterViewD7;dxmdsD7;dxdbtrD7;dxtrmdD7;dxorgcD7;dxdborD7;dxFlowChartD7;dxLayoutControlD7;dxLayoutControlcxEditAdaptersD7;dxPSCoreD7;dxPSTeeChartD7;dxPsPrVwAdvD7;dxPSLnksD7;dxPSdxOCLnkD7;dxPSdxMVLnkD7;dxPSdxLCLnkD7;dxPSdxFCLnkD7;dxPSdxDBTVLnkD7;dxPSdxDBOCLnkD7;dxPSDBTeeChartD7;dxPScxCommonD7;dxPScxTLLnkD7;dxPScxSSLnkD7;dxPScxPCProdD7;dxPScxGridLnkD7;dxPScxExtCommonD7;dxPScxVGridLnkD7;fo_d7;xtx_d7;Rave50CLX;Rave50VCL;pngimaged7;dxGDIPlusD7;UnRegDxPNG;unageneral_d7 + + + False + + + + + + False + + + True + False + + + False + False + 0 + 0 + 0 + 0 + False + False + False + False + False + 1043 + 1252 + + + + + 0.0.0.0 + + + + + + + + + + diff --git a/Tests/X2XMLDataBindingTests.cfg b/Tests/X2XMLDataBindingTests.cfg index d636d14..92047fd 100644 --- a/Tests/X2XMLDataBindingTests.cfg +++ b/Tests/X2XMLDataBindingTests.cfg @@ -33,9 +33,9 @@ -$M16384,1048576 -K$00400000 -E"..\" --N"..\Lib" --LE"c:\program files\borland\delphi7\Projects\Bpl" --LN"c:\program files\borland\delphi7\Projects\Bpl" +-N0"..\Lib" +-LE"C:\Documents and Settings\PsychoMark\My Documents\Borland Studio Projects\Bpl" +-LN"C:\Documents and Settings\PsychoMark\My Documents\Borland Studio Projects\Bpl" -w-UNSAFE_TYPE -w-UNSAFE_CODE -w-UNSAFE_CAST diff --git a/Tests/X2XMLDataBindingTests.dpr b/Tests/X2XMLDataBindingTests.dpr index 943065c..6484079 100644 --- a/Tests/X2XMLDataBindingTests.dpr +++ b/Tests/X2XMLDataBindingTests.dpr @@ -1,10 +1,15 @@ program X2XMLDataBindingTests; uses + ActiveX, GUITestRunner, - ObjectMappingTests in 'Source\ObjectMappingTests.pas'; + ObjectMappingTests in 'Source\ObjectMappingTests.pas', + DataBindingResultXML in 'Source\DataBindingResultXML.pas', + XMLDataBindingGenerator in '..\Units\XMLDataBindingGenerator.pas', + XMLDataBindingHelpers in '..\Units\XMLDataBindingHelpers.pas'; begin + CoInitialize(nil); RunRegisteredTests; end. diff --git a/Tests/X2XMLDataBindingTests.mes b/Tests/X2XMLDataBindingTests.mes new file mode 100644 index 0000000..3a6b06e --- /dev/null +++ b/Tests/X2XMLDataBindingTests.mes @@ -0,0 +1,144 @@ +[GeneralSettings] +HandleExceptions=0 +AppendMapFileToBinary=1 +NoOwnMadExceptSettings=0 +CheckFileCrc=1 +CheckForFrozenMainThread=0 +FreezeTimeout=60000 +AutomaticallySaveBugReport=0 +AutoSaveBugReportIfNotSent=1 +AutomaticallyMailBugReport=0 +AutoMailProgressBox=0 +CopyBugReportToClipboard=0 +SuspendAllRunningThreads=0 +ShowPleaseWaitBox=1 +PleaseWaitIcon=plwait1 +AutomaticallyContinueApplication=0 +AutomaticallyRestartApplication=0 +AutomaticallyCloseApplication=0 +MailAddress= +SendInBackground=1 +Send32Icon=send321 +MailAsSmtpServer=0 +MailAsSmtpClient=0 +UploadViaHttp=0 +MailViaMapi=1 +MailViaMailto=1 +SmtpServer= +SmtpPort=25 +SmtpAccount= +SmtpPassword= +HttpServer= +HttpPort=80 +HttpAccount= +HttpPassword= +BugReportFile=bugreport.txt +AttachBugReport=0 +AttachBugReportFile=1 +DeleteBugReportFile=1 +BugReportSendAs=bugreport.txt +BugReportZip= +ScreenShotDepth=0 +ScreenShotAppOnly=0 +ScreenShotSendAs=screenshot.png +ScreenShotZip= +AdditionalAttachments= +AppendBugReports=1 +BugReportFileSize=100000 +DontSaveDuplicateExceptions=1 +DontSaveDuplicateFreezings=1 +DuplicateExceptionDefinition=1 +DuplicateFreezeDefinition=2 +ShowExceptionBox=1 +OkBtnText=&OK +DetailsBtnText=&Details +PleaseWaitTitle=Information +PleaseWaitText=Please wait a moment... +MailSubject=bug report +MailBody=please find the bug report attached +SendBoxTitle=Sending bug report... +PrepareAttachMsg=Preparing attachments... +MxLookupMsg=Searching for mail server... +ConnectMsg=Connecting to server... +AuthMsg=Authentication... +SendMailMsg=Sending mail... +FieldsMsg=Setting fields... +SendAttachMsg=Sending attachments... +SendFinalizeMsg=Finalizing... +MailFailureMsg=Sorry, sending the bug report didn't work. +VersionVariable= +[ExceptionBox] +ShowButtonMailBugReport=1 +ShowButtonSaveBugReport=0 +ShowButtonPrintBugReport=0 +ShowButtonShowBugReport=1 +ShowButtonContinueApplication=1 +ShowButtonRestartApplication=1 +ShowButtonCloseApplication=1 +IconButtonSendBugReport=send1 +IconButtonSaveBugReport=save1 +IconButtonPrintBugReport=print1 +IconButtonShowBugReport=show1 +IconButtonContinueApplication=continue1 +IconButtonCantContinueApplication=cantContinue1 +IconButtonRestartApplication=restart1 +IconButtonCloseApplication=close1 +FocusedButton=0 +SendAssistant=SendAssistant +SaveAssistant=SaveAssistant +PrintAssistant=PrintAssistant +AutomaticallyShowBugReport=0 +NoOwnerDrawButtons=0 +BigExceptionIcon=big1 +TitleBar=%25appname%25 +ExceptionMessage=An error occurred in the application. +FrozenMessage=The application seems to be frozen. +BitFaultMsg=The file "%25modname%25" seems to be corrupt! +MailBugReportText=send bug report +SaveBugReportText=save bug report +PrintBugReportText=print bug report +ShowBugReportText=show bug report +ContinueApplicationText=continue application +RestartApplicationText=restart application +CloseApplicationText=close application +[BugReport] +ListThreads=1 +ListModules=1 +ListHardware=1 +ShowCpuRegisters=1 +ShowStackDump=1 +Disassembly=1 +HideUglyItems=0 +ShowRelativeAddrs=1 +ShowRelativeLines=1 +FormatDisassembly=0 +LimitDisassembly=5 +EnabledPlugins=modules|processes|hardware +[Filters] +Filter1ExceptionClasses=EDBEditError +Filter1DontCreateBugReport=1 +Filter1DontCreateScreenshot=1 +Filter1DontSuspendThreads=1 +Filter1DontCallHandlers=1 +Filter1ShowBox=3 +Filter1Assis= +Filter2ExceptionClasses= +Filter2DontCreateBugReport=0 +Filter2DontCreateScreenshot=0 +Filter2DontSuspendThreads=0 +Filter2DontCallHandlers=0 +Filter2ShowBox=0 +Filter2Assis= +GeneralDontCreateBugReport=0 +GeneralDontCreateScreenshot=0 +GeneralDontSuspendThreads=0 +GeneralDontCallHandlers=0 +GeneralShowBox=0 +GeneralAssis= +[Assistants] +Assistant1=SendAssistant|Send Assistant|ContactForm|DetailsForm|ScrShotForm +Assistant2=SaveAssistant|Save Assistant|ContactForm|DetailsForm +Assistant3=PrintAssistant|Print Assistant|ContactForm|DetailsForm +Forms1=TPF0%0eTMEContactForm%0bContactForm%07Message%0c%13%00%00%00Contact Information%08MinWidth%04%00%00%00%00%08OnAction%0c%1b%00%00%00madExcept.HandleContactForm%05Timer%04%00%00%00%00%00%09INVButton%0bContinueBtn%07Caption%0c%08%00%00%00Continue%07Enabled%09%0bNoOwnerDraw%08%07Visible%09%00%00%09INVButton%07SkipBtn%07Caption%0c%04%00%00%00Skip%07Enabled%08%0bNoOwnerDraw%08%07Visible%09%00%00%09INVButton%09CancelBtn%07Caption%0c%06%00%00%00Cancel%07Enabled%09%0bNoOwnerDraw%08%07Visible%09%00%00%08INVLabel%06Label1%07Caption%0c%0a%00%00%00your name:%07Enabled%09%07Spacing%04%00%00%00%00%00%00%07INVEdit%08NameEdit%07Colored%09%07Enabled%09%05Lines%04%01%00%00%00%08Optional%09%0aOutputName%0c%0c%00%00%00contact name%0aOutputType%07%09nvoHeader%07Spacing%04%00%00%00%00%04Text%0c%00%00%00%00%05Valid%09%00%00%08INVLabel%06Label2%07Caption%0c%0b%00%00%00your email:%07Enabled%09%07Spacing%04%00%00%00%00%00%00%07INVEdit%09EmailEdit%07Colored%09%07Enabled%09%05Lines%04%01%00%00%00%08Optional%08%0aOutputName%0c%0d%00%00%00contact email%0aOutputType%07%09nvoHeader%07Spacing%04%00%00%00%00%04Text%0c%00%00%00%00%05Valid%09%00%00%0bINVCheckBox%08MemCheck%07Caption%0c%0b%00%00%00remember me%07Checked%08%07Enabled%09%0aOutputName%0c%00%00%00%00%07Spacing%04%00%00%00%00%00%00%00 +Forms2=TPF0%0eTMEDetailsForm%0bDetailsForm%07Message%0c%0d%00%00%00Error Details%08MinWidth%04%00%00%00%00%08OnAction%0c%00%00%00%00%05Timer%04%00%00%00%00%00%09INVButton%0bContinueBtn%07Caption%0c%08%00%00%00Continue%07Enabled%09%0bNoOwnerDraw%08%07Visible%09%00%00%09INVButton%07SkipBtn%07Caption%0c%04%00%00%00Skip%07Enabled%09%0bNoOwnerDraw%08%07Visible%09%00%00%09INVButton%09CancelBtn%07Caption%0c%06%00%00%00Cancel%07Enabled%09%0bNoOwnerDraw%08%07Visible%09%00%00%08INVLabel%06Label1%07Caption%0c'%00%00%00in which situation did the error occur?%07Enabled%09%07Spacing%04%00%00%00%00%00%00%07INVEdit%0bDetailsMemo%07Colored%09%07Enabled%09%05Lines%04%09%00%00%00%08Optional%08%0aOutputName%0c%0d%00%00%00error details%0aOutputType%07%0dnvoOwnSection%07Spacing%04%00%00%00%00%04Text%0c%00%00%00%00%05Valid%09%00%00%00 +Forms3=TPF0%0eTMEScrShotForm%0bScrShotForm%0dActiveControl%07%0bContinueBtn%07Message%0c%18%00%00%00Screenshot Configuration%08MinWidth%04%00%00%00%00%08OnAction%0c%1e%00%00%00madExcept.HandleScreenshotForm%05Timer%04%fa%00%00%00%00%09INVButton%0bContinueBtn%07Caption%0c%08%00%00%00Continue%07Enabled%09%0bNoOwnerDraw%08%07Visible%09%00%00%09INVButton%07SkipBtn%07Caption%0c%04%00%00%00Skip%07Enabled%08%0bNoOwnerDraw%08%07Visible%09%00%00%09INVButton%09CancelBtn%07Caption%0c%06%00%00%00Cancel%07Enabled%09%0bNoOwnerDraw%08%07Visible%09%00%00%0bINVCheckBox%0bAttachCheck%07Caption%0c%25%00%00%00attach a screenshot to the bug report%07Checked%09%07Enabled%09%0aOutputName%0c%00%00%00%00%07Spacing%04%00%00%00%00%00%00%08INVImage%0aScrShotImg%06Border%09%09Clickable%09%07Enabled%09%04File%0c%00%00%00%00%06Height%04%00%00%00%00%07Spacing%04%00%00%00%00%05Width%04%00%00%00%00%00%00%08INVLabel%06Label1%07Caption%0c%15%00%00%00(click to edit image)%07Enabled%09%07Spacing%04%00%00%00%00%00%00%00 diff --git a/Tests/XSD/DataBindingResult.xsd b/Tests/XSD/DataBindingResult.xsd new file mode 100644 index 0000000..dc06875 --- /dev/null +++ b/Tests/XSD/DataBindingResult.xsd @@ -0,0 +1,76 @@ + + + + + + Defines the expected intermediate result of a Data Binding + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Units/DelphiXMLDataBindingGenerator.pas b/Units/DelphiXMLDataBindingGenerator.pas index 21425e4..dc6121a 100644 --- a/Units/DelphiXMLDataBindingGenerator.pas +++ b/Units/DelphiXMLDataBindingGenerator.pas @@ -442,7 +442,7 @@ begin 'Load%0:sFromStream(AStream: TStream)', ' doc := NewXMLDocument;'#13#10 + ' doc.LoadFromStream(AStream);'#13#10 + - ' Result := GetOfferte(doc);', + ' Result := Get%0:s(doc);', ' doc: IXMLDocument;'); WriteFunction(interfaceItem.TranslatedName, @@ -687,6 +687,7 @@ begin itemProperty := AItem.Properties[propertyIndex]; dataTypeName := ''; writeTextProp := False; + writeOptional := True; { Get data type } case itemProperty.PropertyType of @@ -704,6 +705,10 @@ begin end else dataTypeName := PrefixInterface; + { Collections have a Count property, no need to write a + HasX property as well. } + writeOptional := (propertyItem.ItemType <> itCollection); + dataTypeName := dataTypeName + propertyItem.TranslatedName; end; end; @@ -712,8 +717,9 @@ begin if Length(dataTypeName) > 0 then begin - writeOptional := itemProperty.IsOptional and - (member in [dxmPropertyGet, dxmPropertyDeclaration]); + if writeOptional then + writeOptional := itemProperty.IsOptional and + (member in [dxmPropertyGet, dxmPropertyDeclaration]); case ASection of dxsInterface, diff --git a/X2XMLDataBinding.bdsproj b/X2XMLDataBinding.bdsproj index 0ec6262..f8e576c 100644 --- a/X2XMLDataBinding.bdsproj +++ b/X2XMLDataBinding.bdsproj @@ -125,7 +125,7 @@ - madExcept + False diff --git a/X2XMLDataBinding.cfg b/X2XMLDataBinding.cfg index 957a33c..2125801 100644 --- a/X2XMLDataBinding.cfg +++ b/X2XMLDataBinding.cfg @@ -34,7 +34,6 @@ -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" --DmadExcept -w-UNSAFE_TYPE -w-UNSAFE_CODE -w-UNSAFE_CAST diff --git a/X2XMLDataBinding.dpr b/X2XMLDataBinding.dpr index 6ddf861..9dcd426 100644 --- a/X2XMLDataBinding.dpr +++ b/X2XMLDataBinding.dpr @@ -3,11 +3,6 @@ program X2XMLDataBinding; {$WARN SYMBOL_PLATFORM OFF} uses - madExcept, - madLinkDisAsm, - madListHardware, - madListProcesses, - madListModules, Forms, MainFrm in 'Forms\MainFrm.pas' {MainForm}, XMLDataBindingGenerator in 'Units\XMLDataBindingGenerator.pas', diff --git a/X2XMLDataBinding.mes b/X2XMLDataBinding.mes new file mode 100644 index 0000000..3a6b06e --- /dev/null +++ b/X2XMLDataBinding.mes @@ -0,0 +1,144 @@ +[GeneralSettings] +HandleExceptions=0 +AppendMapFileToBinary=1 +NoOwnMadExceptSettings=0 +CheckFileCrc=1 +CheckForFrozenMainThread=0 +FreezeTimeout=60000 +AutomaticallySaveBugReport=0 +AutoSaveBugReportIfNotSent=1 +AutomaticallyMailBugReport=0 +AutoMailProgressBox=0 +CopyBugReportToClipboard=0 +SuspendAllRunningThreads=0 +ShowPleaseWaitBox=1 +PleaseWaitIcon=plwait1 +AutomaticallyContinueApplication=0 +AutomaticallyRestartApplication=0 +AutomaticallyCloseApplication=0 +MailAddress= +SendInBackground=1 +Send32Icon=send321 +MailAsSmtpServer=0 +MailAsSmtpClient=0 +UploadViaHttp=0 +MailViaMapi=1 +MailViaMailto=1 +SmtpServer= +SmtpPort=25 +SmtpAccount= +SmtpPassword= +HttpServer= +HttpPort=80 +HttpAccount= +HttpPassword= +BugReportFile=bugreport.txt +AttachBugReport=0 +AttachBugReportFile=1 +DeleteBugReportFile=1 +BugReportSendAs=bugreport.txt +BugReportZip= +ScreenShotDepth=0 +ScreenShotAppOnly=0 +ScreenShotSendAs=screenshot.png +ScreenShotZip= +AdditionalAttachments= +AppendBugReports=1 +BugReportFileSize=100000 +DontSaveDuplicateExceptions=1 +DontSaveDuplicateFreezings=1 +DuplicateExceptionDefinition=1 +DuplicateFreezeDefinition=2 +ShowExceptionBox=1 +OkBtnText=&OK +DetailsBtnText=&Details +PleaseWaitTitle=Information +PleaseWaitText=Please wait a moment... +MailSubject=bug report +MailBody=please find the bug report attached +SendBoxTitle=Sending bug report... +PrepareAttachMsg=Preparing attachments... +MxLookupMsg=Searching for mail server... +ConnectMsg=Connecting to server... +AuthMsg=Authentication... +SendMailMsg=Sending mail... +FieldsMsg=Setting fields... +SendAttachMsg=Sending attachments... +SendFinalizeMsg=Finalizing... +MailFailureMsg=Sorry, sending the bug report didn't work. +VersionVariable= +[ExceptionBox] +ShowButtonMailBugReport=1 +ShowButtonSaveBugReport=0 +ShowButtonPrintBugReport=0 +ShowButtonShowBugReport=1 +ShowButtonContinueApplication=1 +ShowButtonRestartApplication=1 +ShowButtonCloseApplication=1 +IconButtonSendBugReport=send1 +IconButtonSaveBugReport=save1 +IconButtonPrintBugReport=print1 +IconButtonShowBugReport=show1 +IconButtonContinueApplication=continue1 +IconButtonCantContinueApplication=cantContinue1 +IconButtonRestartApplication=restart1 +IconButtonCloseApplication=close1 +FocusedButton=0 +SendAssistant=SendAssistant +SaveAssistant=SaveAssistant +PrintAssistant=PrintAssistant +AutomaticallyShowBugReport=0 +NoOwnerDrawButtons=0 +BigExceptionIcon=big1 +TitleBar=%25appname%25 +ExceptionMessage=An error occurred in the application. +FrozenMessage=The application seems to be frozen. +BitFaultMsg=The file "%25modname%25" seems to be corrupt! +MailBugReportText=send bug report +SaveBugReportText=save bug report +PrintBugReportText=print bug report +ShowBugReportText=show bug report +ContinueApplicationText=continue application +RestartApplicationText=restart application +CloseApplicationText=close application +[BugReport] +ListThreads=1 +ListModules=1 +ListHardware=1 +ShowCpuRegisters=1 +ShowStackDump=1 +Disassembly=1 +HideUglyItems=0 +ShowRelativeAddrs=1 +ShowRelativeLines=1 +FormatDisassembly=0 +LimitDisassembly=5 +EnabledPlugins=modules|processes|hardware +[Filters] +Filter1ExceptionClasses=EDBEditError +Filter1DontCreateBugReport=1 +Filter1DontCreateScreenshot=1 +Filter1DontSuspendThreads=1 +Filter1DontCallHandlers=1 +Filter1ShowBox=3 +Filter1Assis= +Filter2ExceptionClasses= +Filter2DontCreateBugReport=0 +Filter2DontCreateScreenshot=0 +Filter2DontSuspendThreads=0 +Filter2DontCallHandlers=0 +Filter2ShowBox=0 +Filter2Assis= +GeneralDontCreateBugReport=0 +GeneralDontCreateScreenshot=0 +GeneralDontSuspendThreads=0 +GeneralDontCallHandlers=0 +GeneralShowBox=0 +GeneralAssis= +[Assistants] +Assistant1=SendAssistant|Send Assistant|ContactForm|DetailsForm|ScrShotForm +Assistant2=SaveAssistant|Save Assistant|ContactForm|DetailsForm +Assistant3=PrintAssistant|Print Assistant|ContactForm|DetailsForm +Forms1=TPF0%0eTMEContactForm%0bContactForm%07Message%0c%13%00%00%00Contact Information%08MinWidth%04%00%00%00%00%08OnAction%0c%1b%00%00%00madExcept.HandleContactForm%05Timer%04%00%00%00%00%00%09INVButton%0bContinueBtn%07Caption%0c%08%00%00%00Continue%07Enabled%09%0bNoOwnerDraw%08%07Visible%09%00%00%09INVButton%07SkipBtn%07Caption%0c%04%00%00%00Skip%07Enabled%08%0bNoOwnerDraw%08%07Visible%09%00%00%09INVButton%09CancelBtn%07Caption%0c%06%00%00%00Cancel%07Enabled%09%0bNoOwnerDraw%08%07Visible%09%00%00%08INVLabel%06Label1%07Caption%0c%0a%00%00%00your name:%07Enabled%09%07Spacing%04%00%00%00%00%00%00%07INVEdit%08NameEdit%07Colored%09%07Enabled%09%05Lines%04%01%00%00%00%08Optional%09%0aOutputName%0c%0c%00%00%00contact name%0aOutputType%07%09nvoHeader%07Spacing%04%00%00%00%00%04Text%0c%00%00%00%00%05Valid%09%00%00%08INVLabel%06Label2%07Caption%0c%0b%00%00%00your email:%07Enabled%09%07Spacing%04%00%00%00%00%00%00%07INVEdit%09EmailEdit%07Colored%09%07Enabled%09%05Lines%04%01%00%00%00%08Optional%08%0aOutputName%0c%0d%00%00%00contact email%0aOutputType%07%09nvoHeader%07Spacing%04%00%00%00%00%04Text%0c%00%00%00%00%05Valid%09%00%00%0bINVCheckBox%08MemCheck%07Caption%0c%0b%00%00%00remember me%07Checked%08%07Enabled%09%0aOutputName%0c%00%00%00%00%07Spacing%04%00%00%00%00%00%00%00 +Forms2=TPF0%0eTMEDetailsForm%0bDetailsForm%07Message%0c%0d%00%00%00Error Details%08MinWidth%04%00%00%00%00%08OnAction%0c%00%00%00%00%05Timer%04%00%00%00%00%00%09INVButton%0bContinueBtn%07Caption%0c%08%00%00%00Continue%07Enabled%09%0bNoOwnerDraw%08%07Visible%09%00%00%09INVButton%07SkipBtn%07Caption%0c%04%00%00%00Skip%07Enabled%09%0bNoOwnerDraw%08%07Visible%09%00%00%09INVButton%09CancelBtn%07Caption%0c%06%00%00%00Cancel%07Enabled%09%0bNoOwnerDraw%08%07Visible%09%00%00%08INVLabel%06Label1%07Caption%0c'%00%00%00in which situation did the error occur?%07Enabled%09%07Spacing%04%00%00%00%00%00%00%07INVEdit%0bDetailsMemo%07Colored%09%07Enabled%09%05Lines%04%09%00%00%00%08Optional%08%0aOutputName%0c%0d%00%00%00error details%0aOutputType%07%0dnvoOwnSection%07Spacing%04%00%00%00%00%04Text%0c%00%00%00%00%05Valid%09%00%00%00 +Forms3=TPF0%0eTMEScrShotForm%0bScrShotForm%0dActiveControl%07%0bContinueBtn%07Message%0c%18%00%00%00Screenshot Configuration%08MinWidth%04%00%00%00%00%08OnAction%0c%1e%00%00%00madExcept.HandleScreenshotForm%05Timer%04%fa%00%00%00%00%09INVButton%0bContinueBtn%07Caption%0c%08%00%00%00Continue%07Enabled%09%0bNoOwnerDraw%08%07Visible%09%00%00%09INVButton%07SkipBtn%07Caption%0c%04%00%00%00Skip%07Enabled%08%0bNoOwnerDraw%08%07Visible%09%00%00%09INVButton%09CancelBtn%07Caption%0c%06%00%00%00Cancel%07Enabled%09%0bNoOwnerDraw%08%07Visible%09%00%00%0bINVCheckBox%0bAttachCheck%07Caption%0c%25%00%00%00attach a screenshot to the bug report%07Checked%09%07Enabled%09%0aOutputName%0c%00%00%00%00%07Spacing%04%00%00%00%00%00%00%08INVImage%0aScrShotImg%06Border%09%09Clickable%09%07Enabled%09%04File%0c%00%00%00%00%06Height%04%00%00%00%00%07Spacing%04%00%00%00%00%05Width%04%00%00%00%00%00%00%08INVLabel%06Label1%07Caption%0c%15%00%00%00(click to edit image)%07Enabled%09%07Spacing%04%00%00%00%00%00%00%00