[fpc-pascal] a proposal about "with" syntax

印場 乃亜 shiruba at galapagossoftware.com
Sat Mar 16 19:02:35 CET 2013


Hi,

I also think this would be useful, but for other reasons, often times I end up with code like the following:

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).  In Xiangrong's example, this could be mci, but even it it was a static name it would be useful.  (If this exists and I am just not aware, please let me know!)

Thank you,
   Noah Silva

On 2013/03/16, at 15:13, Xiangrong Fang <xrfang at gmail.com> wrote:

> Suppose I have the following class:
> 
> type
>   TMyClass = class
>   public
>     property Caption: string read FCaption write FCaption;
>     property Items[Index: Integer]: string read GetItem write SetItem; default;
>     function Count: Integer;
>   end;
> 
> I would like to do this:
> 
> with MyClassInstance as mci, SomethingElse do begin
>   Caption := 'A new caption';
>   for i := 0 to Count - 1 do
>     mci[i] := UpperCase(mci[i]);
> end;
> 
> That is, to add an optional "as" clause to the with statement so that access array element in a structure is made easier.
> _______________________________________________
> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20130317/6fd94514/attachment.html>


More information about the fpc-pascal mailing list