1. Tom Mangano
  2. PowerBuilder
  3. Thursday, 8 August 2024 20:32 PM UTC

this is the script

dec{ 2 }	ld2_temp
long		ll_pos, ll_arrayCount, ll_ac 
string	ls_temp, ls_file_read

Try 
	
	ls_file_read = is_file_string_read		/* debugging */
	
	ll_pos = LastPos( is_file_string_read, is_tilde ) 
	
	ls_temp = Mid( is_file_string_read, ll_pos + 1 )
	
	ll_arrayCount = UpperBound( id2_cost_extended )
	
	if isNull( ll_arrayCount )=True then 
		ll_arrayCount = 0 
	end if 
	
	ll_ac = ll_arrayCount + 1
	
	ld2_temp = Dec( ls_temp )
	id2_cost_extended[ ll_ac ] = ld2_temp
	
	/*
		debugging 
	*/
	
	ll_arrayCount = UpperBound ( id2_cost_extended ) 
	
	ld2_temp = id2_cost_extended[ ll_arrayCount ] 
	
Catch ( runTimeError er )
	as_errorString = as_errorString 
End Try 

Return

instance array id2_cost_extended[] is null when this function is called

ll_arrayCount = NULL

ll_ac gets set to 1 (verified that ll_ac = 1 in the debugger)

when this line is executed

id2_cost_extended[ ll_ac ] = ld2_temp

the program falls into the Try Catch,

as_errorString = '', i.e. no runtime error reported

when i look at the value of id2_cost_extended[] in the debugger, it's null.

i've regenerated the nvo and the nvo it's inherited from

what am i doing wrong?

 

Tom Mangano Accepted Answer Pending Moderation
  1. Friday, 9 August 2024 14:04 PM UTC
  2. PowerBuilder
  3. # 1

thanks for all of the replies.

setting the array to null - it's  because i had my head in a dark place.

initializing with a local array "fixed" my error.

string ls_temp[]

is_string[] = ls_temp[]

is_string[] has no elements, it's not NULL, and behaves as expected.

 

 

Comment
  1. John Fauss
  2. Friday, 9 August 2024 19:14 PM UTC
I'm glad to learn you have resolved the issue, Tom!
  1. Helpful 1
  1. David Peace (Powersoft)
  2. Wednesday, 14 August 2024 12:15 PM UTC
Please mark the issue resolved,
  1. Helpful
There are no comments made yet.
Benjamin Gaesslein Accepted Answer Pending Moderation
  1. Friday, 9 August 2024 06:31 AM UTC
  2. PowerBuilder
  3. # 2

Internally, an array variable is simply a pointer to some location in memory. If you set it to null, it points to nothing. If you want to assign values to an array variable that is null, initialize a new array locally and set the variable to this new array first. I.e.

 

decimal ld_array[]

if isnull( id2_cost_extended ) then
    id2_cost_extended = ld_array
end if

id2_cost_extended[1] = some_value
Comment
  1. John Fauss
  2. Friday, 9 August 2024 19:13 PM UTC
I will respectfully disagree with a portion of your assertion, Benjamin, where you stated "If you set it to null, it points to nothing." In many languages, C/C++ for example, you are 100% correct that NULL is equivalent to the memory address zero.

However, I do not believe this is how PB implements its concept of null variables or null objects. I posit that PB manages a "descriptor" block/structure for every variable and object, and in that descriptor is a flag that indicates if the variable/object is null. The SetNull() function does not result in any change to the value of a variable... it simply enables the "I'm null" flag in the variable's or the object's descriptor.

This is what I've observed by sleuthing in memory as I've performed research for papers and example programs I've published over the last several years. I maintain that if Appeon wanted to, it could provide a SetNotNull() function that would disable this flag in the descriptor and thereby "restore" the variable's value.

Consider for a moment the simple case of a PB Byte variable. It can hold a value of zero to 255... all of the possible patterns for eight bits. Like all PB variable, it can also be null. If there is no external tracking of null status, then how can PB discern between that variable having a value of zero and it being null? It can't - so there MUST be another means for PB to manage null status under the covers.
  1. Helpful
  1. Benjamin Gaesslein
  2. Monday, 12 August 2024 07:10 AM UTC
John, all that may well be true and I cannot contest it but it's purely academic, no? I do not know how PB handles null values but the implementation details make no functional difference. :)

In the end, all variables are a pointer to some memory address. What happens in memory when you use setnull? I suspect that PB clears the pointer but the value will stay in memory until it's garbage collected? Restoring the pointer to that address may be possible in theory but I think it might not be very safe unless there's still some other reference to this memory address/variable to keep it from being garbage collected



I'm guessing that under the hood, PB implements all basic variables as pointers. Setnull() will change the pointer to a nullpointer to memory address 0, which is not accessible and will lead to a null pointer exception when accessed. This is what C does, NULL is simply defined as 0 and assigning NULL to a pointer will create a pointer that does not point to a valid object.
  1. Helpful
There are no comments made yet.
Marc Wietscher Accepted Answer Pending Moderation
  1. Friday, 9 August 2024 06:03 AM UTC
  2. PowerBuilder
  3. # 3

as_errorString = er.GetMessage()

;-)

Comment
There are no comments made yet.
John Fauss Accepted Answer Pending Moderation
  1. Friday, 9 August 2024 03:56 AM UTC
  2. PowerBuilder
  3. # 4

Hi, Tom - 

Why is the instance array null? An unbounded array is empty (no elements) by default and can be null only if explicitly made that way via the SetNull() PowerScript function. What is the purpose of setting an unbounded array to null?

Best regards, John

Comment
  1. Chris Pollach @Appeon
  2. Friday, 9 August 2024 12:32 PM UTC
Correct John!

Tip: you can free memory by doing this ...

Any work_arrary[]

Any empty_array[]

Work_Array [n] = 1234

...

Work_array = Empty_Array // free mem
  1. Helpful
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.