PxPlus User Forum

Twitter Twitter Twitter

Author Topic: Creating a new instance of an object especially for a Query  (Read 2018 times)

Arno de Greef

  • Member
  • **
  • Posts: 10
    • View Profile
Creating a new instance of an object especially for a Query
« on: November 08, 2023, 11:19:43 AM »
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

  • Diamond Member
  • *****
  • Posts: 122
  • PxPlus guru with skills in PHP, JS, C#, Java
    • View Profile
    • Stéphane's Web Resume
Re: Creating a new instance of an object especially for a Query
« Reply #1 on: November 09, 2023, 02:02:32 AM »
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

  • Member
  • **
  • Posts: 10
    • View Profile
Re: Creating a new instance of an object especially for a Query
« Reply #2 on: November 09, 2023, 09:26:42 AM »
Hi Stéphane,

This sounds interesting. Will have a look !

Thanks,
Arno de Greef

Arno de Greef

  • Member
  • **
  • Posts: 10
    • View Profile
Re: Creating a new instance of an object especially for a Query
« Reply #3 on: November 09, 2023, 02:32:12 PM »
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

  • Administrator
  • Diamond Member
  • *****
  • Posts: 1091
    • View Profile
Re: Creating a new instance of an object especially for a Query
« Reply #4 on: November 09, 2023, 05:58:24 PM »
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

  • Member
  • **
  • Posts: 10
    • View Profile
Re: Creating a new instance of an object especially for a Query
« Reply #5 on: November 10, 2023, 03:17:02 AM »
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

  • Staff
  • Diamond Member
  • *****
  • Posts: 280
    • View Profile
    • PVX Plus Technologies
Re: Creating a new instance of an object especially for a Query
« Reply #6 on: November 13, 2023, 10:00:14 AM »
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

  • Member
  • **
  • Posts: 10
    • View Profile
Re: Creating a new instance of an object especially for a Query
« Reply #7 on: December 06, 2023, 10:49:56 AM »
PxPlus has shared with us a fix that seems to have resolved the issue.

Thanks!