View Issue Details

IDProjectCategoryView StatusLast Update
0004294JEDI VCL00 JVCL Componentspublic2007-11-30 13:58
ReporterbheAssigned ToAHUser 
PrioritynormalSeveritytweakReproducibilityalways
Status resolvedResolutionfixed 
Product Version 
Target VersionFixed in Version3.34 
Summary0004294: Avoid dirty cast in TJvDockVSBlock.ResetActiveBlockWidth
DescriptionSolution w/o dirty cast could be:

procedure TJvDockVSBlock.ResetActiveBlockWidth;
var
  I: Integer;
  TextWidth: Integer;
  tHDC: HDC;
  tS: TSize;
begin
  FActiveBlockWidth := 0;

  for I := 0 to VSPaneCount - 1 do
  begin
    // <(bhe)>
    tHDC := GetDC(VSChannel.Parent.Handle);
    try
      tS.cX := 0;
      tS.cY := 0;
      Windows.GetTextExtentPoint32(tHDC, PChar(VSPane[I].FDockForm.Caption),
        Length(VSPane[I].FDockForm.Caption), tS);
      TextWidth := tS.cx + InactiveBlockWidth + 10;
    finally
      ReleaseDC(VSChannel.Parent.Handle, tHDC);
    end;
    // </(bhe)>

    if TextWidth >= VSChannel.ActivePaneSize then
    begin
      FActiveBlockWidth := VSChannel.ActivePaneSize;
      Exit;
    end;

    FActiveBlockWidth := Max(FActiveBlockWidth, TextWidth);
  end;

  if FActiveBlockWidth = 0 then
    FActiveBlockWidth := VSChannel.ActivePaneSize;
end;

TagsNo tags attached.

Activities

AHUser

2007-11-30 13:57

developer   ~0014036

The GetDC does not garantee that the returned DC has the same font object selected, so the GetTextExtentPoint32 can return a wrong width. Furthermore the DC could be created outside of the for-loop what would make it faster.

I have changed the code to use the is-operator before typecasting. In the case of a TCustomForm it typecasts using the valid cracker-typecast. If it can't typecast the parent, the VSChannel.ActivePaneSize will be used.

Issue History

Date Modified Username Field Change
2007-11-14 03:57 bhe New Issue
2007-11-30 13:57 AHUser Status new => resolved
2007-11-30 13:57 AHUser Fixed in Version => Daily / SVN
2007-11-30 13:57 AHUser Resolution open => fixed
2007-11-30 13:57 AHUser Assigned To => AHUser
2007-11-30 13:57 AHUser Note Added: 0014036