[fpc-pascal] Re: Is this if /else syntax wrong?
Frank Church
vfclists at gmail.com
Thu Jul 1 12:52:19 CEST 2010
It is working now on 2.2.4. I think it was a temporary IDE glitch, which is
what I suspected. Adding the ; made it go away, but it wasn't really the
problem
2010/7/1 Mattias Gärtner <nc-gaertnma at netcologne.de>
> Zitat von Frank Church <vfclists at gmail.com>:
>
>
> I will be upgrading to 2.4.0 soon.
>>
>> It shouldn't be an error then.
>>
>> 2010/7/1 Guillermo Martínez Jiménez <gmartinez at burdjia.com>
>>
>> > procedure TfrmHometel.SetSplitterSizes;
>>> > var
>>> > i: integer;
>>> > begin
>>> > for i:=3D 0 to ComponentCount - 1 do
>>> > begin
>>> > if Components[i] is TSplitter then
>>> > begin
>>> > with TSplitter(Components[i]) do
>>> > begin
>>> > if Cursor =3D crHSplit then
>>> > Width :=3D 7
>>> > else if Cursor =3D crVSplit then
>>> > Height :=3D 7;
>>> > ; // <-- removing this semicolon results in a syntax error. Is it
>>> > syntax error some kind of extra strict compiler check.
>>> > Color :=3D clBlue;
>>> > end;
>>> > end;
>>> > end;
>>> > end;
>>>
>>> Compare with next:
>>>
>>> if Cursor =3D crHSplit then
>>> Width :=3D 7
>>> else
>>> if Cursor =3D crVSplit then
>>> Height :=3D 7; // <-- This semicolon is for the "if".
>>> ; // <-- This semicolon is for the "else".
>>>
>>
> No. A semicolon ends *all* open if/if-else/do statements.
> The second semicolon is an empty statement - a 'no operation'.
>
>
>
> Is like this:
>>>
>>> IF ... THEN
>>> BEGIN
>>> ...
>>> END
>>> ELSE BEGIN
>>> IF ... THEN
>>> BEGIN
>>> ...
>>> END; // <-- This END is for the "IF".
>>> END; // <-- This END is for the "ELSE".
>>>
>>> I recommend to use "BEGIN ... END" blocks in nested "IF" always to
>>> prevent this kind of mistakes.
>>>
>>
> In general I agree, but in this case there are no nested ifs, so it won't
> help here.
>
> Mattias
>
>
>
> _______________________________________________
> fpc-pascal maillist - fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
>
--
Frank Church
=======================
http://devblog.brahmancreations.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20100701/060f12e5/attachment.html>
More information about the fpc-pascal
mailing list