how to manage invalidate between two tvirtualstringtree in same form?

drama22
drama22 used Ask the Experts™
on
i have two tvirtualstringtree in a form i wanted to invalidate them using timers

but i stuck with problems it seems that only 1 VST got invalidated and the other one ignored any idear why ?

i use invalidate with current code within timer

procedure Tform1.Timerval1Timer(Sender: TObject);
{$J+}
Const
iCount: Cardinal = 0;
{$J-}
begin
Inc(iCount);
if (iCount * TTimer(Sender).Interval) > 500 then
begin
xbool := NOT xbool;
iCount := 0;
end;
VDT1.Invalidate;
end;

procedure Tform1.Timerval2Timer(Sender: TObject);
{$J+}
Const
iCount: Cardinal = 0;
{$J-}
begin
Inc(iCount);
if (iCount * TTimer(Sender).Interval) > 500 then
begin
xbool := NOT xbool;
iCount := 0;
end;
VDT2.Invalidate;
end;

Open in new window


issue happens when i use beforecellpaint on each VSt

procedure Tform1.VDT1BeforeCellPaint(Sender: TBaseVirtualTree;
  TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
  CellPaintMode: TVTCellPaintMode; CellRect: TRect; var ContentRect: TRect);
var
Data: PUserdataon;
NewRect: TRect;
xOff, yOff: Integer;

begin
GradientFillCanvas(TargetCanvas, clred, clWhite, CellRect, gdHorizontal); // GraphUtil

if not Assigned(Node) then
begin
exit;
end;

Data := vdt1.GetNodeData(Node);

begin
NewRect := CellRect;
NewRect.Left := NewRect.Left + 2;
NewRect.Width := 24;
NewRect.Top := NewRect.Top;
NewRect.Bottom := NewRect.Bottom;
xOff := CellRect.Left + 70;
yOff := CellRect.Top +((30 - TargetCanvas.TextHeight('H')) div 2);
if xbool or (Data.FObject.bool= false) then
TargetCanvas.font.color := clred
else
TargetCanvas.font.color := clgray;
TargetCanvas.TextOut(xOff, yOff, Data.FObject.Username);

end;

end;

//vdt2 paint

procedure Tform1.VDt2BeforeCellPaint(Sender: TBaseVirtualTree;
  TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
  CellPaintMode: TVTCellPaintMode; CellRect: TRect; var ContentRect: TRect);
var
Data: PUserdataoff;
NewRect: TRect;
xOff, yOff: Integer;

begin
GradientFillCanvas(TargetCanvas, clred, clWhite, CellRect, gdHorizontal); // GraphUtil

if not Assigned(Node) then
begin
exit;
end;

Data := vdt2.GetNodeData(Node);

begin
NewRect := CellRect;
NewRect.Left := NewRect.Left + 2;
NewRect.Width := 24;
NewRect.Top := NewRect.Top;
NewRect.Bottom := NewRect.Bottom;
xOff := CellRect.Left + 70;
yOff := CellRect.Top +((30 - TargetCanvas.TextHeight('H')) div 2);
if xbool or (Data.FObject.bool= false) then
TargetCanvas.font.color := clred
else
TargetCanvas.font.color := clgray;
TargetCanvas.TextOut(xOff, yOff, Data.FObject.Username);

end;

end; 

Open in new window


To be mor spicific issue happen when i try to draw blink text with

if xbool or (Data.FObject.bool= false) then

Open in new window


is my timer for blink text has issue ?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2016
Commented:
you might try to exchange VDT1 with VDT2 in the timer procedures. then you could see whether timer2 was working at all.

generally, a control should be invalidated if it needs painting. a timer is not very suitable for this. you should invalidate after you added or removed nodes from tree control. or if you moved, resized, or scrolled the list. Windows is a responsive System. the next time when it checks whether a form or its controls are "dirty" it would recognize that the trees need painting and would issue a wmpaint message. with a timer you may spoil this well-defined system since while a form was repainted the form and its controls were locked and invalidation by the timers might fail because of that.

Sara

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial