Forum > Beginners

[Solved] pointer to out of scope const

(1/2) > >>

Joanna from IRC:
I have a class which contains a variable; ar_checkbox_captions:tstringarray;


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---  PROCEDURE TINI_CHECKCOMBOBOX.TEST;           const ar:array [0..5] of string = ('1','2','3','4','5','6');BEGINAR_CHECKBOX_CAPTIONS:= AR;LOAD;END;  
The ar_checkbox_captions starts with zero values and is initially set to nil. After I assign it to the const ar and leave the test procedure the values continue to be valid even though the array is no longer in scope. Did it make a copy of ar ? or is the information from ar still being used even though its no longer in scope?

marcov:
The AR array is typed, so is a constant that has an address in data memory somewhere, and is not on the stack.

If tstringarray is a pointer, then the address of the constant is stored in it, and can be referenced outside.

Not languagewise elegant, but safe.

Joanna from IRC:
That’s interesting. So the constant inside a procedure exists for the life of the program execution. That explains it. Thanks .

440bx:

--- Quote from: Joanna from IRC on December 04, 2024, 01:09:48 pm ---That’s interesting. So the constant inside a procedure exists for the life of the program execution. That explains it. Thanks .

--- End quote ---
Note that depending on the setting of the $J directive that "constant" may be a variable (writable constant)

Joanna from IRC:

--- Quote from: 440bx on December 04, 2024, 06:11:54 pm ---
--- Quote from: Joanna from IRC on December 04, 2024, 01:09:48 pm ---That’s interesting. So the constant inside a procedure exists for the life of the program execution. That explains it. Thanks .

--- End quote ---
Note that depending on the setting of the $J directive that "constant" may be a variable (writable constant)

--- End quote ---
I  assume that this directive only applies to typed. Constants?

Navigation

[0] Message Index

[#] Next page

Go to full version