Category: StackOverflow

Start touch and finish touch event Delphi

I implement simple painting application in Delphi FMX for Windows pc with touch screen. I am looking for a function which is invoked directly after the first touch on the screen and similar function invoked after finishing the touch. Very close to MouseDown and MouseUp and using TControl.Pressed. I tried to use mouse functions but unfortunately, many windows touch screens do not send this event after touching the screen (some of them do). I also tried Tap function but it is called only if you do not drag a finger over the screen. Finally, I wanted to use TGestureManager but it seems to focus on just Gestures like zoom, rotate, etc. Is there any other option to achieve my goal?
Read More

Is it better to do if assigned(MyObj) then or if (MyObj <> nil) then [duplicate]

This question already has an answer here: Best way to check if a Variable is nil? 2 answers When i read the modifications made in the original delphi source code (mostly in the firemonkey) I saw that embarcadero sometime replace if assigned(MyObj) then by if (MyObj <> nil) then. Is their any real reason to do this or it's simply purely cosmetic ?
Read More

Delphi – Using TEdit.tagObject to point to another object

I am using a descendant of TEdit and using TagObject to store an object. I'm using Firemonkey. In short, I am working with another object and want to assign a property of that object to my TMyEdit, so that whenever I load the object, the text gets updated, and when I change the text, the object gets updated. So I do it like this: Edit1 : TMyEdit; MyElement:TMyProperty; ... Edit1.TagObject:=TMyTextProperty(MyElement); (The typecast is necessary for other reasons. I mention it just in case it is related). The code works when MyElement is not nil to start with. If MyElement was nil, MyEdit automatically creates a new instance of TMyTextProperty and assigns it to tagObject. procedure TMyEdit.MyOnChange(Sender : TObject); begin if tagObject=nil then TagObject:=TMyTextProperty.Create(''); TMyTextProperty(TagObject).value:=text; end; I assume that since tagObject is a pointer and i pointed it to MyElement, then myElement would also be updated. But it isn't. Edit1.TagObject contains my value, but MyElement is stil nil. I need MyElement to be the newly created object. What am I doing wrong? How can I make sure that whenever the TagObject gets created, the MyElement points to the new object? Many thanks
Read More

Performance of HTTP POSTS from Firemonkey Android app has suddenly collapsed when on mobile data

A Delphi 10.2.3 Firemonkey app on Android I've had this app running and in use for about 6 months, and it's been fine. I recompiled the code after Windows Spring Update (I don't know if this is related), and the performance of HTTP POSTS has dramatically slowed e.g. a 49 byte response (to a simple request) is taking over 10 seconds whereas on wifi it's about 0.1 seconds. It's not the server side, in the sense that the connection is very brief, as one would expect. To do the connection, I'm using idHTTP, which has always worked fine. No code changed, I've tried a number of different networks, good signal and bad (it makes no real difference). Checked all the usual things, connections closing, things are freed as they should be, etc. Any ideas? Is there some parameter I should look at? (Edit) * Just to add, any test app that only does this sort of connection has the same problem. 0.1 seconds on wifi, 16 seconds in mobile data. * I realised I hadn't checked a GET - they work fine, nice 0.1 sec response to the same request, but run as a get. So it looks like there's something weird about the POST. (Edit) Completed a fresh Windows & Delphi install, and tested using a small android app that with 2 buttons, Get & Post, calling web services that simply return the parameters. No change. POST takes 10-ish seconds, GET takes about 0.1. Any ideas would be very helpful.
Read More

Crossplatform audio support in Delphi

I'm running Delphi Tokyo and I'm looking for a way to play audio on Windows and Android (and maybe at some point iOS). On Windows I can do with something like PlaySound(PChar(ResourceName), 0, SND_RESOURCE or SND_ASYNC), but I'm stuck on Android. I've tried TMediaPlayer, but it takes about a second before it starts playing, which is too long for a mouse click or screen tap. Basically I've built a Minesweeper clone and I'm looking for sound support (if you want to know the background). Suggestions?
Read More

DeviceCheck for iOS in FMX

Starting at iOS 11 Apple now has a means of letting us identify devices that have used something up (e.g. a trial period etc.) without identifying any personally identifying information: https://developer.apple.com/documentation/devicecheck The above link describes these DeviceCheck APIs. How can we do this in an FMX app? Will also need for Android eventually too. My intent is to let users vote from the app - but only vote once. thanks, russ
Read More

secure remote MySQL access with firemonkey

I've built an app that can download SQLite data via http it C++ Builder. I want to now allow users to give feedback that will get pushed into a remote database without traversing internet unencrypted. The database can be a MySQL that can live on a Synology NAS (although I don't mind using any other approach that might be easier - even pay if not too expensive) at a static IP address on the internet. Very low data payload required. I want to do this in C++ in Rad Studio in a Firemonkey app. I'm a novice (my day job is engineer) and this is just for my enjoyment. How can I make a secure connection from my FMX app (iOS and/or Android) to the remote database using the FireDAC components or Indy. My head is swimming from all the information out there that is above my head. thanks, russ
Read More

C++ Builder Tokyo 10.2.3 FMX Android application crash if I dont click on Next button on virtual keyboard

I use C++ Builder Tokyo 10.2.3 and trying to do something very simple on Android like typing some text into an Edit box. If I press Next or Done key on virtual keyboard everything is fine. If I press an Exit Button to go back the previous form it looks it is fine but then if I press Android Back button application crash. It took me hours to identify the problem but couldn't find any solution but trying to disable all other objects when user clicks in an Edit box and enable them if user click on Next.. It seems to me a bug but need to make sure before report it to Embarcadero. Thanks
Read More

Custom drawing of TCustomListbox items

I'm rewriting a VCL component showing a customized TCustomListbox to Firemonkey in Delphi 10.2. The customization used an overridden DrawItem, basically adding some indentation and setting the text color depending on the item text and index. DrawItem made it rather easy, but there seem to be nothing like that in FMX. I can override PaintChildren and draw every item myself, but then it looks differently and I have to deal with scrolling and everything myself. I'm just starting with FMX and don't have the sources yet. Is there a DrawItem replacement in FMX? I may have missed it. If not, how do it get the needed information? Basically, the rectangle to draw in and ideally the style used. Problems The solution by Hans works, but has some major problems: Color Setting the color doesn't work, the text is always black. I tried various possibilities including this one: PROCEDURE TMyItem.Paint; BEGIN TextSettings.FontColor := TAlphaColorRec.Red; INHERITED; END; Speed Opening a box with 180 Items takes maybe two seconds. We need that many items and their count is actually the reason why we need a customized box (we provide filtering using the TEdit part of our component). A version using strings without TMyItem was faster (though probably slower than the VCL version), but using these items seems to slow it down even more (it's slower than filling an HTML list styled similarly). Or something else? Having no sources and practically no documentation I can't tell. I tried to cache the items for reuse, but this didn't help. It looks like using custom items is actually faster than using strings, (timing in milliseconds): nItems String TMyItem 200 672 12 2000 5604 267 20000 97322 18700 The speed problem seems to accumulate when the content changes multiple times. I was using FListBox.Items.Clear;, then I tried n := FListBox.Items.Count; FOR i := 0 TO n-1 DO FListBox.ListItems[n-1-i].Free; and finally FListBox.Clear;, which makes most sense (and which I found last). Still, in the end it seems to need 2 ms per item.
Read More

How to keep controls visible while designing a form

In Delphi 7, controls (e.g. TImage) that had their Visible flag set to False would still be visible on the form designer. In recent versions of Delphi (Delphi 10.2), setting an FMX control's Visible flag to False hides the control during design time, making it harder to find on the form. I searched through Delphi's option and the web and couldn't find a way to restore the D7 behavior, is there a solution to this?
Read More