Tagged: XMLMarshal
- This topic has 4 replies, 2 voices, and was last updated 5 years, 2 months ago by
kimbomadsen.
-
AuthorPosts
-
-
October 2, 2020 at 11:08 #55113
VadimMest
ParticipantHello
TkbmMWXMLMarshal doesn’t process all properties in object based on class(TObjectList<TItem>)
I need to create xml file with additional property Total for node with “sequence” Item
<?xml version=”1.0″ encoding=”utf-8″ ?>
<Items>
<Item>
<Quantity>10</Quantity>
<Price>10</Price>
</Item>
<Item>
<Quantity>20</Quantity>
<Price>20</Price>
</Item><Total>
<TotalWithVat>500</TotalWithVat>
<Vat>100</<Vat>
</Total></Items>
But TkbmMWXMLMarshal skips property Total.
How do I need to describe class TItems for full xml?
All code:
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, kbmMWDateTime, kbmMWXML,
kbmMWXMLMarshal,
kbmMWObjectMarshal, kbmMWRTTI, kbmMWNullable, Generics.Collections;type
TTotal = class
private
FTotalWithVat: currency;
FVat: currency;
public
property TotalWithVat: currency read FTotalWithVat write FTotalWithVat;
property Vat: currency read FVat write FVat;
end;TItem = class
private
FQuantity: currency;
FPrice: currency;
public
property Quantity: currency read FQuantity write FQuantity;
property Price: currency read FPrice write FPrice;
end;[kbmMW_Root(‘Items’, [])]
[kbmMW_Child(‘Item’)]TItems = class(TObjectList<TItem>)
private
FTotal: TTotal;
public
constructor Create; virtual;
destructor Destroy; override;// [kbmMW_Element]
property Total: TTotal read FTotal write FTotal;
end;TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation
{$R *.dfm}
{ TTableItems }constructor TItems.Create;
begin
Inherited Create;
FTotal := TTotal.Create;
end;destructor TItems.Destroy;
begin
FreeAndNil(FTotal);
inherited;
end;procedure TForm1.FormCreate(Sender: TObject);
var
Items: TItems;
Item: TItem;
xml: TkbmMWDOMXML;
mx: TkbmMWXMLMarshal;
begin
kbmMWRegisterKnownClasses([TTableItems, TItem]);Items := TItems.Create;
Item := TItem.Create;
Item.Quantity := 10;
Item.Price := 10;
Items.Add(Item);
Item := TItem.Create;
Item.Quantity := 20;
Item.Price := 20;
Items.Add(Item);Items.Total.TotalWithVat:= 500;
Items.Total.Vat := 100;mx := TkbmMWXMLMarshal.Create;
mx.Typed := False;
ShowMessage(mx.AsString(Items));
mx.Free;Items.Free;
end;end.
-
October 5, 2020 at 22:27 #55129
kimbomadsen
KeymasterHi,
kbmMW do not support that in the current source, however the fix is easy.
Open kbmMWObjectMarshal.pas
Locate the line
if mrt=mwrmrtObject then
at line (approx.) 1078 and 1349 and change it to:
if true then
In the kbmMW source the code covered by that condition will be moved after the next code block, to ensure the local properties/fields are listed _after_ the sequenced elements. Doing the above fix only will result in the Total line appearing before the sequenced elements.
Please report back your result so I can include the change in the next release.
-
October 8, 2020 at 09:28 #55153
-
October 12, 2020 at 07:04 #55167
VadimMest
ParticipantDear Kim
This changing breaks down function Unmarshal for some JSON
-
October 15, 2020 at 13:24 #55173
kimbomadsen
KeymasterHi,
Can you please paste a sample that breaks with the change?
best regards
Kim/C4D
-
-
-
AuthorPosts
- You must be logged in to reply to this topic.
