Reputation: 3127
I have written some components for the IDE and they all look like this:
unit xxx;
interface
uses
System.Classes, System.SysUtils;
type
TMyClass = class(TComponent)
//code...
end;
implementation
end.
In this way I can use them on VCL and FMX; in other words I can make a VCL win program and a FMX Android app that use my components. The code you can't see is the implementation of the class but that's not important.
In point 2 I mean that under FMX win32 I have the component like this:
If I change platform (say android) I get this
What am I doing wrong? I went in IDE > Tools > Options > Library and for each platform I have added the path in which the IDE can find the .pas with the sources. Any idea?
The weird thing is that under FMX if I want to be able to create an Android app with my components I have to change the platform to win32, drag-drop the component and then change back to Android. The component works very well on android too.
Upvotes: 3
Views: 570
Reputation: 4751
You just need to include System.Classes
(you already have it from what I can see) and then be usure to use this attribute:
type
[ComponentPlatformsAttribute(pidWin32 or pidAndroid)]
TTestComponent = class(TComponent)
//...
end;
In this way you will be able to drag and drop components from the IDE to the view even when you've switched to Android. Basically your code is fine and it works with VCL and FMX but with that attribute you are telling the IDE that the component is compatible with the platforms you are specifying.
ComponentPlatformsAttribute gives component builders more specific control over the exposed components.
To fix the problem you should:
You can find more arguments to pass to the constructor of the attribute, I have found them in the System.Classes
pas file:
pidWin32 = $0001;
pidWin64 = $0002;
pidOSX32 = $0004;
pidiOSSimulator = $0008;
pidAndroid = $0010;
pidLinux32 = $0020;
pidiOSDevice32 = $0040;
pidiOSDevice = pidiOSDevice32;// deprecated 'Use pidiOSDevice32';
pidLinux64 = $0080;
pidWinNX32 = $0100;
pidWinIoT32 = $0200; // Embedded IoT (Internet of Things) Windows w/ Intel Galileo
pidiOSDevice64 = $0400;
pidWinARM = $0800;
pidOSX64 = $1000;
pidOSXNX64 = pidOSX64 deprecated 'Use pidOSX64';
pidLinux32Arm = $2000;
pidLinux64Arm = $4000;
pidAndroid64 = $8000;
There is an answer here that can be helpful if you want to include every single platform, you can pass 0 to the constructor of the attribute like [ComponentPlatformsAttribute(0)]
. It seems that it works but I wouldn't use it, I prefer declaring the platforms one by one even if it can be tedious!
Upvotes: 4