Forum > General
Accessing Property via Pointer
Thaddy:
No, just do not misuse properties, use fields. A getter would need a call. So asm is required. You can't bluntly substitute an address with a call.
MarkMLl:
I am by no means a fluent interpreter of the entrails of the FPC compiler, but would point you at this recent thread https://forum.lazarus.freepascal.org/index.php/topic,66220.msg506413.html#msg506413 where Remy (and others) was surprised by the fact that a setter was able to accept a var parameter rather than one passed purely by value.
The implication of this is that instead of a property corresponding to predefined procedure and function types as the setter and getter, they behave almost like macros with replacement done at the source level which is later resolved to any suitable entry point.
So like others, I'm surprised that your code is accepted by the compiler, and there's a real risk that if you do that you'll generate something pathological: the answer to your question has to be "Dunno, take a look at the generated assembler" :-)
MarkMLl
kupferstecher:
--- Quote from: Martin_fr on February 20, 2024, 07:46:29 pm ---Afaik, you shouldn't even be able to take the address of a property
--- 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";}};} --- pSth:= @Foo.sth;That should generate an error.
--- End quote ---
Yes, I think so. When I testet it I didn't really expect it to work (though would be good). If there were such an error I wouldn't have asked here.
--- Quote ---In the same way 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";}};} --- inc(Foo.sth);gives an error.
--- End quote ---
Ah, I remember such a discussion here on the forum. And somehow can understand the reasoning (double access because of read plus write, while one could assume a single operation?). But I think it would come handy and make properties much more useful. For the outside of the class it would behave just like a regular variable. Because of the restriction I cannot pass the property to a function, so I either have to explicitely call the property (i.e. hard code it), or pass setters and getters, which is more effort to implement. Instead the compiler should just do its magic~
--- Quote from: Thaddy on February 20, 2024, 07:59:59 pm ---A getter would need a call. So asm is required. You can't bluntly substitute an address with a call.
--- End quote ---
I see your point, the compiler (or the generated code) can't really know that the pointer address in the moment of dereferencing is pointing on a property instead of a plain variable. Perhaps a special property pointer would be needed. But yes, ...
--- 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";}};} ---pSth: ^Property of Integer;
(just a joke)
--- Quote from: MarkMLl on February 20, 2024, 08:19:00 pm ---The implication of this is
--- End quote ---
a bit difficult to grasp :)
Navigation
[0] Message Index
[*] Previous page