Jump to content
Sign in to follow this  
mvanrijnen

[D11.2 VCL] Invalid Type Cast exception with inherited vcl controls

Recommended Posts

Hi,

Having a problem with an inherited control of TGroupBox/TCustomGroupBox

 

the line  var GroupBox := Control as TCustomGroupBox; in following Vc;.StdCtrls method goes wrong (Invalid typecast);

 

 

The inherited control worked always in previois delphi versions, now are we gonna get a lot of problems like this? 

Other people stumbled up on this problem with inherited controsls?

Better, someone knows how to quickly work around this problem?


the code from vcl.stdctrl (D11.2):

 

[edit]

hmz, in a clean project it works, going to dig some more

 

 


procedure TGroupBoxStyleHook.Paint(Canvas: TCanvas);
var
  R, CaptionRect: TRect;
  Details: TThemedElementDetails;
  SaveIndex: Integer;
  LStyle: TCustomStyleServices;
begin
  LStyle := StyleServices;
  if not LStyle.Available then Exit;

  PaintBackground(Canvas);
  CaptionRect := GetCaptionRect(Canvas);
  var GroupBox := Control as TCustomGroupBox;
  if GroupBox.ShowFrame then
    R := GetBoxRect(Canvas);
  if Control.Enabled then
    Details := LStyle.GetElementDetails(tbGroupBoxNormal)
  else
    Details := LStyle.GetElementDetails(tbGroupBoxDisabled);

  SaveIndex := SaveDC(Canvas.Handle);
  try
    ExcludeClipRect(Canvas.Handle, CaptionRect.Left, CaptionRect.Top,
      CaptionRect.Right, CaptionRect.Bottom);
    if GroupBox.ShowFrame then
      LStyle.DrawElement(Canvas.Handle, Details, R);
  finally
    RestoreDC(Canvas.Handle, SaveIndex);
  end;
  DrawControlText(Canvas, Details, Text, CaptionRect,  Control.DrawTextBiDiModeFlags(DT_VCENTER or DT_CENTER));
end;
Edited by mvanrijnen

Share this post


Link to post

fixed .... 

Was a trick for the custom component to paint like a GroupBox, so the GroupBoxStyleHook was registred for it. 

Made an own stylehook, and now it works 🙂

 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×