[fpc-pascal] with statement using mulltiple objects
Frederic Da Vitoria
davitofrg at gmail.com
Tue Sep 16 12:36:17 CEST 2014
2014-09-16 12:26 GMT+02:00 Philippe <philippe at quarta.com.br>:
> Em 16.09.2014 05:44, Frederic Da Vitoria escreveu:
>
> 2014-09-14 16:23 GMT+02:00 Mark Morgan Lloyd <
> markMLl.fpc-pascal at telemetry.co.uk>:
>
>> I'd be far happier if there were provision for declaring a temporary
>> "shortcut" symbol:
>>
>> with shortcut: TSomething= TreeRoot.SubDirs[Low(TreeRoot.SubDirs)]^ do
>> begin
>> shortcut.DirLogged := true;
>> shortcut.DirHatFocus := false;
>> shortcut.SubDirsExpanded := true;
>>
>
> Yes, something close to alias in SQL, instead of plain elision which
> "with" currently performs. This would allow for a clearer writing without
> the pitfalls of the Pascal "with".
>
>
> could the compiler avoid "with" pitfalls?
>
> now the compiler attach a property to the closest "with" where it finds it.
>
> the compiler could check if the property appears in another "with" of the
> "with" stack and produce a message (hint, warning or error, which may be
> configurated).
>
> is not it a way to make the "with" safe?
>
I don't think it would make it safe, only slightly safer. Imagine: you are
using 2 nested "with" which have a field with the same name. The compiler
would tell you so. You'd check and decide that it's OK because you really
intended to mean the internal "with". Then, later, you remove or rename the
field which is used in the internal "with". The compiler won't send you any
warning since you will have removed a danger. But the meaning of your code
will have changed and will now be wrong. Will you remember that there was a
warning before and will you realize that the fact this warning disappeared
means trouble?
--
Frederic Da Vitoria
(davitof)
Membre de l'April - « promouvoir et défendre le logiciel libre » -
http://www.april.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20140916/488cb49c/attachment.html>
More information about the fpc-pascal
mailing list