Creating a styled VCL component - c++builder

I am trying to create a custom VCL component in C++ Builder 10.1 Berlin that is derived from TGraphicControl and kind of looks like a TProgressBar.
I want it to draw itself using the Windows Theme system. In order to do this, I have included Vcl.Themes.hpp in my source code, and overwritten the virtual Paint() method to call the TCustomStyleServices::DrawElement method.
The problem is the 64 bit linker complains that Vcl::Themes::TCustomStyleServices::DrawElement cannot be resolved.
How do I satisfy the linker?

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.

Delphi - How to correctly register a graphic class since XE8?

I'm writing a Delphi package, which provides a new custom TGraphic object, allowing to read a new image format in VCL components like TImage.
I originally developed this package with RAD Studio XE7, and it worked well. However I migrated recently to a newer RAD Studio compiler version, and although my package continues to work properly on that new version, I noticed a strange bug that never appeared before.
I have a form with several components, some of them are TImage components. Immediately after opening the IDE, the first time I open my project in design time, all the TImage components containing my custom TGraphic component loose their content. If I close then reopen the project, the images reappear, and the bug no longer happen until I close and reopen my IDE.
I dug in my code to understand what may cause the issue. To register my custom TGraphic component, I use the class initialization section, in which I wrote the following code:
initialization
begin
Vcl.Graphics.TPicture.RegisterFileFormat('svg', 'Scalable Vector Graphics', TWSVGGraphic);
end;
However I found that, since the XE8 compiler version, the TImage constructor is called before my initialization section, causing thus apparently the above mentioned issue. All the compiler versions since XE8 are affected, but this bug never happened on XE7 or earlier. So something changed since XE8.
Here are my questions:
Is the way I use for register my custom graphic class correct?
If not, what is the correct way to do that?
As something seems different since XE8, what it the new correct manner to register my graphic component?
Did anyone else faced the same issue? How he resolved it?
Is this may be a new RAD Studio bug, or the issue is rather on my side?
This is most likely a side effect of the smart loading the IDE applies to design time packages. You can overwrite this behavior by calling ForceDemandLoadState(dlDisable) during the Register procedure of your package.
More about this can be found in the documentation of more recent versions of Delphi than XE8: Explicitly disabling smart loading of components in a design-time package

Add fmx form to Delphi Package

As the title says really. How can I add an FMX form to a delphi package? In the package I have a Tpanel descendant component - which is all installed fine. What I'd like to do is include a form in the package so that when I click on the panel at runtime the form pops up for example. (I don't want to use the FMX form at design time - just at runtime, so I just want to include the FMX form as in the package, the component has design time properties though)
It seems I can only add a VCL form to the package - when I right click and 'add new' to the package, it tries to add the VCL to the package - which I don't want. I want to run it on OSX.
I've found plenty of adding VCL forms e.g. Adding forms and frames to packages probably something obvious I'm missing - tia
Delphi XE6 on Windows 8/OSX target
Packages have affinity to a particular framework. Your package appears to be a VCL package. In the .dproj file you will find
<FrameworkType>VCL</FrameworkType>
Change this to
<FrameworkType>FMX</FrameworkType>
to have affinity to FireMonkey.
Although I've not done so recently, I expect that you get to make the framework affinity choice when you create the package. Presumably you chose VCL. Or the package was created before FMX existed and the project upgrade process added (correctly) the VCL framework setting.

Error: F1026 File not found: 'System.Actions.dcu' switching back to Delphi XE2 from XE3

I'm moving my code to Delphi XE3 from XE2, but it should compile in both. I notice that some units get 'System.Actions' auto added to the USES clause. This then causes an error when returning to XE2 with:
F1026 File not found: 'System.Actions.dcu' (unit scope "System" indicates Win64, OSX32, Win32 only)
I've never really understood unit scope properly. Is there a correct solution to resolve this rather than wrapping stuff within compiler version {$IFDEF}'s?
Thanks
There is no Actions unit in XE2. It is new in XE3, as part of refactoring work to bring Actions support into FireMonkey. This is documented:
What's New in Delphi and C++Builder XE3:
Actions: FireMonkey now supports actions and action lists, two features that were previously supported only in VCL:
Important: Every FireMonkey or VCL application that uses actions must specify the System.Actions and System.Classes units in the uses section.
Changes in Implementation of VCL Actions
The System.Actions unit is created in the RTL package. Classes from the Vcl.ActnList unit that provide framework-independent action features are moved into this unit. Classes in System.Actions extend the most fundamental behavior of action features introduced in the TBasicAction and TBasicActionLink classes.
Important: As a result of these changes, you need to add the System.Classes and System.Actions units into the uses section.
Implementation of Actions in FireMonkey and VCL
FireMonkey (FMX)
The framework-independent implementation is common to FireMonkey and VCL:
This basic actions functionality is extended in the new System.Actions RTL unit.
VCL
Framework-independent action features that were implemented in the Vcl.ActnList unit in previous RAD Studio releases are now in the new System.Actions unit in the RTL (common to VCL and FireMonkey).
Important: As a result of these changes, you need to add the System.Actions unit to the uses section (or #includes) in your VCL applications that use actions.
You will have to either remove the reference to Actions if you are not actually using actions in your code, or else {$IFDEF} it out.
What Remy said is quite correct, but there may be an easier way to make your code work in both XE2 and XE3. Simply add a unit alias from System.Actions to Vcl.ActnList.
Add this in your project options, on the Delphi Compiler page. You need to add the following:
System.Actions=Vcl.ActnList
Note that if you need to compile in both XE2 and XE3 using the same .dproj file then you are out of luck. That unit alias setting will stop the program compiling under XE3. However, if you have have different .dproj files for XE2 and XE3, then this will allow you to use the same source in both. Or, if you only need to compile for XE2 at the command line, then you could add this unit alias there. I can't tell whether or not this will help you, but I know that the unit alias feature has helped me out of a similar spot on more than one occasion in the past.
If you have ONE project file you still can solve the problem with a "dummy" System.Actions.pas file in your project path directory:
This file will be taken under XE2.
The XE3 compiler will find his System.Actions.dcu in the IDE /lib directory.
Anyway: In normal cases you should use different project files - then the solution with the unit alias is recommended.
The dummy System.Actions.pas could look like:
unit System.Actions;
(*
XE2 compatibility unit: since XE3 unit System.Actions will be inserted into every
interface in units which use actions.
compilerswitch in [uses] is ignored by IDE - so this solution enable successful
compilation in XE2 with same project file than XE3
*)
interface
implementation
end.

Adding new property to TMS control "TAdvSmoothDock" but it doesn't appear in the Object Inspector

I'm trying to add a new property (Images: TImageList) to the TMS Control "TAdvSmoothDock" but the property doesn't appear in the Object Inspector
I defined it under "Published" as following :
Published
property Images: TImageList read GetImages write SetImages;
I can compile it but the property doesn't appear in the Object Inspector.
it does appear in the delphi IDE when using the control in the code:
like :
AdvSmoothDock1.Images := ImageList1;
currently I'm using Delphi XE2 VCL.
Regards.
You need to rebuild the TMS packages that contain the component, not just change the source code.
The Object Inspector doesn't use the code source to figure out what to display. It uses RTTI (run-time type information) it gets from the compiled version in the runtime package that contains the component (or the designtime package if there is no runtime package available.
Figure out what package the TMS component is in, open that package's source in the IDE (the .dproj file for the package), and do a build of that package. Make sure it's seeing your version of the source instead of the normal TMS version, so your changes are used.
(Of course, the proper way to do this would be to create your own descendant of the TAdvSmoothDock, add the property, put it into your own package that uses the TMS one, and never touch the TMS source code.)

Resources