[fpc-pascal] with statement using mulltiple objects

vfclists . vfclists at gmail.com
Mon Sep 15 21:03:11 CEST 2014


On 13 September 2014 20:29, vfclists . <vfclists at gmail.com> wrote:

>
>
> On 13 September 2014 20:02, Sven Barth <pascaldragon at googlemail.com>
> wrote:
>
>> On 13.09.2014 20:13, vfclists . wrote:
>>
>>> According to the docs the with statement when used with mulltiple
>>> objects only works with the last parameter.
>>>
>>>
>>> The statement
>>>
>>> With A,B,C,D do Statement;
>>>
>>> is equivalent to
>>>
>>> With A do
>>>   With B do
>>>    With C do
>>>     With D do Statement;
>>>
>>> --
>>>
>>> I thought that if all the objects have the property the statement would
>>> apply to them eg.
>>>
>>>
>>> with Label1, Label2, Label3 do
>>>    Caption = 'Text'.
>>>
>>> I thought all the 3 labels would have the caption set, but only Label3's
>>> caption is set. Is this a difference between Delphi's Object Pascal and
>>> FreePascal, or has Delphi's Object Pascal always worked in the same
>>> manner?
>>>
>>
>> It has always worked in this manner. It's just for abbreviating typing,
>> not for combining properties. (and then the with-variant with multiple
>> elements is even more seldomly used than the single-element one...)
>>
>> Regards,
>> Sven
>> _______________________________________________
>> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
>> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
>>
>
> What then is the nesting for if the command will only apply to the last
> item with the property? Is each nested element supposed to be a property of
> the enclosing element?
>
> What is the rationale for such a statement, ie using multliple elements?
>
> --
> Frank Church
>
> =======================
> http://devblog.brahmancreations.com
>



This is a fragment I was using with multiple elements. So it means that all
this time it was only working  because all of them had been set at design
time and the command was only applied to the last one.

I wonder where I got the impression that because they all shared the
property the command applied to all of them.

  with qrySCParameters, qrySavedCommands, qryTemplateParameters,
    qryLiveCommands, qryLCParameters do
  begin
    Connection := dmCentral.localCommandsConnection;
  end;

    dmCentral.localCommandsConnection.Connected := True;

I am happy with the use of 'with' on a single element, but using it with
multiple elements is plainly evil.

-- 
Frank Church

=======================
http://devblog.brahmancreations.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20140915/96be427e/attachment.html>


More information about the fpc-pascal mailing list