Creating a new instance of an object especially for a Query

Started by Arno de Greef, November 08, 2023, 11:19:43 AM

Previous topic - Next topic

Arno de Greef

Hello,

We have created an object to read some information from our database. We would like to show this information in a column of a query. We want to create a new instance of the object when starting the query and drop the object when closing the query.

To do this, we're looking into the Initialization and Closing procedures on the interface tab of the query interface. During the initialization procedure we need create the object and make the objects CTL available to both a formula in the query itself and the closing procedure. To that end we tried normal (non global) variabeles. This seems to work file with classic queries, however in query+ queries the CTL can be used in the formula but does not arrive in the closing procedure. Naturally we could use a global variable, but we worry about the scope of these variables. Chances are we will use multiple (same) queries at the same time causing the risk of globals overwriting each other.

Is there anybody out there with experience in this matter who is willing to share  :) ?

Thanks,
Arno de Greef

Stéphane Devouard

Hi Arno

PxPlus has an interesting concept of LOCAL globals

If you declare
LOCAL %INFO$ in a program

Then %INFO$ will be global in the current stack level and "above"
If there is another similar declaration in a higher stack level, then the current %INFO$ value will be preserved, the new value will replace it, and when dropping to a lower stack level, the preserved value will be restored

Hope this helps
Stéphane Devouard
Portfolio | Work

Arno de Greef

Hi Stéphane,

This sounds interesting. Will have a look !

Thanks,
Arno de Greef

Arno de Greef

Hi Stéphane,

In queries I use the Initialization and Closing procedures, which are calls. To get any result from the query, I have to leave that call. This means dropping to a lower stack and loosing the local global I created in the call.

I think local globals are great, but I'm affraid they can't help in this situation.

Thank you for your suggestion.

Arno de Greef

PxPlus

Actually why not just pass a variable to contain the object handle into the initialization call, set it during initialization, then during the finalization pass the same variable and drop the object.  The variable you pass in should remain localized to the current Query session.

Arno de Greef

Thank you PxPlus for your reply.

If I understand correctly, you suggest something like

In the initialization procedure : "CALL.PRG",my_object_ctl
In the closing procedure : "CLOSE.PRG",my_object_ctl

I tested this in the attached example. CALL.PRG puts 100 in the variable and CLOSE.PRG shows a messagebox with the received variable.

To test I used

%nomads'QueryProgram$="*winqry"
process "test","demo.en"
%nomads'QueryProgram$="*winqry2"
process "test","demo.en"

In my first test (*winqry) the messagebox showed 100, in the second (*winqry2) showed 0.

Am I missing something?

Jane Raymond

Arno,
I have found the cause of the issue and have a possible solution. If you could report this issue to our helpdesk I can let you know you the solution:
http://helpdesk.pvxplus.com

Jane Raymond
Software Developer
PVX Plus Technologies Ltd.

Arno de Greef

PxPlus has shared with us a fix that seems to have resolved the issue.

Thanks!