Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.clipper.visual-objects > #13057 > unrolled thread

IVarList sort in natural order / as per class definition

Started byRobert Pope <cooeee@gmail.com>
First post2020-09-04 06:30 -0700
Last post2020-09-07 04:18 -0700
Articles 6 — 3 participants

Back to article view | Back to comp.lang.clipper.visual-objects


Contents

  IVarList sort in natural order / as per class definition Robert Pope <cooeee@gmail.com> - 2020-09-04 06:30 -0700
    Re: IVarList sort in natural order / as per class definition "Wolfgang Riedmann" <wriedmann@gmail.com> - 2020-09-05 09:53 +0200
    Re: IVarList sort in natural order / as per class definition Jafar <jafar@marti-orbak.nl> - 2020-09-07 01:59 -0700
      Re: IVarList sort in natural order / as per class definition Robert Pope <cooeee@gmail.com> - 2020-09-07 02:58 -0700
        Re: IVarList sort in natural order / as per class definition Jafar <jafar@marti-orbak.nl> - 2020-09-07 03:25 -0700
          Re: IVarList sort in natural order / as per class definition Robert Pope <cooeee@gmail.com> - 2020-09-07 04:18 -0700

#13057 — IVarList sort in natural order / as per class definition

FromRobert Pope <cooeee@gmail.com>
Date2020-09-04 06:30 -0700
SubjectIVarList sort in natural order / as per class definition
Message-ID<40414534-8edf-4756-82eb-f35545c4cb60o@googlegroups.com>
Does anyone know if there is a way to get IVarList() (or another similar function) to return its array output in the same order as they were defined in the class? For example, if I have:

CLASS MyClass

  EXPORT MyVar1 AS STRING
  EXPORT MyVar2 AS STRING
  EXPORT MyVar3 AS STRING
  EXPORT MyVar10 AS STRING
  EXPORT MyVar4 AS STRING

Then I would like IVarList to return {#MyVar1, #MyVar2, #MyVar3, #MyVar10, #MyVar4}.

IVarList seems to be a bit random with its sorting. For example I might get {#MyVar2, #MyVar1, #MyVar3, #MyVar10, #MyVar4} as its output. That random order seems to be maintained until the next compile, where it might shuffle again slightly.

The object I am actually trying to encode has about 20 exports (some of them are references to other objects / arrays).

Bonus points if you can get the elements in their original case too. IVarList returns an array of symbols, so my mixed case names are being lost too.

Cheers!

[toc] | [next] | [standalone]


#13065

From"Wolfgang Riedmann" <wriedmann@gmail.com>
Date2020-09-05 09:53 +0200
Message-ID<hrguflFu13vU1@mid.individual.net>
In reply to#13057
Hi Robert,

you can't either. If you need the same order every time you need to
sort it yourself.
And compile time symbols are case independent - so no chance to get
back the original case from symbols.

Wolfgang

Robert Pope wrote:

> Does anyone know if there is a way to get IVarList() (or another
> similar function) to return its array output in the same order as
> they were defined in the class? For example, if I have:
> 
> CLASS MyClass
> 
>   EXPORT MyVar1 AS STRING
>   EXPORT MyVar2 AS STRING
>   EXPORT MyVar3 AS STRING
>   EXPORT MyVar10 AS STRING
>   EXPORT MyVar4 AS STRING
> 
> Then I would like IVarList to return {#MyVar1, #MyVar2, #MyVar3,
> #MyVar10, #MyVar4}.
> 
> IVarList seems to be a bit random with its sorting. For example I
> might get {#MyVar2, #MyVar1, #MyVar3, #MyVar10, #MyVar4} as its
> output. That random order seems to be maintained until the next
> compile, where it might shuffle again slightly.
> 
> The object I am actually trying to encode has about 20 exports (some
> of them are references to other objects / arrays).
> 
> Bonus points if you can get the elements in their original case too.
> IVarList returns an array of symbols, so my mixed case names are
> being lost too.
> 
> Cheers!



-- 

[toc] | [prev] | [next] | [standalone]


#13066

FromJafar <jafar@marti-orbak.nl>
Date2020-09-07 01:59 -0700
Message-ID<fcdd5fd5-8629-4316-bba1-4f4b1e1ab38en@googlegroups.com>
In reply to#13057
"The object I am actually trying to encode has about 20 exports (some of them are references to other objects / arrays). "

Why not just sort the variables in alphabetical order?
Wouldn't that also do away with the random order?

[toc] | [prev] | [next] | [standalone]


#13067

FromRobert Pope <cooeee@gmail.com>
Date2020-09-07 02:58 -0700
Message-ID<1f1b766d-467d-40a1-ac14-4b67ee580262o@googlegroups.com>
In reply to#13066
On Monday, September 7, 2020 at 6:59:09 PM UTC+10, Jafar wrote:
> "The object I am actually trying to encode has about 20 exports (some of them are references to other objects / arrays). "
> 
> Why not just sort the variables in alphabetical order?
> Wouldn't that also do away with the random order?

That is actually what I had, in the absence of having them in the order that I wanted them in.

I'm trying to generate XML where the elements need to follow a specific sequence as defined by an XSD. I was trying to use that same sequence on my class, but ran into the issues described in this thread.

What I did today was to define an array of symbols that lists out the fields in the order I need. I then use that to perform the IVarGet()'s in the correct order. It isn't the most elegant solution (it would have been nice if I only had to define the fields once), but it works.

[toc] | [prev] | [next] | [standalone]


#13068

FromJafar <jafar@marti-orbak.nl>
Date2020-09-07 03:25 -0700
Message-ID<2275ebd3-adcb-4076-b16d-b7fe7596544en@googlegroups.com>
In reply to#13067
"where the elements need to follow a specific sequence as defined by an XSD"

Wouldn't it then make more sense to extract the variable names from the XSD instead?
I don't have example code for this, but I think that would give a more reliable result since you can extract the exact order & variable names required by your XSD regardless of any future changes.

[toc] | [prev] | [next] | [standalone]


#13069

FromRobert Pope <cooeee@gmail.com>
Date2020-09-07 04:18 -0700
Message-ID<66444dc7-a871-4fa3-9b08-9eff170f90e4o@googlegroups.com>
In reply to#13068
On Monday, September 7, 2020 at 8:25:45 PM UTC+10, Jafar wrote:
> Wouldn't it then make more sense to extract the variable names from the XSD instead?

That seems like a nice and clean solution, actually.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.clipper.visual-objects


csiph-web