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.
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.
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.
> 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...
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.
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
Anyway, thank you very much to all of you.
Stéphane.
On 27 Nov 2007 07:40:51 -0800,
in sybase.public.powerbuilder.powerscript
Regards
Arthur
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
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