Forum > Beginners

“case (a,b) of...” doesn’t compile

(1/4) > >>

Weiss:
I am trying pascal code of 30 years ago, written in vanila pascal. This statement doesn’t compile, and I honestly never seen this syntax before:


--- 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";}};} ---  dataarraytype = RECORD                    CASE (r, c) OF                      r : (rp : ARRAY [dataindextype] OF real);                      c : (cp : ARRAY [cmpxindextype] OF complex)  

compiler does not like “(“ , expects identifier. It is Fourier transform, I honestly can’t re-write this part without taking the code apart. I don’t understand the record altogether, if it is a record of two members, both arrays, why wasn’t it declared as such? I think case was needed, but don’t know why.

TRon:
see also: https://www.freepascal.org/docs-html/ref/refsu15.html

It is a variant record. Meaning that both rp and cp use overlapping memory. You can access both fields but both fields are of a different type (the variant).

you could probaly rewrite it as:

--- 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";}};} ---dataarraytype =record  case boolean of  true: (rp: array[dataindextype] of real;  false: (cp: array[cmpxindextype] of complex;end; 

440bx:
or even closer to what the OP showed...


--- 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";}};} ---type   TENUM = (r, c); dataarraytype =record  case TENUM of  r : (rp : array[dataindextype] of real;  c : (cp : array[cmpxindextype] of complex;end; 

TRon:
Even better 440bx. I missed the fact that it is probably an on-the-fly created enum type.

440bx:

--- Quote from: TRon on September 25, 2023, 05:51:01 am ---...it is probably an on-the-fly created enum type.

--- End quote ---
That's my guess too based on how Pascal defines variants.

Navigation

[0] Message Index

[#] Next page

Go to full version