Forum > General

refer to writable constant using different names

(1/2) > >>

440bx:
Hello,

I'm trying to refer to a writable constant using different names, for instance:
--- 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";}};} ---{$MODE OBJFPC} program _Constants; const  SOME_TEXT  : pchar = 'some text'; const  OTHER_TEXT = SOME_TEXT;          { illegal expression }  OTHER_TEXT : pchar = SOME_TEXT;  { got SYSTEM.PChar expected SYSTEM.PChar } beginend. Basically, I want to be able to sometimes refer to the "constant" SOME_TEXT using the name OTHER_TEXT but, everything I've tried so far makes the compiler unhappy.

On a different note, the error message on the second option doesn't really help much. "got SYSTEM.PChar expected SYSTEM.PChar", it's a bit disconcerting to have the compiler complain that it got what it expected (usually that's not an error ;) )

as the signature states, FPC v3.0.4 (haven't tested with later versions)

MarkMLl:
Use a macro and be done with it.

MarkMLl

Thausand:

--- Quote from: 440bx on June 18, 2022, 05:07:27 pm ---Basically, I want to be able to sometimes refer to the "constant" SOME_TEXT using the name OTHER_TEXT but, everything I've tried so far makes the compiler unhappy.

--- End quote ---
Try var for read (no write, then error):


--- 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";}};} ---const  SOME_TEXT : pchar = 'some text';var  OTHER_TEXT: pchar absolute SOME_TEXT; 

440bx:

--- Quote from: MarkMLl on June 18, 2022, 05:16:24 pm ---Use a macro and be done with it.

MarkMLl

--- End quote ---
thank you for the suggestion but, I avoid macros like the plague.



--- Quote from: Thausand on June 18, 2022, 05:27:36 pm ---
--- 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";}};} ---const  SOME_TEXT : pchar = 'some text';var  OTHER_TEXT: pchar absolute SOME_TEXT; 
--- End quote ---
thank you, I appreciate the suggestion. 

Honestly, I was hoping for something that didn't use macros or "absolute" but, it's likely there is no other way.

jamie:
we don't have ORG here  :D

Navigation

[0] Message Index

[#] Next page

Go to full version