Reputation: 1572
I'm doing some components and I want to do them compatibles for VCL and FMX. So I have a structure that follows this pattern:
General_dpk (with TCustomMyClass) + VCL_dpk (with TMyClass) + FMX_dpk (with TMyClassFMX)
Each package have their register procedure that registered their components. In the components palette appears both components (VCL and FMX). How to do that only appears the components according the type of project selected (VCL or FMX) like the others Delphi components?
Thanks
Upvotes: 7
Views: 2237
Reputation: 1572
Well, after a long search I have asked in the Embarcadero forum. There, Remy told me the answer kindly (easy when you know it). The thing is that you need to call GroupDescendentsWith function into the register procedure like this
// para componentes VCL
GroupDescendentsWith(TMyClass, Vcl.Controls.TControl);
// para componentes FMX
GroupDescendentsWith(TMyClassFMX, Fmx.Types.TControl);
(This answer is from the now defunct Embarcadero forum.)
Upvotes: 7
Reputation: 11
For programs that use FMX, FmxBeepButton must be defined in the project defines.
//unit BeepButton;
// This is BeepButton.INC
interface
uses
{$IFDEF FmxBeepButton}
FMX.Types, BeepButtonFmxAncestor
{$ELSE}
BeepButtonVclAncestor
{$ENDIF}
;
Type
TBeepButton = class(TCustomBeepButton)
public
procedure Click; override;
end;
implementation
{ TBeepButton }
procedure TBeepButton.Click;
begin
inherited;
DoBeep;
end;
end.
unit BeepButtonFmxAncestor;
interface
uses
System.SysUtils, System.Classes, FMX.Types, FMX.Controls,
FMX.Controls.Presentation, FMX.StdCtrls;
type
TCustomBeepButton = class(TButton)
private
{ Private declarations }
protected
procedure DoBeep;
{ Protected declarations }
public
constructor Create(AOwner: TComponent); override;
{ Public declarations }
published
property Position;
{ Published declarations }
end;
implementation
{ TCustomBeepButton }
constructor TCustomBeepButton.Create(AOwner: TComponent);
begin
inherited;
StyleLookup := 'Buttonstyle'
end;
procedure TCustomBeepButton.DoBeep;
begin
Beep;
end;
end.
unit BeepButtonVclAncestor;
interface
uses
System.SysUtils, System.Classes, Vcl.Controls, Vcl.StdCtrls;
type
TCustomBeepButton = class(TButton)
private
{ Private declarations }
protected
procedure DoBeep;
{ Protected declarations }
public
{ Public declarations }
published
{ Published declarations }
end;
implementation
{ TCustomBeepButton }
procedure TCustomBeepButton.DoBeep;
begin
Beep;
end;
end.
unit VCL.BeepButton;
{$INCLUDE BeepButton.INC}
unit VCL.BeepButtonRegister;
interface
uses
Classes, Vcl.Controls, VCL.BeepButton;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Samples', [TBeepButton]);
GroupDescendentsWith(TBeepButton, Vcl.Controls.TControl);
end;
end.
unit VCL.BeepButton;
{$INCLUDE BeepButton.INC}
unit VCL.BeepButtonRegister;
interface
uses
Classes, Vcl.Controls, VCL.BeepButton;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Samples', [TBeepButton]);
GroupDescendentsWith(TBeepButton, Vcl.Controls.TControl);
end;
end.
Upvotes: 0
Reputation: 14160
You can use in the Register procedure code from this answer : Delphi XE2: Is there a predefined conditional to identify VCL and FireMonkey? to check whether it is Firemonkey or VCL application.
Upvotes: 0