[Lazarus] Bug in cody. Exploding a hanging with block.

Mattias Gaertner nc-gaertnma at netcologne.de
Sun Jun 8 22:14:13 CEST 2014


On Sun, 08 Jun 2014 21:50:17 +0300
ListMember <listmember at letterboxes.org> wrote:

> I had some time to spare and I thought I might take a shot at, my long 
> time desire of, getting rid of 'with's in VirtualTrees.pas
> 
> One thing I noticed is this: If the with block is more involved than a 
> simple element, such as this:
> 
>        with Owner, FHeader, FFixedAreaConstraints, TreeView do begin
> 
> you have to start 'exploding' from the right-most element and work your 
> way to the left-most one. Otherwise, the resulting code can become 
> meaningless/uncompilable.

Yes. That's why the tool is in Cody and not in the standard IDE.

 
> Since there's that workaround, I can live with that caveat.
> 
> But, I think the one below is a bug:
> 
> Here is the original code:
> 
> procedure TVirtualTreeColumns.UpdatePositions(Force: Boolean = False);
> var
>    I, RunningPos: Integer;
> begin
>    if not FNeedPositionsFix and (Force or (UpdateCount = 0)) then begin
>      RunningPos := 0;
>      for I := 0 to High(FPositionToIndex) do
> *with Items[FPositionToIndex[I]] do **begin*
>          FPosition := I;
>          FLeft := RunningPos;
>          if coVisible in FOptions then Inc(RunningPos, FWidth);
> *end*;
>    end;
> end;
> 
> when I explode 'Items[FPositionToIndex[I]]' it becomes this:
> 
> procedure TVirtualTreeColumns.UpdatePositions(Force: Boolean = False);
> var
>    I, RunningPos: Integer;
> begin
>    if not FNeedPositionsFix and (Force or (UpdateCount = 0)) then begin
>      RunningPos := 0;
> *for I := 0 to High(FPositionToIndex) do**
> **      Items[FPositionToIndex[I]].FPosition := I;*
>        Items[FPositionToIndex[I]].FLeft := RunningPos;
>        if coVisible in Items[FPositionToIndex[I]].FOptions then 
> Inc(RunningPos, Items[FPositionToIndex[I]].FWidth);
>    end;
> end;

Fixed.


Mattias




More information about the Lazarus mailing list