Category: StackOverflow

How detect the mouse back and forward buttons in a Delphi FMX Windows form?

Has anyone found a way to detect the mouse back and forward buttons in a Delphi FMX form in Windows (and only Windows)? I understand this works fine in a VCL application, using procedure WMAppCommand(var Msg: Winapi.Messages.TMessage); message WM_APPCOMMAND; but this has no effect in an FMX application. If anyone already has worked out a solution to this, would very much appreciate a hint (or the code they used, of course).
Read More

Why is recorded microphone audio sometimes truncated in Delphi?

My Delphi 10-4-2 FMX project captures microphone audio to a file using this code: private fFileIncrement: Integer; fMic: TAudioCaptureDevice; procedure TForm1.RecordButtonClick(Sender: TObject); begin fMic := TCaptureDeviceManager.Current.DefaultAudioCaptureDevice; if fMic <> nil then begin RecordButton.Enabled := False; StopButton.Enabled := True; Inc(fFileIncrement); fMic.FileName := 'TESTWAVE-' + fFileIncrement.ToString + '.wav'; fMic.StartCapture; end; end; procedure TForm1.StopButtonClick(Sender: TObject); begin if (fMic <> nil) and (fMic.State = TCaptureDeviceState.Capturing) then begin fMic.StopCapture; StopButton.Enabled := False; RecordButton.Enabled := True; end; end; Intermittently, approximately one out of three audio files are missing the last half second of the recording. What would cause the end of the audio to be cut?
Read More

FMX: Setting TScrollBar thumb size by changing ViewportSize reduces maximum settable value

Add a TScrollBar to a form in FMX and leave min and max at the default values 0 and 100. Set ViewportSize to 50. This makes the thumb half then length of the scroll bar. However, the value for the scroll bar can now only be set between 0 and 50. It seems that the maximum settable value is Max - ViewportSize. How can I set the thumb size while still being able to set values between 0 and Max? I know that I could set Max to 150 (Max + ViewportSize) but I'm already using Max in my code to determine what the maximum settable value is. I note that the documentation is no help at all. It doesn't mention this issue and also incorrectly states that ViewportSize is in pixels. http://docwiki.embarcadero.com/Libraries/Sydney/en/FMX.StdCtrls.TScrollBar.ViewportSize
Read More

Android Socket Timeout Exception during Rest data connection, only during mobile network connection

After updating Delphi version 10.1 to 10.4.2, I encountered this problem, which only occurs on some Android 10 and 11 devices. The APP exchanges data with the server via TDSRestConnection. On the same phone, where previously the app developed with Delphi 10.1 worked correctly, stops working after the update to Delphi version 10.4.2 and after the Android upgrade on the phone. The APP works only over the WiFi network and no longer works over the mobile network, generating this error after a while (7/8 seconds): java.net.SocketTimeoutException: failed to connect to /xxx.xxx.xx.xx (port 17200) from /100.118.154.102 (port 42050) after 300000ms: isConnected failed: ETIMEDOUT (Connection timed out). I also tried using different internet mobile providers (TIM, VODAFONE) The 4G connection is Very Good and the Internet speed test doesn't show any problem. The error doesn't appear immediately. The function GetSql is called more times in the sincro procedure, but unfortunately it stops working not at the same point. The code: Client side: const fConnectTimeout=300000; const fReadTimeout=300000; function TServerMethods1Client.GetSql(StringaSql: string; const ARequestFilter: string): TFDJSONDataSets; begin if FGetSqlCommand = nil then begin FGetSqlCommand := FConnection.CreateCommand; FGetSqlCommand.RequestType := 'GET'; FGetSqlCommand.Text := 'TServerMethods1.GetSql'; FGetSqlCommand.Prepare(TServerMethods1_GetSql); end; FGetSqlCommand.Parameters[0].Value.SetWideString(StringaSql); FGetSqlCommand.Execute(ARequestFilter); if not FGetSqlCommand.Parameters[1].Value.IsNull then begin FUnMarshal := TDSRestCommand(FGetSqlCommand.Parameters[1].ConnectionHandler).GetJSONUnMarshaler; try Result := TFDJSONDataSets(FUnMarshal.UnMarshal(FGetSqlCommand.Parameters[1].Value.GetJSONValue(True))); if FInstanceOwner then FGetSqlCommand.FreeOnExecute(Result); finally FreeAndNil(FUnMarshal) end end else Result := nil; end; function SelectSql(StringaSQL:String;tb:TFDMemTable;out Errore:String):Boolean; overload; var jds: TFDJSONDataSets; data: TFDAdaptedDataSet; begin try result:=false; if DMClientRestModule=nil then DMClientRestModule:=TDMClientRestModule.Create(nil); DMClientRestModule.DSRestConnection1.Port := STRTOINT(REST_PORT); DMClientRestModule.DSRestConnection1.Host := REST_HOST; DMClientRestModule.DSRestConnection1.SessionID := ''; DMClientRestModule.DSRestConnection1.HTTP.ConnectTimeout := fConnectTimeout; DMClientRestModule.DSRestConnection1.HTTP.ReadTimeout := fReadTimeout; jds :=TFDJSONDataSets.Create; jds := DMClientRestModule.ServerMethods1Client.GetSql(StringaSql); if (Assigned(jds)) then begin data := TFDJSONDataSetsReader.GetListValue(jds, 0); tb.AppendData(data); tb.Open; result:=true; end; try DMClientRestModule.Free; DMClientRestModule:=NIL; except end; except result:=false; Errore:=GetStrException(ExceptObject,ExceptAddr); end; END; Server side: function TServerMethods1.GetSql(StringaSql: String): TFDJSONDataSets; var dset:TFDJSONDataSets; begin try DbConn.Params.Clear; //TFDConnection DbConn.Params.Database:=fdb; DbConn.Params.UserName:=fuid; DbConn.Params.Password:=fpwd; DbConn.Params.Add('server='+fdbserver); DbConn.Params.Add('port='+fport); DbConn.Params.DriverID:='MySQL'; try q1.Close; // TFDQuery if not DbConn.Connected then DbConn.Connected:=true; if not DbConn.Connected then log('Not conneted to db') else log('Connected to db') ; with q1 do begin close; SQL.Clear; SQL.Add(StringaSql); Log(StringaSQl); open; end; Result := TFDJSONDataSets.Create; // The "TFDJSONDataSetsWriter" class provides static "ListAdd" method. // It uses reflection to convert results of the query into "TFDJSONDataSets". TFDJSONDataSetsWriter.ListAdd(Result,'',q1); except Log(GetStrException(ExceptObject,ExceptAddr)); Result := TFDJSONDataSets.Create; TFDJSONDataSetsWriter.ListAdd(Result,'',q1); end; finally DbConn.Connected:=false; end; end; update 16/04/2021 Investigating better, it seems that the Sql String that causes the exception is the following (Long text sql string) StringaSql :='SELECT PLANNING_ENGINEERS.DATE_JOB,NOT_A_JOB, '; StringaSql := StringaSql + ' PLANNING.PLAN_ID,PLANNING.CONTACTID,PLANNING.CALLER_REFER, '; StringaSql := StringaSql + ' PLANNING.COMPANYID,PLANNING.DEPOTID,CALLTYPEID,TIME_BEGIN,'; StringaSql := StringaSql + ' TIME_END,LOCATION_DESCRIPTION,ADDRESS1,ADDRESS2,ZIP,PLACE,PROVINCE,'; StringaSql := StringaSql + ' PHONE1,PHONE2,FAX,EMAIL,LATITUDE,LONGITUDE, '; StringaSql := StringaSql + ' PLANNING.DELETED,PLANNING.CLOSED,PLANNING.SUSPENDED,PLANNING.NOTES,'; StringaSql := StringaSql + ' PLANNING.INTERNAL_NOTES,PLANNING.SUGGESTION_NOTES,PLANNING.CLOSING_NOTES,ORDER_REFERENCE,EXTERNAL_REFERENCE, '; StringaSql := StringaSql + ' EXTERNAL_REFERENCE_DESC '; StringaSql := StringaSql + ' ,(SELECT CALLTYPES.DESCRIPTION FROM CALLTYPES WHERE CALLTYPES.CALLTYPE_ID=PLANNING.CALLTYPEID)'; StringaSql := StringaSql + ' AS CALL_DESC '; StringaSql := StringaSql + ' ,(SELECT CALLTYPES.TYPE FROM CALLTYPES WHERE CALLTYPES.CALLTYPE_ID=PLANNING.CALLTYPEID)'; StringaSql := StringaSql + ' AS CALL_TYPE '; StringaSql := StringaSql + ' ,(SELECT DEPOTS.NOTES FROM DEPOTS WHERE DEPOTS.DEPOT_ID=PLANNING.DEPOTID)'; StringaSql := StringaSql + ' AS DEPOT_NOTES '; StringaSql := StringaSql + ' FROM PLANNING,PLANNING_ENGINEERS WHERE '; StringaSql := StringaSql + ' PLANNING.DELETED=''N'' AND PLANNING.CLOSED=''N'' AND PLANNING.SUSPENDED=''N'' '; StringaSql := StringaSql + ' AND PLANNING_ENGINEERS.PLANID=PLAN_ID '; StringaSql := StringaSql + ' AND PLANNING_ENGINEERS.ENGINEERID='+'42'; StringaSql := StringaSql + ' AND PLANNING_ENGINEERS.DATE_JOB BETWEEN '+QuotedStr(FormatDateTime('YYYYMMDD', date))+' AND '+QuotedStr(FormatDateTime('YYYYMMDD',date))+' '; StringaSql := StringaSql + ' ORDER BY DATE_JOB,TIME_BEGIN'; During the WIFI connection, the call to the server works fine then it send back the result. Instead during the 4G connection, the call raise the exception below: Exception ENetHTTPClientException in module ... java.net.SocketException : Connection reset. I also reported a ticket RSP-33699 to Embarcadero Here the video: RestIssue
Read More

How to fix a column in TStringGrid with delphi FMX?

I want to make a grid with FireMonkey where it has a fixed column, but neither TGrid nor TStringGrid have that property, nor allow me to change it dynamically at runtime, as far as I can see. Does anyone have a way to make this work? Imagine I have 500 columns (I don't, and I won't have that number, this is just for demonstration purposes). I want to lock the first column so its content will always be visible as the user scrolls the grid along the X axis (horizontally). Same thing as with the header row, it's always locked in place so when the user scrolls along the Y axis, the header is always visible. I am using Delphi 10.3.3 CE.
Read More

Specifying an IP Address in FireMonkey TWebBrowser

The FireMonkey TWebBrowser component allows the developer to specify a local file (file://...) or a URL (https://www...). However, there seems to be no way to get the browser to work by specifying an IP address (192.168.1... or http://192.168.1... etc.) The browser just appears to hang. Is it possible to specify an IP address with this component? I'm currently using Delphi 10.4.2 developing for iPhone. Safari on the same phone has no problem accessing 192.168.1... addresses.
Read More

Why does the FormFactor.Width and FormFactor.Height not change when a Delphi FMX application is resized?

I’m a long time Delphi VCL developer and I’m just starting to learn FMX. I created a simple little application that displays the ClientHeight, ClientWidth, FormFactor.Width, and FormFactor.Height inside a TMemo in the OnResize event handle… … Read More

Read More

Embeded VCL Form with FMX Form

I want to use TWindowsMediaPlayer in an FMX Form. I create it with this code, but playing media causes an error: Access violation at address 004080D6 in module 'Project1.exe'. Read of address 00000500 How can resolve it? var frmvlc: TFrmVlc; begin frmvlc := TFrmVlc.Create(self); frmvlc.WindowsMediaPlayer1.URL := filename; // it play video but not show it. self.AddObject(TFmxObject(frmvlc.Panel1)); error hier end;
Read More

Rad Studio 10.2.3 error when install apk: INSTALL_PARSE_FAILED_NO_CERTIFICATES

How can I solve this problem? C:\Users\user\Documents\Embarcadero\Studio\19.0\PlatformSDKs\android-sdk-windows\platform-tools>adb install Project.apk Performing Streamed Install adb: failed to install Project.apk: Failure [INSTALL_PARSE_FAILED_NO_CERTIFICATES: Failed collecting certificates for /data/app/vmdl1331479076.tmp/base.apk: Failed to collect certificates from /data/app/vmdl1331479076.tmp/base.apk: Attempt to get length of null array] I am using RAD STUDIO 10.2.3, with SDK 25 to compile an app on Android 11. Thank you!
Read More

ForegroundService can’t start – FMX

On newer version android I'm change startService to startForegroundService but service can't start.In manifest file is added ForegroundService permission. LIntent := TJIntent.Create; LIntent.setClassName(TAndroidHelper.Activity.getBaseContext, TAndroidHelper.StringToJString('myService')); TAndroidHelper.Activity.startForegroundService(LIntent); On android 5 work fine: LIntent := TJIntent.Create; LIntent.setClassName(TAndroidHelper.Activity.getBaseContext, TAndroidHelper.StringToJString('com.embarcadero.services.myService')); TAndroidHelper.Activity.startService(LIntent);
Read More

Why can’t I install a custom font in Win32 under FMX?

I've tried AddFontResourceEx(). But it only works in VCL. Android can modify the IDE source code to load fonts. I think it may be related to Direct2D. Only after manually installing fonts into the system can I enumerate my custom fonts. I am here: https://github.com/TheOriginalBytePlayer/FireMonkey-Fonts It seems to be a feasible solution, but it's not smooth.
Read More

My Basic Android App closes after splashscreen

I have created a basic Android64 app, with just one button and managed to build it. After installing it on my device (sideloaded), I see the app in the startmenu but once I start it it shows a splashscreen and then closes. I never get to see the button... unit MainUnit; interface uses System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Controls.Presentation, FMX.StdCtrls; type TMain = class(TForm) Button1: TButton; procedure FormCreate(Sender: TObject); private { Private declarations } public { Public declarations } end; var Main: TMain; implementation {$R *.fmx} {$R *.LgXhdpiPh.fmx ANDROID} procedure TMain.FormCreate(Sender: TObject); begin end; end. What's wrong here? :-/ PS: I have noticed, that the form is not set to visible by default, and changed that (but no change). Is there a reason to it? PS: Update 13042021: I found out this only happens on my OnePlus 8 Pro, but not on my Samsung S9. Weird!
Read More