Create a new component compatible with VCL and FMX
Asked Answered
A

3

6

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

Adjudication answered 2/1, 2013 at 12:3 Comment(6)
What kind of components do you have? Visual or Nonvisual?Nonconformity
@Sir Rufo they are a non visual componentsAdjudication
non visual components are not related to VCL or FMX. why would you seperate? Do you think TADOConnection is different in VCL and FMX?Nonconformity
@Sir Rufo this components have some properties (like Color) that are dependent of framework (in VCL is TColor and in FMX is TAlphaColor) and/or need some libraries that are dependence of framework (like Dialogs)Adjudication
@Cadetill If your component is referencing Colors and Dialogs, then your component is not truly non-visual. Consider refactoring out those references or seperating it into a run-time and a design-time package.Rhpositive
@Alan Clark The components that I'm doing are to manage the Google Maps API. In them I specify the features of the map, markers, polylines,.... That is why I can't separated into different packages their properties.Adjudication
A
6

Well, after a long search I have asked in the Embarcadero forum. There, Remy said 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);

The answer on Embarcadero forum here

Adjudication answered 7/1, 2013 at 8:39 Comment(0)
P
0

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.

Pugh answered 2/1, 2013 at 12:13 Comment(1)
How will that help? Why would knowing whether or not the Delphi IDE was a VCL or FMX app be relevant?Commonwealth
E
0
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.
Empoverish answered 10/7 at 15:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.