Tag: firemonkey

Reliable method for checking that an online file exists

I have the following code which checks that a file exists on a website. Sometimes it works and sometimes it doesn't. When it doesn't work it invokes EIdHTTPProtocolException and returns 0 even though the file is present on the server. Does anyone have an idea for why it doesn't always work? It seems more likely to work if I'm debugging the code, so I wonder if it has to do with timing? This is an FMX application running on Windows and I'm using Delphi 10.4. Note that I have changed the link to a fake one for posting here so obviously the code below will always return 0 if you try it. uses IdHTTP, IdStack; function CheckFileOnlineExists(const OnlineFile: string; var Size: Int64): Byte; var IdHttp: TIdHTTP; begin Result := 0; // File not found IdHttp := TIdHTTP.Create(nil); try try IdHttp.Head(OnlineFile); Size := IdHttp.Response.ContentLength; if Size > 0 then Result := 2; // File found except on E: EIdHTTPProtocolException do ; on E: EIdSocketError do Result := 1; // No internet end; finally IdHttp.Free; end; end; procedure TMainForm.FormActivate(Sender: TObject); Var LSize : Int64; LRes : Byte; begin // Check if online file exists LRes := CheckFileOnlineExists('http://websiteurl.com/file_test.png', LSize); if (LRes <> 2) or (LSize <> 5497) then begin if LRes = 0 then Caption := 'Website check file not found. This app will close' else Caption := 'Internet connection is needed to run this application'; Close; end; end;
Read More

LaunchScreen.TemplateiOS target directory

in Sydney, when we build an app for iOS there is now a new folder that will be created: LaunchScreen.TemplateiOS\. The problem is that it's make a little the mess in the directory structure of my project. Is there any way to specify the directory where the LaunchScreen.TemplateiOS directory must be created ? NOTE/Update: It's seam their is not any option, you can vote for it here: https://quality.embarcadero.com/browse/RSP-33503
Read More

FireMonkey 3D – Sun, Earth and Moon

Following up on an earlier post, Simple FireMonkey 3D, I'm going to make a simplified model of the solar system to explore multiple 3D objects interacting with each other in a scene. I'll also play around a little with light sources. Source code for the project is available here and is compatible with the Delphi Community Edition. The project starts off like most of my 3D projects; A
Read More

How to download Images without freeze or crash Delphi app

I have this code. Make a PHP Query to server and the results are Image URLs. I try to put them to a Listbox, in a TImage in ListboxItems with AnonymousThread and loop. All good on Windows but on Android the app crash. procedure TForm10.Button1Click(Sender: TObject); var aJSONArray: TJSOnArray; ThumbUrl, Postid: String; PCount: integer; begin ListBox1.Items.Clear; Edit1.Text := ''; TThread.CreateAnonymousThread( procedure begin aJSONArray := TJSOnArray.Create; aJSONArray := TJSONObject.ParseJSONValue(TEncoding.ASCII. GetBytes(NetHTTPClient1.Get('https://server/getUserPhotos.php?userid=1'). ContentAsString), 0) as TJSONArray; TThread.Synchronize(nil, procedure var AI: Integer; LBI: TListBoxItem; img: TImage; begin ListBox1.ItemHeight := ((ListBox1.Width / 3)-2); ListBox1.ItemWidth := ((ListBox1.Width / 3)-2); for AI := 0 to (aJSONArray.Count -1) do begin ListBox1.BeginUpdate; ThumbUrl := (aJSonArray.Items[AI].GetValue<string>('image_url_150')); Postid := (aJSonArray.Items[AI].GetValue<string>('post_id')); if ThumbUrl <> '' then begin LBI := TListBoxItem.Create(Self); LBI.Parent := ListBox1; try img := TImage.Create(self); img.Parent := ListBox1.ItemByIndex(AI); img.Align := TAlignLayout.Client; img.WrapMode := TImageWrapMode.Fit; with img.Margins do begin Left := 1; Right := 1; Top := 1; Bottom := 1; end; img.Tag := StrToInt(Postid); img.TagString := ThumbUrl; img.OnPainting := imgPainting; finally ListBox1.EndUpdate; end; end; end; end); aJSONArray.Free; end).Start; end; procedure TForm10.imgPainting(Sender: TObject; Canvas: TCanvas; const ARect: TRectF); var AStream: TMemoryStream; begin TThread.CreateAnonymousThread( procedure begin try AStream := TMemoryStream.Create; NetHTTPClient1.Get(TImage(Sender).TagString, AStream); AStream.Position := 0; TThread.Synchronize(nil, procedure begin TImage(Sender).Bitmap.LoadFromStream(AStream); end); finally AStream.Free; end; end).Start; end; I try to download images in the loop but the app freezes until all images are downloaded. What goes wrong?
Read More

Force raising touch event on android system by Delphi FireMonkey

I am developing an CONTROLLER-SERVER-CLIENT system by delphi 10.3. I am going to use Indy component for network communication between controller, server and client. In here the controller side can be developed to windows application or android apk format. I think the server side is best developed to windows application. But client side must only be made to android apk format. So I decided to use firemonkey library for these projects. The controller's purpose is to view android phone screen and control android system by remote touch events. In this case real touch event will be occured directly by client apk . The controller will send only touch event information to client by server mediation. For now the big problem that I faced is how to occure touch event on android system, not on special app interface. I have searched many articles about this on google, but still didn't gathered any useful information. How to occure touch event on android system by special apk that devloped with delphi firemonkey. Is it impossible? If not then Please give me small advice. Thank you.
Read More

How to disable listbox scroll inside a TVertScrollBar

I have a TVertScrollBox and I have some components inside it. One of them is a TListBox witch has some TListBoxItem. That TListBox has the size of all of its items. So it doesn't have a scrollbar. I need that the scroll gesture over TListBox goes to TVertScrollBox. When I try to scroll in a listbox it do not scroll itself nor its parent. It only can be tested in mobile. In windows we can not simulate, once mouse wheel is not the same event of scrooling by touching. I already tried to send the events to its parent but it hasn't worked so far. unit Unit1; 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, FMX.ListBox, FMX.Layouts; type TForm1 = class(TForm) Button1: TButton; VertScrollBox1: TVertScrollBox; ListBox1: TListBox; ListBoxItem1: TListBoxItem; ListBoxItem2: TListBoxItem; ListBoxItem3: TListBoxItem; ListBoxItem4: TListBoxItem; ListBoxItem5: TListBoxItem; private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.fmx} end. object Form1: TForm1 Left = 0 Top = 0 Caption = 'Form1' ClientHeight = 480 ClientWidth = 400 FormFactor.Width = 320 FormFactor.Height = 480 FormFactor.Devices = [Desktop] DesignerMasterStyle = 0 object VertScrollBox1: TVertScrollBox Position.X = 48.000000000000000000 Position.Y = 80.000000000000000000 Size.Width = 273.000000000000000000 Size.Height = 313.000000000000000000 Size.PlatformDefault = False TabOrder = 1 Viewport.Width = 257.000000000000000000 Viewport.Height = 313.000000000000000000 object Button1: TButton Position.X = 104.000000000000000000 Position.Y = 352.000000000000000000 TabOrder = 1 Text = 'Button1' end object ListBox1: TListBox Position.X = 24.000000000000000000 Position.Y = 24.000000000000000000 Size.Width = 200.000000000000000000 Size.Height = 241.000000000000000000 Size.PlatformDefault = False TabOrder = 2 DisableFocusEffect = True DefaultItemStyles.ItemStyle = '' DefaultItemStyles.GroupHeaderStyle = '' DefaultItemStyles.GroupFooterStyle = '' Viewport.Width = 196.000000000000000000 Viewport.Height = 237.000000000000000000 object ListBoxItem1: TListBoxItem TabOrder = 0 Text = 'ListBoxItem1' end object ListBoxItem2: TListBoxItem Position.Y = 19.000000000000000000 TabOrder = 1 Text = 'ListBoxItem2' end object ListBoxItem3: TListBoxItem Position.Y = 38.000000000000000000 TabOrder = 2 Text = 'ListBoxItem3' end object ListBoxItem4: TListBoxItem Position.Y = 57.000000000000000000 TabOrder = 3 Text = 'ListBoxItem4' end object ListBoxItem5: TListBoxItem Position.Y = 76.000000000000000000 TabOrder = 4 Text = 'ListBoxItem5' end end end end
Read More

Close mobile keyboard with TMemo

On Firemonkey 10.4.1 and Android, if I put a TEdit, I can exit with the "Ok" button of my mobile keyboard. On TMemo with Wordwrap option set to false, the "Ok" button that I have with the edit is use to go at the next line. How I can close the keyboard ? all other component are not selectable (rectangle, image, ...). Did I need to show a transparent layout and close manually the keyboard when it is visible with a OnClick event ?
Read More

Does anyone knows why my Delphi FMX app opens from beginning after a while?

I am new in Delphi and start using Delphi 10.4.1 to develop Android apps. I use Samsung Galaxy Note 10 Light. Unfortunately my apps starts from the beginning if I start using other apps or do some phone calls etc. I tried to play with my phone settings to not the let my apps do battery optimized etc. but no use. I compiled Debug - Release no chance at all. I don't know if is there settings or something on my Delphi (I did try an Xamarin Apps, they keep stay exactly in the same screen even if I open it back after a day ) Please help ! Thanks
Read More

First authorization for LocationSensor in Firemonkey

I use a TLocationSensor component where Active=True is set to design mode (same effect in by coding). When I use the app for the first time on Android I get the message to accept to be localised. If I answer with Yes I never enter in my LocationSensorLocationChanged event. I close app, open it again and now it's ok. I test with this method : procedure TfrmMain.LocationSensorLocationChanged(Sender: TObject; const OldLocation, NewLocation: TLocationCoord2D); begin if (NewLocation.Latitude > 0) and (NewLocation.Longitude > 0) then begin edGeocode.Text := NewLocation.Latitude.ToString + '-' + NewLocation.Longitude.ToString; end; end; I'm using Firemonkey 10.4.1.
Read More

How to solve ANR on Android firemonkey

On my Android application develop with Firemonkey 10.4.1, I see a lot of ANR in my Google Play Console. The first one is : Input dispatching timed out (Waiting to send non-key event because the touched window has not finished processing certain input events that were delivered to it over 500.0ms ago. waitqueue length = 1, head.seq = 14881924, Wait queue head age: 6480.1ms.) And the second one : Input dispatching timed out (9a5f6ef com.xxx.myapp/com.embarcadero.firemonkey.FMXNativeActivity (server) is not responding. Waited 10003ms for FocusEvent(hasFocus=true)) My app contain a TMapView, show bitmap downloaded from my server (or take and upload). I change the loading method by a thread instead of task, but it's same. I don't have any detail on how to get it. When I test in Android 32/64 I never got a ANR. Does something exist to trace these error ? a event where I can add log ?
Read More