<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body bgcolor="#FFFFFF" text="#000000">
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<br>
<br>
One thing I noticed is this: If the with block is more involved than
a simple element, such as this:<br>
<br>
with Owner, FHeader, FFixedAreaConstraints, TreeView do begin<br>
<br>
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.<br>
<br>
Since there's that workaround, I can live with that caveat.<br>
<br>
But, I think the one below is a bug:<br>
<br>
Here is the original code:<br>
<br>
procedure TVirtualTreeColumns.UpdatePositions(Force: Boolean =
False);<br>
var<br>
I, RunningPos: Integer;<br>
begin<br>
if not FNeedPositionsFix and (Force or (UpdateCount = 0)) then
begin<br>
RunningPos := 0;<br>
for I := 0 to High(FPositionToIndex) do<br>
<b>with Items[FPositionToIndex[I]] do </b><b>begin</b><br>
FPosition := I;<br>
FLeft := RunningPos;<br>
if coVisible in FOptions then Inc(RunningPos, FWidth);<br>
<b>end</b>;<br>
end;<br>
end;<br>
<br>
when I explode 'Items[FPositionToIndex[I]]' it becomes this:<br>
<br>
procedure TVirtualTreeColumns.UpdatePositions(Force: Boolean =
False);<br>
var<br>
I, RunningPos: Integer;<br>
begin<br>
if not FNeedPositionsFix and (Force or (UpdateCount = 0)) then
begin<br>
RunningPos := 0;<br>
<b>for I := 0 to High(FPositionToIndex) do</b><b><br>
</b><b> Items[FPositionToIndex[I]].FPosition := I;</b><br>
Items[FPositionToIndex[I]].FLeft := RunningPos;<br>
if coVisible in Items[FPositionToIndex[I]].FOptions then
Inc(RunningPos, Items[FPositionToIndex[I]].FWidth);<br>
end;<br>
end;<br>
<br>
At first sight, it looks OK. It compiles.<br>
<br>
But, it has, silently, intoduced a bug: It has removed the 'begin
end' block that belonged to the 'with' and did not shift it back to
the 'for' loop.<br>
<br>
IOW, it should have been like this. Notice that 'begin' moved to
back to the for-loop block.<br>
<br>
procedure TVirtualTreeColumns.UpdatePositions(Force: Boolean =
False);<br>
var<br>
I, RunningPos: Integer;<br>
begin<br>
if not FNeedPositionsFix and (Force or (UpdateCount = 0)) then
begin<br>
RunningPos := 0;<br>
<b>for I := 0 to High(FPositionToIndex) do begin</b><br>
Items[FPositionToIndex[I]].FPosition := I;<br>
Items[FPositionToIndex[I]].FLeft := RunningPos;<br>
if coVisible in Items[FPositionToIndex[I]].FOptions then
Inc(RunningPos, Items[FPositionToIndex[I]].FWidth);<br>
<b>end</b>;<br>
end;<br>
end;<br>
<br>
<br>
</body>
</html>