Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to iterate through a global structure properties

358 views
Skip to first unread message

Stéphane

unread,
Nov 26, 2007, 12:06:43 PM11/26/07
to
Hi,

is there any way to iterate through the properties of a
global user-defined structure and get their name, datatype
and value, like you would do in an array ?

For instance, I have the following structure:

global type str_employee from structure
double id
string firstname
string lastname
...
end type

I'd like to iterate from 1 to
<number_of_properties_of_str_employee> and store "id",
"double" and the value for id in local variables, and so on.

I didn't find any way to do that but a structure is close to
an array in a sense so maybe I'm missing something trivial.

Any help appriciated. Thanks.
Stéphane.

Arthur Hefti

unread,
Nov 26, 2007, 12:59:11 PM11/26/07
to
Check out the classdefinition object. I wrote an article in PBDJ. You
can find details on our website at
http://www.catsoft.ch/en/asp/page.aspx?key=downloads

Regards
Arthur

Jeremy Lakeman

unread,
Nov 26, 2007, 11:32:46 PM11/26/07
to
On Nov 27, 3:59 am, Arthur Hefti <art...@catsoft.ch> wrote:
> Check out the classdefinition object. I wrote an article in PBDJ. You
> can find details on our website athttp://www.catsoft.ch/en/asp/page.aspx?key=downloads
>
> Regards
> Arthur
>

But, you can't get the values out... Unless you create a datawindow
with the same types and use dot notation to assign from your structure.

Stéphane

unread,
Nov 27, 2007, 8:23:20 AM11/27/07
to
On Mon, 26 Nov 2007 20:32:46 -0800 (PST),
in sybase.public.powerbuilder.powerscript

Thank you very much Arthur for your link !
I actualy experimented a little bit with the ClassDefinition object yesterday
but I didn't use it the right way.

I had tried something like this:
lcd_var = my_structure.ClassDefinition.Variablelist

This didn't compile (Incompatible property variablelist for type powerobject) so
I ended up thinking that a global structure was not considered as an object an
that its information could not be gathered (although the PB object browser or
System Tree view made me think it was still possible to achieve what I was
looking for).

The code you pointed me to is very interesting and very well explained. Thanks
again.

Jeremy, I don't want to use a datawindow because I want my code to be
independant from any further modification made to the structure (add or remove
property). The goal is to generate a csv file with field names on first line and
the corresponding values and second line for use with WinWord macros.

Philip Salgannik

unread,
Nov 27, 2007, 9:03:12 AM11/27/07
to

"Stephane" <stephane...@free.fr> wrote in message
news:474c1a48@forums-1-dub...

> The goal is to generate a csv file with field names on first line and
> the corresponding values and second line for use with WinWord macros.

"corresponding values " is the killer. You won't be able to get at the
values thru classdefinition...


Stéphane

unread,
Nov 27, 2007, 9:47:47 AM11/27/07
to
On 27 Nov 2007 06:03:12 -0800,
in sybase.public.powerbuilder.powerscript
I know, I've just writen sample code since my last post and now I can iterate
through my structure properties but can't reach their value. I understand better
what Jeremy was stated in his post. :-(

So, what can I do now ? Is there a way to access the values when you know the
properties names (as strings since it comes from VariableList[li_i].Name) ?
Something like rebuilding the variable name "my_struct.my_property" and then
evaluate it ? I guess I expect too much.

fish...@spam_wckp.lodz.pl_please

unread,
Nov 27, 2007, 10:40:51 AM11/27/07
to
This is exactly what Jeremy described.

You have to create a dw (dynamically) structurally identical with your structure
(what a phrase :-) ), than you can assign a structure to your dw and then grab
values from corresponding columns.

This will functionality will introduce you some PB features :-)
Good luck,

On 27 Nov 2007 06:47:47 -0800,
in sybase.public.powerbuilder.powerscript

Stéphane

unread,
Nov 27, 2007, 10:56:14 AM11/27/07
to
OK, that's what I feared :-( Now I have to balance between the time spent on
coding something like that (which I personaly find very interesting !) and the
real need for such a flexible solution for my application. I wanted to rewrite
that part of my application and do something "clean" but I may let the code as
it has already been written.

Anyway, thank you very much to all of you.

Stéphane.


On 27 Nov 2007 07:40:51 -0800,
in sybase.public.powerbuilder.powerscript

Arthur Hefti

unread,
Nov 27, 2007, 1:28:28 PM11/27/07
to
Creating a dynamic DataWindow object based on the definition you get
form the class definition object would be quite simple.

Regards
Arthur

Stéphane

unread,
Nov 28, 2007, 5:31:21 AM11/28/07
to
I'm tented to give it a try but I'd like to be sure that I'm doing this the
right; I was thinking of:
- looping through the variablelist[] and testing for lvd.TypeInfo.Category =
SimpleType! AND lvd.Cardinality.Cardinality = ScalarType!
- if so, get the lvd.TypeInfo.DataTypeOf to build the dw column syntax
dynamically with
" column=(type=" + lvd.TypeInfo.DataTypeOf + " updatewhereclause=yes name=" + +
" dbname='" + lvd.Name +"' )
- once every variablelist[] member has been inspected, build the final dw syntax
and use the DataWindow.Create() method
- assign the structure to the created datawindow

I have two remaining questions:
- for string structure properties, lvd.TypeInfo.DataTypeOf will return " string"
whereas exported datawindow shows "char(n)". Will "string" fit the dw syntax or
do I have to convert each time I have a property of type "string" ?
- my structure is actualy made of simple datatypes but also arrays and even
structures. I initialy wanted to ignore the arrays and to use recursivity to
decode the nested structures. But, since I have to assign the full structure to
a datawindow to get the values, how do I do that ?


On 27 Nov 2007 10:28:28 -0800,
in sybase.public.powerbuilder.powerscript

Arthur Hefti

unread,
Nov 29, 2007, 1:12:30 AM11/29/07
to
In theory this looks fine. When you create a datawindow on column type
varchar the data type in the datawindow is char(32766), this would also
be the type used for strings. To overcome the nested structure/array
problem you could assign the data column by column and recursively
decode the structure.

However this is only the technical approach. It looks to me like you're
building some data/object handling layer between the database and the
application. The structure has to know about the table column names,
decoding arrays maybe foreign keys are needed, etc.

I would choose an other approach in writing NVOs that can handle this
kind of work. Maybe passing the table name will automatically create a
datawindow within the nvo, providing getter/setter methods for the data,
handle retrieve and update logic, etc.

Regards
Arthur

0 new messages