[fpc-pascal] a proposal about "with" syntax
Xiangrong Fang
xrfang at gmail.com
Sat Mar 16 23:55:45 CET 2013
shiruba <shiruba at galapagossoftware.com>'s example is better than mine, and
was exactly the reason I posted this suggestion.
I don't think a class helper is worth for this stuff, if I need to write a
helper I would rather do this:
longobj := BigLongThingIDontWantToWriteOutEverySingleTime;
With longobj do begin
Height := 100;
Width := 200;
...
SomeOtherObject.Submit(longobj);
end;
That's not elegant, but it is really not worth for a helper in this case,
IMHO. "with" itself is a convenience syntax anyway, why adding an "as" to
make it more convenient a bad idea? I don't know what's make it complex if
there are 2 or more subject in the with?
2013/3/17 Daniel Gaspary <dgaspary at gmail.com>
> On Sat, Mar 16, 2013 at 3:02 PM, 印場 乃亜 <shiruba at galapagossoftware.com>
> wrote:
> > With BigLongThingIDontWantToWriteOutEverySingleTime do
> > begin
> > Height := 100;
> > Width := 200;
> > ...
> >
> SomeOtherObject.Submit(BigLongThingIDontWantToWriteOutEverySingleTime);
> > end;
> >
> > Notice how I have to write the long thing out again at the bottom. There
> > must be a way around that (Something like "Self", but that refers to
> > whatever you are using in With).
>
> You can use a Class Helper:
>
> http://pastebin.com/pFL49byh
>
> But you gonna need to use a type cast. And with a "SomethingElse" at
> the with, as showed by Xiangrong, things can become messy.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20130317/d56d8adc/attachment.html>
More information about the fpc-pascal
mailing list