[fpc-pascal] Changing var to out in rtl code
max.vlasov at gmail.com
Sun Nov 21 22:07:25 CET 2010
On Sun, Nov 21, 2010 at 9:22 PM, Michael Van Canneyt <michael at freepascal.org
> On Sun, 21 Nov 2010, Max Vlasov wrote:
>> I'm one of those developers who takes hints and warnings seriously and I
>> must say at least once a week it helps me find a bugs even before running
>> program. So when I got a warning about some uninitialized variable passed
>> by reference (Delphi 5 is ok with such variable being uninitialized), I
>> what I should do to fix this, and the best solution for this is changing
>> the declaration from "var " to to "out " (CMIIW).
>> But is it possible to do the same (partially, gradually or in any other
>> way) for the "legacy" code that keeps the interface compatibility with
>> For example TStrignList.Find(const S: string; var Index: Integer):
>> Boolean; declares "var " so my existing fragments expecting just an result
>> from this
>> call, got "Hint: Local variable "Index" does not seem to be initialized"
>> warning. But looking at the implementation details it seems it is safe to
>> "var Index" to "out Index" and possibly it is also safe for any
>> delphi/lazarus code calling this method
> For this particular instance, I changed the code. (rev 16395)
> But in general, one must be careful with changing such things.
Michael, great to hear, the only thing I didn't notice initially (sorry), is
that it's a virtual method. The change would probably break inheritance in
some cases for some developers, but I just can't imagine someone overriding
TStringList.Find since its logic is completely full and content for ages and
even if so, probably making such small fix should not be a problem. Sorry
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the fpc-pascal