PxPlus User Forum

Twitter Twitter Twitter

Author Topic: Access IOL variables as properties  (Read 283 times)

Thomas Bock

  • Diamond Member
  • *****
  • Posts: 173
    • View Profile
Access IOL variables as properties
« on: November 10, 2023, 05:03:32 AM »
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
Code: [Select]
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
Code: [Select]
begin
g=new("GetIOL")
g'whatParams()
delete object g
end

All suggestions are welcome.

Devon Austen

  • Administrator
  • Diamond Member
  • *****
  • Posts: 382
  • Don’t Panic
    • View Profile
    • PVX Plus Technologies
Re: Access IOL variables as properties
« Reply #1 on: November 10, 2023, 08:35:37 AM »
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).
« Last Edit: November 10, 2023, 08:38:15 AM by Devon Austen »
Principal Software Engineer for PVX Plus Technologies LTD.

PxPlus

  • Administrator
  • Diamond Member
  • *****
  • Posts: 1091
    • View Profile
Re: Access IOL variables as properties
« Reply #2 on: November 10, 2023, 11:08:49 AM »
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.