Is there a way for testing, either at design time or run time, which O/S a Miletus has been compiled for? Something like the
{$IFDEF WINDOWS}
that we'd do in an FMX app.
I'm working on an app for Raspberry Pi that I also want to run on Windows, where for Pi I use the Pi UART control but on Windows the USBSerial control. So I need to know which control to use. At present I've added WINDOWS to the directives list for Windows build, so I can test that with IFDEF, which works of course, but it would be neater if there's something built-in to Miletus that I can test instead.
We don't have defines for the supported target platforms but at run time you can use the GetOSVersionP promise to check this.
//Mark as async
[async]
procedure WebButton1Click(Sender: TObject);
//Implementation of WebButton1Click
procedure TForm3.WebButton1Click(Sender: TObject);
var
os: TMiletusOSVersion;
begin
os := Await(TMiletusOSVersion, GetOSVersionP);
if os.Platform = opWindows then
ShowMessage('I''m on Windows')
else
ShowMessage('I''m not on Windows');
end;
This is of course not tied to a button click. You could do the same from the Form.OnCreate event and store the TMiletusOSVersion result.