Forum > General

[SOLVED] Type conversion?

(1/4) > >>

egsuh:
Hi, why following codes causes compile 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";}};} ---type   TInputTypes = (itText, itPassWord, itRadio, itCheckbox, itHidden, itTel,                 itNumber, itUrl, itEmail, itRrange, itDate, itMonth, itWeek); var   ts: string;   anIT: TInputTypes; begin   ts := // sometext;    ReadStr(ts, anIT);  <== this is not compiled ...  end; 
Error message : Typecast has different size (1 -> 4) in assignment

MarkMLl:
The documentation isn't exactly helpful, but I think the big question is what types (as the non-first argument(s)) ReadStr() accepts: it might be unreasonable to expect it to handle a locally-defined enumeration.

MarkMLl

Zvoni:
What Mark said.
Added: He's passing the Enum-Variable, and not an Enum-Value to ReadStr.....

What exactly is OP trying to achieve?

MarkMLl:

--- Quote from: Zvoni on August 15, 2022, 12:34:26 pm ---What Mark said.
Added: He's passing the Enum-Variable, and not an Enum-Value to ReadStr.....

What exactly is OP trying to achieve?

--- End quote ---

I assume that he's trying to read into the variable. Might be doable with a cast.

I suspect that it would be tricky to override ReadStr(), even for a fixed number of parameters.

MarkMLl

dje:
You seem to want a FPC feature in DELPHI mode (or maybe even in Delphi). The following code works in FPC mode, but produces your error in DELPHI mode.

Maybe someone else can provide the exact reason why.


--- 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 fpc}program project1;type  TInputTypes = (itText, itPassWord, itRadio, itCheckbox, itHidden, itTel,    itNumber, itUrl, itEmail, itRrange, itDate, itMonth, itWeek);var  ts: string;  anIT: TInputTypes;begin  ts := 'itText';  ReadStr(ts, anIT);  Readln;end.  

Navigation

[0] Message Index

[#] Next page

Go to full version