View Issue Details

IDProjectCategoryView StatusLast Update
0004294JEDI VCL00 JVCL Componentspublic2007-11-30 13:58
ReporterbheAssigned ToAHUser 
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;
  I: Integer;
  TextWidth: Integer;
  tHDC: HDC;
  tS: TSize;
  FActiveBlockWidth := 0;

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

    if TextWidth >= VSChannel.ActivePaneSize then
      FActiveBlockWidth := VSChannel.ActivePaneSize;

    FActiveBlockWidth := Max(FActiveBlockWidth, TextWidth);

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

TagsNo tags attached.



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