Archive for the ‘VCL’ Category.

VCL Ribbon – Ribbon Group Component Editor

I’ve created a component editor specifically for the TRibbonGroup component. With this component editor it will hopefully make it a little easier to layout your ribbon groups.

It has a number of commands for adding controls to the group as well as changing the alignment and vertical row count for the group.

Download

Delphi 2010 version

Delphi 2009 version

Install

  1. Open up your Delphi version.
  2. Select the Components | Install Packages menu item.
  3. Click on the Add button and select the extracted BPL from the downloaded zip file.

The component editor should now be available when you click on a group on the ribbon.

Some screen captures

Available commands for the Component Editor

Available commands for the Component Editor

When you select a command, you can also choose what actions to create as that command.

When you select a command, you can also choose what actions to create as that command.

You can create the different types of Small and Large buttons. NOTE: Selecting the dropdown button is a little different to the others.

You can create the different types of Small and Large buttons. NOTE: Selecting the dropdown button is a little different to the others.

When you are creating a dropdown button you are selecting that actions that should be added to the button as dropdown items. Only one button is created. You can also enter in the button caption.

When you are creating a dropdown button you are selecting that actions that should be added to the button as dropdown items. Only one button is created. You can also enter in the button caption.

VCL Ribbon – Context Tabs

Context Tabs was bought up in a comment to my MDI post.

I’ve been putting considerable effort into getting this working for one of my personal projects. I think it looks pretty good.

Design Time

Design Time

 

Runtime

Runtime

 

Runtime (second tab)

Runtime (second tab)

Unfortunately it isn’t viable to release these changes to the public. This just proves that it is possible though!

If you posted a comment on the previous post, I’ve responded to all comments now.

VCL Ribbon MDI Fix

Disclaimer: I wrote the VCL Ribbon implementation in Delphi 2009. At the time there was no scope for MDI support in the Ribbon however the number of posts about this issue made me look into fixing it. Today I set aside some time to look at a solution and I now present this solution.

The MDI Ribbon bug is evident when your application is a MDI application and the MDI Children are maximized. The screen capture below shows this bug.

VCL Ribbon MDI Bug

VCL Ribbon MDI Bug

The fix is to drop a new component onto the Form with the Ribbon on it. Then you just need to set the Ribbon property to be the TRibbon component on the form, that is all that needs to be done.

The screen shot below shows the component at design time.

VCL Ribbon MDI Bug Fix

VCL Ribbon MDI Bug Fix

When you toggle the Enable MDI Fix check box, you need to restore and maximum a MDI Child form. For real use, you wouldn’t want to disable it anyway.

Various screen captures of the demo application with the fix active.

Fixed Ribbon MDI Bug

Fixed Ribbon MDI Bug

Fixed Ribbon MDI Bug

Fixed Ribbon MDI Bug

Fixed Ribbon MDI Bug

Fixed Ribbon MDI Bug

 

Downloading the Fix

You can download the component and demo application from my site. I may also put the fix on CodeCentral in future.

Ribbon VCL MDI Bug Fix Download

To install the component into the IDE, open the RibbonMDIFix2010.dpk file in Delphi 2010 (should also work, but is untested). In the project manager, select the Install command. Make sure the path to the RibbonMDIFix.pas unit is on your library path so that the compiler can find the file when compiling your application.

 

Further Ribbon Details

If you search for my QualityCentral entries on the Ribbon, most of the issues I raise I also provide the workaround for. Most are simple changes that can be done by copying the Ribbon units into your project folder. IIRC none are interface breaking (I’ve saved those).

 

Performance issue with MDI Applications using the TActionManager framework

There is also an issue with the MDI “detection” when a TActionMainMenuBar component (and descendants) are used in an application. This is actually a bug that was raised with Borland/CodeGear support several years ago. When you have an action that calls GetActiveMDIChild you may see processor usage increase significantly. On the Window group in the application feature throughout this post you’ll see the Close button. This is the TWindowClose standard MDI action. This actions update handler calls ActiveMDIChild. If you are running an MDI application that utilises TActionManager CPU usage will increase because of this. This occurs because of the Window Hook installed for menu processing. It handles the WM_MDIGETACTIVE message, so if an action is calling that method, the window hook is also processing it.

My solution (which also uses a window hook) avoids increasing CPU usage unnecessarily by listening to more specific MDI messages. There is no need to listen to the WM_MDIGETACTIVE (that I can see).

Themed Grids in Delphi 2010

I was reminded of a new feature in Delphi 2010 when someone recently posted a new comment on a very old blog post. It was the post about my CodeCentral entry that provided a themed TDBGrid component.

In Delphi 2010 the TStringGrid, TDrawGrid and TDBGrid components now have a DrawingStyle property. The default value for this property is gdsThemed which means all grids in your Delphi 2010 applications will be themed by default. If you application isn’t themed, then your grids will use the gdsClassic style, which is how they appeared before Delphi 2010.

You actually get three different drawing style options. Themed, Classic and Gradient.

  • The Classic style is just the previous drawing style.
  • The Themed style uses the current theme information (if enabled) .
  • The Gradient style uses two new properties called GradientStartColor and GradientEndColor to paint the fixed row cells.

The following screen captures show each of the new styles.

Grids Classic Drawing Style

Grids Classic Drawing Style

Grids Themed Drawing Style

Grids Themed Drawing Style

Grids Gradient Drawing Style

Grids Gradient Drawing Style

Indicator Painting Issue

If you strain your eyes for long enough, you might see a painting issue with the Themed and Gradient drawing style images above. To be fair, I didn’t notice it until I wrote the sample application to demonstrate the feature. I had a look to see if the issue has been raised in QualityCentral yet and it hasn’t.

The issue is a lot more obvious when you change the gradient colors a little. As shown in the screen shot below.

Grids Gradient Drawing Style Issue

The indicator transparency issue

The indicator isn’t drawn as transparent. This is a simple fix and only occurs for the TDBGrid component since the indicator isn’t valid for the other grids. Internally the indicator image is stored in a TImageList. When the image from the image list is drawn it isn’t drawn with transparency.

The Fix

  1. Copy the DBGrids.pas file to your applications folder. It is located in the <InstallDir>\Source\Win32\DB folder.
  2. Search for FIndicators.Draw (There is only one occurrence in the entire unit located in the DrawCell method of TCustomDBGrid.)
  3. Change the line under the FIndicators.Draw line to the following:
(ARect.Top + ARect.Bottom - FIndicators.Height) shr 1, Indicator, dsTransparent, itImage, True);

The red bolded parameters are the additional parameters added to the Draw method call (which starts on the preceeding line).

The following screen shot was created with the above fix applied to the DBGrids unit.

Grids Gradient Drawing Style Issue Fixed

The indicator transparency issue fixed

It’s a shame the indicator is not actually exposed for easy customisation. Even more of a shame is the inability to customise the move column painting.

Source Code

The source code and a compiled executable is available for download.

Source Code Download

D2006: What on earth are these Explicit* properties in my DFM

If you need to make sure your application can still be compiled in previous Delphi versions you need to watch out for some new properties that are added by Delphi 2006 to your DFM. These new properties are for all TControl descendants and are called ExplicitTop, ExplicitLeft, ExplicitHeight and ExplicitWidth. These are not actually published properties; you won’t find them in the object inspector.

The Explicit* properties remember the previous bounds of a control before the Align or Anchor properties are changed from their defaults. The only time the Explicit* properties are not written is when the Align property is set back to its default value of alNone. This is when the Explicit* properties are actually used by the control to reset its bounds to what it was previously.

You can download the example here to play along at home if you like (executable included):
http://www.jed-software.com/files/ExplicitProps.zip

This example takes a TPanel and changes its align property value from

alNone -> alClient -> alNone

Example Usage:

  1. Run the application
  2. Click on the Get Values button
  3. Values from Figure 1 are displayed in the Memo control
  4. Click on the Align Client button
  5. Click on the Get Values button again and Figure 2 displays the added Memo control contents
  6. Click on the Align None button
  7. Click on the Get Values button a final time and the Memo control should have the same values added to it that were added in Step 3.

So what has changed?
In previous Delphi versions if the align property was changed to alClient and then back to alNone, the control would stay as if it was aligned client still. These new properties mean that the original bounds is restored when this occurs. As noted with the example.

When the panel was aligned client it up the left over client area of the form; as expected. When clicking on the Align None button the panel was restored back to its size prior to setting Align to alClient.

If you want to know the specific conditions for having these properties written to the DFM check out the DoWriteExplicit function in the DefineProperties method for TControl.

Figure 1

Align is alNone

ExplicitTop: 40

ExplicitLeft: 256

ExplicitHeight: 185

ExplicitWidth: 329

Top: 40

Left: 256

Height: 185

Width: 329

----------------------
Figure 2

Align is alClient

ExplicitTop: 40

ExplicitLeft: 256

ExplicitHeight: 185

ExplicitWidth: 329

Top: 0

Left: 193

Height: 456

Width: 450

----------------------