Reputation: 4193
Delphi manages to have TLabel
exist in FMX and VCL. So, how do I create two components, both with the same name, except one is for VCL and one is for FMX?
Yes, I know I can use ifdef
s and recompile the library every time. But that is not exactly clean code.
Upvotes: 3
Views: 211
Reputation: 596166
Implement your two components in different Unit Scopes, which were created for this exact purpose.
For example, implement TMyComponent
for VCL in Vcl.MyUnit.pas
, and implement TMyComponent
for FMX in FMX.MyUnit.pas
.
Then, to use TMyComponent
in any other unit, you can either:
use {$IFDEF}
s to conditionally specify Vcl.MyUnit
or FMX.MyUnit
in the uses
clause.
create separate projects for VCL and FMX, where the VCL project specifies Vcl
in its Unit Scope Names compiler setting, and the FMX project specifies FMX
, and then you can use just MyUnit
in the uses
clause.
Also see Adding Unit Scope Names for Your Own Components.
For reference, VCL's TLabel
is in the Vcl.StdCtrls
unit scope, and FMX's TLabel
is in the FMX.StdCtrls
unit scope.
Upvotes: 12