Access IOL variables as properties

Started by Thomas Bock, November 10, 2023, 05:03:32 AM

Previous topic - Next topic

Thomas Bock

I'm trying to save the variables of an iolist as a property with a dynamic approach. The purpose is to retrieve extermal parameters only once without the need to adjust anything when new parameters are introduced. So far I had no luck.

Here ist my class
def class "GetIOL" create required
property params$
function whatParams()
print "whatParams()"
print lst(iol(params$))
print sub(params$,sep,"~")
print params.name$
return 1
function end
end def
ON_CREATE:
call "GetIOL.pvc;FETCH_PARAMS", params$
print "ON_CREATE"
print lst(iol(params$))
print sub(params$,sep,"~")
print params.name$
return
FETCH_PARAMS:
enter p$
dim p$:iolist id$,name$,value
p.id$="ABC"
p.name$="XYZ"
p.value=42
exit


No variable arrives inside the object, though the iolist is constantly present.
I also tried static iol=iol(params$) and several other approaches. But everything failed.

This is my test program
begin
g=new("GetIOL")
g'whatParams()
delete object g
end


All suggestions are welcome.

Devon Austen

#1
Unfortunately Composite strings cannot be used as object properties (See the note here: https://manual.pvxplus.com?directives/dim.htm#Mark7).

You can probably accomplish what you are going for by dynamically creating properties (https://manual.pvxplus.com?directives/def_class.htm#dynamic).
Principal Software Engineer for PVX Plus Technologies LTD.

PxPlus

For further clarification on this issue:

When you create a composite string you are creating a variable that when referenced is constructed on the fly from the variables defined in the IOLIST (or parsed in the case of update).

So in your example you have defined a composite string params$ whose value should be derived from the variables param.id$, param,name$, and param.value.

The problem stems from the fact these, as they are true variables, will not be saved when you exit the ON_CREATE or any Method call.  Also as true variables they cannot be defined as properties or local values within the object in the hopes that this will preserve their contents.  The logic that builds the composite string when you reference params$ only looks at defined variable list and not any object related elements.

Normally when running within an object and a variable is referenced the system will look at the property and local variable list to see if the variable is defined and, if not, proceed to the list of true variables.  Composite strings only look at the true variable list as the variable names are dynamically created from the composite string variable name and element in the associated iOLIST.