How to have the same name for vcl and fmx components

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 ifdefs and recompile the library everytime. But that is not exactly clean code.

What do you mean by “recompile the library everytime”?

Delphi has the components in separate units - are you unable to do that?

I’m guessing you’re worried about the IDE throwing an exception when you call RegisterComponent for your FMX TRohit after already having called RegisterComponent for your VCL TRohit. Is that correct?

If TRohit is a non-visual component then you most likely only need to call RegisterComponent once for it and it will be available for both VCL and FMX.

If TRohit is a visual component then the FMX and VCL versions need to be different classes in different units (and probably different packages too). In this case RegisterComponent and the IDE are smart enough to know that your FMX and VCL TRohit components do not exist in the same namespace and will not throw an exception.

If you want to write a single source TRohit visual component then it’s theoretically possible but I wouldn’t recommend it. FMX and VCL are similar at the application programmer level but at the component author level they are radically different.

I had started a few years ago with non-visual common components, with one unit for both types of components. And of course had to do a build every time. But as soon as I read your comment, I realised what I had to do.

Also, I am using different namespaces now, which probably helps. Because it didnt work when I had first tried it with no namespaces.