1. Dan Cooperstock
  2. PowerBuilder
  3. Monday, 10 February 2020 18:01 PM

I just want to confirm my understanding. Suppose I have the following (over-simplified) code:

nvo_myobj obj
obj.StringValue = "foo"
w_mywindow.Post wf_do_something("The value is: " + obj.StringValue)
DESTROY obj

Is that OK, because the function arguments have been evaluated at the execution time of that function call, so even though the object is destroyed before the posted function runs, it still passes "The value is: foo" to the function? Or is the function call evaluation delayed until the posted event actually happens, in which case this code would be a problem? (I believe it is the former, but want to be sure I'm right.)

Thanks.

Accepted Answer
Michael Kramer Accepted Answer Pending Moderation
  1. Monday, 10 February 2020 18:28 PM
  2. PowerBuilder
  3. # Permalink
2
Votes
Undo

Hi Dan, you're right!

Parameter expression is evaluated at time of call. There is no lazy evaluation in PowerScript.
Even POST DYNAMIC doesn't make the evaluation lazy. PowerScript is never lazy.

This has consequences: If you call post of_MyFunc(Now()) as argument you pass time of call; not time of execution.

Another post consideration is that you cannot post a call being passed as parameter because expression is required immediately. This is side effect of parameter calculated immediately.

/*  VALID  */      of_func2(     of_func1())
/*  VALID  */ post of_func2(     of_func1())
/* INVALID */      of_func2(post of_func1())
/* INVALID */ post of_func2(post of_func1())

HTH /Michael

Comment
There are no comments made yet.
Miguel Leeuwe Accepted Answer Pending Moderation
  1. Monday, 10 February 2020 19:52 PM
  2. PowerBuilder
  3. # 1
1
Votes
Undo

In addition to what Michael said, there's one thing you have to be careful with:

It won't work if your passing the object.string parameter "by ref".

See the attached illustrating sample app (pb2017) to see what I mean.

regards

Attachments (1)
Comment
True good points ! Though personally - maybe I'm old-fashioned - I'm not too fond to rely on garbage collection as it has it's quirks too.
  1. Miguel Leeuwe
  2. Monday, 10 February 2020 22:33 PM
Hi Miguel ... Yes, you should never rely on G.C! My next release of the STD Framework will track all NVUO's and alert the App developer if they are not disposed of properly. Also, it will track App memory used within the Apps address space and alert the App when memory is low and or critical (an app crash is inevitable). You try out the new code here in its beta form for PB2019 build 2170: https://sourceforge.net/projects/stdfndclass/files/Applications/PowerBuilder/OrderEntry/Beta/PB2019/

Note: The STD Framework's 2019R2 beta does not have all this NVUO / Memory tracking code - yet. ;-)
  1. Chris Pollach @Appeon
  2. Tuesday, 11 February 2020 19:00 PM
Thanks for that Chris, it might be very useful !
  1. Miguel Leeuwe
  2. Wednesday, 12 February 2020 02:18 AM
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.