You are not logged in.
Pages: 1
Ah, the wrapper makes sense. It would be useful to add this info to the documentation on this page: http://synopse.info/files/html/Synopse% … ml#TITL_80
The examples are very good, but finding out how to add data as Pairs, Objects and Arrays (both variants and strings added to existing variants) took much reading and trying (tiiime) for a newbie.
I've added the TDocVariantData.SortByName method.
Would something similar be possible also for TDocVariant? (All my existing code uses TDocVariant). I'm a bit lost on these variants still.
Btw, it seems like the "Exchg" procedure was redeclared (patching only this "SortByName", "Compare" & "Exchg" won't compile).
// Rolf Lampa
I've added the TDocVariantData.SortByName method.
See http://synopse.info/fossil/info/b38f4de17dYour v2 is not a valid JSON content. I suppose there are some [ ] missing to make it a JSON array.
Thank you very much for the SortByName!
And yes, the brackets were missing:
v2 := _Json( '[{ "B":"Bee"},{"C":"Sii"},{"A":"Ei"}]' );
I actually collect my lists (via RTTI) one by one, returning them as string, and then add them as JSON arrays to the owning object, like so:
vMain, vTV: Variant;
begin
// Retrieving RTTI Context etc.
...
// Add an empty Array
vMain.Add('TaggedValues', _Arr([]));
props := c.GetIndexedProperty('TaggedValues');
Cnt := c.GetProperty('TaggedValuesCount').GetValue(aInstance).AsInteger;
for i := 0 to Cnt - 1 do
begin
Obj := props.GetValue(aInstance, [i]).AsObject;
vTV := _Json( GetTaggedValuesAsJsonStr(Obj) ); // '[{"name":"val"},{...}]'
//
// vTV.SortArray; // <-- Sort before nesting the list into vMain
//
vMain._('TaggedValues').Add( vTV );
end;
By producing consistent locations of objects I will be able to track any changes in model info (using diff), and for this reason I happily "take the pain" to handle each list/array individually in order to be able to sort them.
// Rolf Lampa
I'm using JSON format for exporting / importing UML model info (from EA) and for file-diff purposes I'd like to be able to sort JSON pairs and arrays (I can then test-compare Export.txt with Import.txt, for example).
But I'm not experienced with the SynCommon.pas unit and have a problem finding out how to sort the two examples below :
v, v2: Variant;
begin
TDocVariant.New(v);
TDocVariant.New(v2);
v := _Json( '{ "B":"Bee","C":"Sii","A":"Ei" }' );
// How do I sort v in order to get
// '{ "A":"Ei","B":"Bee","C":"Sii" }' ?
v2 := _Json( '{ "B":"Bee"},{"C":"Sii"},{"A":"Ei"}' );
// How do I sort v2 in order to get :
// '{"A":"Ei"},{"B":"Bee"},{"C":"Sii"}' ?
I have tried dirty hacks like copying the content to TStrings, but I keep loosing data (and with big models such hacks will not perform).
What would be the fastest and simplest way to sort by name, ascending?
// Rolf Lampa
Pages: 1