Forum > Pas2JS

Problem with for in loop and TList

<< < (2/2)

Thaddy:
Yes. Write code that doesn't use any of the documented limitations of Pas2Js.
Usually that is perfectly possible.

Note: also the other way around: Pas2Js has features like e.g. anonymous methods (in trunk) that are not yet available in FPC core.

Akira1364:

--- Quote from: dubst3pp4 on December 17, 2018, 09:53:08 am ---
--- Quote from: Akira1364 on December 15, 2018, 06:41:57 am ---You don't need to implement anything.

HeavyUser clearly thinks you're talking about how the TList enumerator works in actual FPC, not Pas2JS. "Pointer" is a valid keyword in Pas2JS but is used for essentially nothing because it's obviously meaningless in that context. More specifically, the TList in Pas2JS stores JSValues, not Pointers, as is the case for almost everything in Pas2JS.

--- End quote ---
Oh, that's interesting, thanks for the clarification. But what I don't like about this approach is that you thereby have to write platform specific code. I want to write some base classes that I can use on the client (JavaScript target) and on the server (x86 target). Is there a way to avoid compiler switches here?

Best regards,
Marc

--- End quote ---

I mean, you could probably get around it with something as simple 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";}};} ---{$ifdef FPC}type ListItem = Pointer;{$else}type ListItem = JSValue;{$endif}
And then just use ListItem as the type specifier for variables.

mattias:
At the time when TList was added to the pas2js rtl, the "pointer" type did not exist, so jsvalue was used.
If TList would be introduced today it would use pointer.
What do you think, should it be changed to pointer for compatibility?

Navigation

[0] Message Index

[*] Previous page

Go to full version