Category: StackOverflow

Freeing dynamically-created controls in Android

In my Firemonkey multi-platform app, I dynamically create some controls. After using them, I destroy them. In Windows, there is no issue with this dynamically created and destroyed process. However, it seems that in Android, the code below does not destroy the controls as an error will popup to say that the Control already exists (and I do see the old controls are still there when I try to re-create the controls). How do I ensure the controls are destroyed properly in Android (and/or iOS - I assume it's similar for iOS)? for i := oParentRect.ControlsCount-1 downto 0 do begin oControl := oParentRect.Controls[i]; if (oControl is TText) or (oControl is TEdit) then begin FreeAndNil( oControl ); // I have also tried oControl.Free; end; end;
Read More

Printing in Firemonkey

TPrinter* prn = Printer::Printer(); TCanvas* Canvas = prn->Canvas; String text = "Long live the king"; TFillTextFlags fTextFlag = TFillTextFlags(); prn->BeginDoc(); TRectF rect{100, 100, 800, 800}; Canvas->FillText(rect, text, false, 1, fTextFlag, TTextAlign::Leading, TTextAlign::Leading); prn->EndDoc(); ShowMessage("Done Printing!"); The Text coming out is very tiny (as if no scaling was done with respect to DPI... like it was printing to a Screen, not a printer)... I tried the above (similar) codes in VCL, and it comes out fine...
Read More

Firemonkey does not show Hebrew text in iOS

When I fill in a FMX control (like TLabel, TText or TMemo) with a Hebrew text - it's not being shown in iOS (in Android and Win it works fine), only punctuation appears and non-Hebrew symbols. Even in a blank project with just one label on a clean form. Is not it supported or did I forget to configure my project with some encoding/codepage etc.? Delphi 10.3 Version 26.0.36039.7899; iPhone 7 Plus, iOS 13.5.1; Mac OS Catalina 10.15.4
Read More

Prevent rearrangement of my visual controls during runtime with dynamic RESIZING of TLayout Control in Delphi Firemonkey [duplicate]

Is there a way that I can prevent re-arrangement of my visual controls during runtime with dynamic RESIZING of some of the controls like TLayout/TVertScrollBox in my case? Here's the controls contained in my form: Form TabControl TabItem1 // select and filter a meta to be to shown in TabItem2 TVertScrollBox1 TabItem2 // select and filter an item to be shown in TabItem3 TVertScrollBox2 TabItem3 // provide the details of the selecte item from TabItem2 TVertScrollBox3 TLayout1 TImage TLabel1 TLabel2 TLayout2 // get its height from TListView item(record) count TLabel3 TListView // dynamically based on item(record) count provide the height TLayout2 Based on the above setup, the size of TLayout1 is dependent on the record count (fdquery.recordcount) to be shown in TListView. Upon running the program, the controls changed its position like the TLabel2 will move to the bottom and all others arbitrarily. I was given the answers here and another one here but it discussed about TPanel created at runtime. I am not really sure if these are relevant to my questions. Because I don't use TPanel controls and its being created at runtime. Mine is create at design time except that some controls are dynamically resizing at runtime. I found another solution from youtube of Alister Christie to create a procedure below: procedure TformMain.OrderControls; begin TImage.Align.alBottom := 0; //Alister sample is Button1.Left := 0; TLabel1.Align.alBottom := 0; TLabel2.Align.alBottom := 0; TLayout2.Align.alBottom := 0; TLabel3.Align.alBottom := 0; TListView.Align.alBottom := 0; end; procedure TfromMain.TVertScrollBox1ItemClick(const Sender: TObject; const AItem: TListViewItem); begin OrderControls; end; But, I am getting the error on alBottom as it is already deprecated. I tried Align.Bottom and this time it is not recognized. My issue is getting deeper here. Going back, all I want is how to make my controls fix to its assigned location even if my other controls are dynamically resizing at runtime.
Read More

Delphi FMX (Android) – How read text file inside zip stream without extract?

Is it possible to read a file from the zip file without extract it? I want to read a text file from a compressed file(as an android assets) in a Memo lines. ZipFile := TZipFile.Create; //Zipfile: TZipFile try ZipFile.Open('C:\Path\to\file.zip', zmRead); for I := 0 to ZipFile.FileCount - 1 do begin if ZipFile.FileNames[I]='A1.txt' then //S: string //My problem is here ? How load A1.txt to memo lines? Memo1.Lines.Add(S); end; ZipFile.Close; finally ZipFile.Free; end;
Read More

Upload file using IdHTTP to specified host based on curl call

I am trying to create an FMX Android application that needs to upload a file to given host. The host owner provided me with a following curl statement to upload a file: curl -T http://<ip-address>:<port> file.txt And when called from Windows Command Prompt it produces the following output (IP and port redacted): * Trying <ip-address>... * TCP_NODELAY set * Connected to <ip-address> (<ip-address>) port <port> (#0) > PUT /file.txt HTTP/1.1 > Host: <ip-address>:<port> > User-Agent: curl/7.55.1 > Accept: */* > Content-Length: 682 > Expect: 100-continue > * Done waiting for 100-continue * We are completely uploaded and fine < HTTP/1.1 200 OK < content-length: 0 < date: Tue, 16 Jun 2020 19:24:18 GMT < connection: close < * Closing connection 0 and file is visible in the expected directory on the host machine. Now I'm trying to have the same behavior using Indy, but either there is some black-box magic occurring on the server-side, or there is an issue with my code - with some solutions the request seems to finalize, but there is no file in the specified directory (and status code 200 is returned). I have also tried using Fiddler to reproduce the curl call, and in the response of a composed query also received 200 status code, but still - no file was properly uploaded. When inspecting Wireshark packets for these solutions they all seemed similar to the curl call - however, I am not an expert in using this tool, so maybe there are issues not visible to my newbie eye. I tried using following solutions: - How do I upload a file using http post? Delphi 2009 - but using PUT instead of POST - Single file upload example - Post a file through https using indy / delphi components And in my case they do not work - so my guess is that the server is somehow not accepting these. I know it's very hard to say what I'm doing wrong without me actually putting some code, but right now it's a total mess - but maybe it's not hard to somehow show me how to convert this curl call to work with TIdHttp? If not, I will try to modify my question soon with more information. EDIT: As requested, I'm adding some sample code: var FHTTP: TIdHTTP; file2send: string; sr: TStringStream; FPutData : TFileStream; begin sr := TStringStream.Create; if OpenDialog1.Execute then file2send := OpenDialog1.FileName; FHTTP := TIdHTTP.Create(self); FPutData := TFileStream.Create(file2send, fmOpenRead or fmShareDenyWrite); FHTTP.Put(PutURL.text, FPutData, sr); end;
Read More

TIdTCPClient Android not connecting to TIdTCPServer on local PC

Using Rad Studio (Delphi) 10.3.2, I have a TCPServer app on my local PC and created an app running on an Android phone to connect using the local IP address, but I get "Connect timed out". Both are connected to the same local network via 192.168.1.x range addresses. I can ping the phone device from my PC. I can connect to the TCPServer from another Windows PC on the network, so that's working. I don't understand what could be getting in the way. Is there something in Android preventing connections to a local IP address? I have the Android Manifest for my app allowing INTERNET access but not sure if there is another one for accessing the local network. I also tried connecting from the phones Chrome browser but nothing arrives at all at the TCP Server.
Read More

conflict with events click and gestures – delphi firemonkey

My application has a TImage with two events, a left or right gesture event to change the image and a TImage click event to zoom the image, but when using the left or right gesture to change the image, the problem occurs, the click of the event is triggered and the zoom is called ... How to solve this? Sorry for my english .. I'm Brazilian
Read More

The TMSFMXWebGMaps is causing to freeze or make my app not responding

I am developing a firemonkey app using Google Map. When I dropped the TMSFMXWebGMaps component and tried to run it. it just freeze forever and not responding. I do not know what I was missing here and have no clue yet. Is there any other TMS components that I should be installing or configuration that I missed here? UPDATE 1 — DELETED THE RME I entered the APIKey in the properties and it works in my RME which I just deleted in this update to avoid confusion. But, when I tried in in my actual development by dropping the TMSFMXWebGMaps componet. It is not responding and cause to freeze when running it.
Read More

Delphi/FMX: How to add a dynamically created top-aligned component under all previously added top-aligned components, instead of second from the top?

I am making an app for Android with Delphi and FMX. In the onclick-procedure of a button I dynamically create a TPanel (with some components in it) which I then add to a TVertScrollBox. I want the TPanels to stack on top of each other, so I set the Align property to Top. procedure TMainForm.AddGroupButtonClick(Sender: TObject); var Group : TPanel; begin Group := TPanel.Create(Self); Group.Parent := Groups; // where Groups is a TVertScrollBox on the form Group.Align := TAlignLayout.Top; //Then I create some other components and set their Parent to Group end; A user would probably expect the new TPanel to be added under all the other TPanels. However, unless there's no TPanels added previously, every new TPanel is added directly under the topmost one, i.e. second from the top. Why is this and how do I add the new TPanel under all the previously added ones? I saw a similar question on here, but they were using VCL, where there apparently is a Top-property you can change. There doesn't seem to be one when working with FMX components though.
Read More