tag:blogger.com,1999:blog-4073584026239112200.post359895464676980644..comments2023-09-29T16:39:50.116+02:00Comments on from old school to new frontier: Be carefull with inline vars.delphiprofihttp://www.blogger.com/profile/09517751070144650172noreply@blogger.comBlogger7125tag:blogger.com,1999:blog-4073584026239112200.post-5311081229502482422019-09-07T17:37:55.901+02:002019-09-07T17:37:55.901+02:00Yes, of course I simplified the example. I had a f...Yes, of course I simplified the example. I had a function returning an uint32 in my game engine and it took me 3h to find the error - that's why I wrote this blog post.delphiprofihttps://www.blogger.com/profile/09517751070144650172noreply@blogger.comtag:blogger.com,1999:blog-4073584026239112200.post-89007173142700672302019-02-28T14:26:08.942+01:002019-02-28T14:26:08.942+01:00You might also be willing to have a look at https:...You might also be willing to have a look at https://www.linkedin.com/pulse/inline-variables-delphi-rio-ivelin-nikolaev/Gad D Lordhttps://www.blogger.com/profile/17398618658913116741noreply@blogger.comtag:blogger.com,1999:blog-4073584026239112200.post-92124829068306559672019-02-18T13:51:58.497+01:002019-02-18T13:51:58.497+01:00So the real issue is that Count returns a UInt32. ...So the real issue is that Count returns a UInt32. It shouldn't. Did this actually happen to you?Rudy Velthuishttps://www.blogger.com/profile/04591719175507325825noreply@blogger.comtag:blogger.com,1999:blog-4073584026239112200.post-61390056155296983012019-02-16T08:50:18.038+01:002019-02-16T08:50:18.038+01:00First: Isn't that why all the Count properties...First: Isn't that why all the Count properties are Integer and not some unsigned typed like Word or UInt32?<br /><br />Also: Your code raises and integer overflow for me. If an unsigned integer variable is already zero, you cannot subtract any further 😉A dead diver that was found deep in the woodshttps://www.blogger.com/profile/04823570521710938871noreply@blogger.comtag:blogger.com,1999:blog-4073584026239112200.post-12556506119996779452019-02-15T23:21:52.956+01:002019-02-15T23:21:52.956+01:00When using inline variables, you don't need to...When using inline variables, you don't need to rely on type inference, you can specify the tye explicitly, eg:<br /><br />Procedure Foo;<br />begin<br /> for var I: int32 := 0 to MyList.Count - 1 do<br /> DoSimeThing(MyList[i]);<br />end;Remy Lebeauhttps://www.blogger.com/profile/03258935925603750579noreply@blogger.comtag:blogger.com,1999:blog-4073584026239112200.post-58577337050937849292019-02-15T20:01:12.034+01:002019-02-15T20:01:12.034+01:00Ok, I really had to read this a lot until I got yo...Ok, I really had to read this a lot until I got your problem and why we don't have this problem (we're using the inline var alot).<br />1. All of our lists are TList descendants (or TObjectList), so Count is an Integer and not unsigned int<br />2. We never use it in this way, because we have only generic lists, thus the last loop looks like that<br /><br />for var Element in MyList do<br /> DoSomething(Element);<br /><br />and creating objects on read access sounds not really like a good problem solver (aka it's bad code).Guanhttps://www.blogger.com/profile/01280071404470235398noreply@blogger.comtag:blogger.com,1999:blog-4073584026239112200.post-49409250560989226592019-02-15T14:57:38.837+01:002019-02-15T14:57:38.837+01:00So it's type inference that is the problem her...So it's type inference that is the problem here, not inline vars. (Not that inline vars don't have their own problems.)<br />If you declare it like this:<br /><br />for var i: Int32 = 0 to MyList.Count -1 do<br /><br />it should work as expected.<br />dummzeuchhttps://www.blogger.com/profile/10964052286248095908noreply@blogger.com