How to Create a Vcl-Theme-Style for my own Component? - delphi

I use the BitmapStyleDesigner.exe (shipped with delphi xe5) to edit vcl styles to my application.
How can i add a custom component to the styler palette? i want my TMyButton, which inherits TButton, have a different color, shape, etc than the standard TButton.
Can this be done only by editing the style, or do i have to edit the source of TMyButton?
The embarcadero wiki hadn't helped (so far).
Thanks in advance!

Editing the VCL Style file is not enough. Unfortunately the VCL Styles are not designed to be extensible on the manner which your describe, Even if is technical possible do that, what you describe will require a lot of work. because you must modify the source of the Vcl.Themes and the Vcl.Styles units. My recommendation is not modify the style file, instead create a new style hook for your button and implement the paint code your self loading the images from a resource file.

Related

How to inherit component palette icons (*.dcr files) for custom components?

In the past, I have written custom components for Borland C++Builder. Some of these were derived from existing components, for example:
class PACKAGE TMyEdit : public TEdit
{
...
}
For some of these, I have also made custom bitmaps for the palette (.dcr files). I know how to create and edit them; that's not the point here.
Nowadays, I'm using a newer version of the IDE, Embarcadero C++Builder XE, and I notice a difference in behaviour for components without a .dcr file.
In the old days, the bitmap on the palette would be the same as the one where the component was derived from. Let's say the TMyEdit had the same bitmap as the TEdit.
But now, these components get a default icon. So all components without a .dcr file look alike on the palette.
I see 2 possible ways to solve this:
Is there perhaps some way to indicate in the source files that I want to inherit the bitmap of the original component?
If that isn't possible, I'll have to create new .dcr files for each new component. Is there a neat way to retrieve the original bitmaps? Perhaps there exists a resource file? Or an option in a wizard that I haven't found yet? If not, I'll have to resort to using Alt-PrtScn and MSPaint. That would work, but it would be tedious.

How to patch TSpinEdit to use Vista/Win7 visual style?

Win7 must give ok style for TSpinEdit, but I see outdated style:
So arrows are not themed, and buttons are old.
I use Delphi7. How to patch VCL to fix style?
OK is:
I don't know if Delphi 7 already had it but you can use TEdit in combination with TUpDown and then set the Association property of the TUpDown to your TEdit.
TSpinEdit is a custom VCL control. There is no Windows control with that functionality. Even in the latest version of Delphi it looks exactly the same as in Delphi 7. And it's really rather ugly isn't it?
The control, in modern Delphi, is implemented in a unit named Vcl.Samples.Spin. Looking at the documentation for the Vcl.Samples namespace we have:
Contains the units for several sample VCL components delivered with RAD Studio - a calendar, an outline, a gauge, and a spinbutton.
The unit will be named differently in Delphi 7, but the principle is the same. These are sample controls, supplied with source code.
So, what you may do is take a copy of the TSpinEdit code, and modify the painting. Change the button drawing to be how you wish it to be.

How to change the default FireMonkey style in Delphi XE2

I saw a youtube video (can't remember which one) where the user changed an option in Delphi XE2 to change the default style for an entire FireMonkey application. After much hunting I can't find the option.
IDE Insight for 'style' shows me 'Default Style - Custom Styles (Forms)' under 'Project Options'. But unless I'm being particularly thick, there's no such option there.
VCL Styles and Firemonkey Styles are fundamentally different.
Because of that I am not sure they should have used the same name.
VCL Styles
Edited through: Tools|Style Designer (External App)
Style Extension .VSF
Format is Binary
Can be set through: Project Options|Application| Appearance (Which just add TStyleManager.SetStyle('StyleName'); to your code
Runtime control of styles can occur through the TStyleManager class
Firemonkey Styles
Editor is Internal to the IDE
Accessed through TStyleBook Resource Property Editor
Can also be accessed by Right click on any visual control and selecting either
Edit Custom Style...
Edit Default Style...
Note: These two menu choices are only available in desktop apps, not mobile apps.
Once in editor you can select the Load.. button to change the style for the selected TStylebook. If the entire application is using the same TStyleBook it will change the whole application.
Style Extension .style
Format is like a DFM
Runtime control of styles can occur on each control and through the TStyleBook
On windows 7 all of the styles both VCL and Firemonkey by default are placed in the
C:\Users\Public\Documents\RAD Studio\9.0\Styles directory
One bullet point is a direct answer, but I felt like I had to give the long answer to help others.

Transparent checkbox with theme-support?

I'm looking for a simple, transparent checkbox component that properly supports XP/Vista/7 theming.
It should also work with Delphi 7.
I've found a component on Torry's that's not working properly, and I know that Raize components has a transparent checkbox - but I'm obviously not going to pay $300 for the entire package just to get this single component.
I've also found many other solutions, but none of them support theming.
The main problem is that TCustomCheckBox is a TWinControl descendant, and in order to implement transparency, you need to make a new TGraphic descendant control from ground up.
Any ideas?
LMD-Tools SE is free, works great on Delphi 7 and has a checkbox component that has a transparency property. I've recently used TLMDCheckbox with its transparency property enabled with Delphi 7.
http://www.lmdinnovative.com/download/index.php#LMD
Download file: setupse10d7.zip. Sorry, I can't post the whole path (url) since I don't have enough juice yet.
This should fix you up :).
ShawnH.
Raize Components is overkill for just this component, but much more capable and supports transparency in a whole load more components. Once you have it, you'll appreciate the other items greatly. I'd say it is the solution you are looking for.
If you can accept an alternative control there is JvXPCheckCtrls.pas with its TJvXPCheckbox component in the JVCL library. http://jvcl.delphi-jedi.org
I think (if I remember correct) it is transparent when themes are used.
It's quite a large package which will add to vcl with the installation of Jvcl. And it doesn't cost you a cent.
But remember, the TJvXPCheckbox component is part of their XP-controls package and you cannot simply lift out the component as a standalone. You will need the installation of Jedi and to get the core code and necessary theme handling to use it.
- Its Mozilla Public Licence ("MPL") version 1.1.
I use AlphaControls for some of my programs - all of their components are skinnable and have reasonably powerful graphics handling options. A lot of the components also have more features than their corresponding Delphi standard components - some I just use for those functions alone. There's a free Lite version available at www.alphaskins.com - it may just be what you're after. It's not Vista/7 theme-aware, mind you. We use Delphi 2010 and vista/7 theme awareness is built into the standard VCL there, although that's probably not the solution you were hoping for.
Not sure if this will help, but I ran into what I think is the same problem when working with the TMSSmooth controls: the label of a checkbox place on a form looked terrible because it was not transparent.
Their demo/example programs had nice looking checkboxes so I took a look at their sample code.
Turns out they reduced the width of the checkbox component to 13 so that only the box itself and no caption shows. Then they added a TLabel for the caption.
Seemed like a clever workaround to me.
Hope this helps.

Best Way to Replace a Visual Component in Delphi

In a Delphi Form, I would like to replace one visual component with another. Example: I want to replace a Panel component with an ElPanel from a 3rd party package.
I would like all identical properties and events of the first component to be transferred to the new one, and all the components that belong to the first component (e.g. Toolbars, memos,status bars, etc.) to end up placed on the new component exactly where they were on the first one.
Is there a best/easiest way to do this other than adding the new component to the form and meticulously transferring every property, event and component to it one-by-one?
I do it as following:
Right click on the form and choose (View as Text).
Press Ctrl + F to search for the Component class name like TPanel and replace it with TElPanel
Switch back to back to the form (View as form)
In the interface section replace the TPanel with TElPanel.
if you have many components using GExperts will be more feasible solutions.
You can use GExperts or you can do it by hand.
To do it by hand, open the .dfm in notepad and replace all the class names. (Replace TPanel with TElPanel for example). When you've made all your changes, open the .pas file with Notepad, and do the same thing.
Make sure you add the required units to your uses clause.
Then open the form in the IDE and clean up any mismatched events or unknown property problems.
If I recall the excellent free GExperts plugin does this. Right click your form and select "Replace Components". http://www.gexperts.org
IMHO, the big drawback of the Replace component GExpert is that it changes the order of the components in the source code. That is not very VCS friendly. :-)
If you have other components inside a container doing this replacement with GExperts will cause some ugly exceptions and possibly unexpected behaviour in the IDE.
So, the best solution is to edit the .dfm file where you want (inside or outside the IDE) and replace manually the types of the components that you want to change. Maybe it will cause some exceptions too, but the IDE will managed them.
If you do it inside the IDE, after switching to design view if you save the .dfm inmediately the IDE will ask you to change the type of the variables related to the components you touched, liberating you to do it.
To convert between text and binary dfm formats, use the convert.exe tool in the Delphi bin\ directory. – Tim Knipe (Oct 28 at 4:15)
You can also use the context menu of the form designer - at least with BDS 2006. It's the last menu item ("Text-DFM" in a German IDE).
In my project I had to convert few doezens forms from one set of components to another.
I have created small perl script to convert components and its properties and do all neccesary mapings.
The script is quick&dirty solution but it is highly configurable. It scanns all dfm and pas files in project direcotory and convert dfm components definitions according to rules that you should provide in ObjectBeginFound, PropertyFound, ObjectEndFound procedures/events.
DFM files should be in text mode. Tested on Delphi 5 files. I don't know if it will be compatible with newer versions. Please send posts if you find it out.
USAGE:
perl.exe cxdfm.pl > logfile.txt
DOWNLOAD LINK
http://dl.dropbox.com/u/15887789/cxdfm.pl

Resources