Category: Firemonkey

Key/Value pairs in ComboBox using Delphi Firemonkey

I would like to use an enumerator to populate a Combobox with Key/Value pairs. Its important that I hide the key from the user and display the value only. On selecting I would like to capture the key associated with the selected value. The code looks something similar to this. var currentObj: ISuperObject; enum: TSuperEnumerator<IJSONAncestor>; while enum.MoveNext do begin currentObj := enum.Current.AsObject; cboUserList.Items.Add(currentObj.S['key'],currentObj.S['value']); end; The key currentObj.S['key'] should be capture on user select of the value currentObj.S['value'] which is visible to the user on the cboUserList dropdownlist. Any ideas?
Read More

Delphi visual component with Canvas

I have always written non-visual components; their creation is pretty easy and they work equally well under VCL and FMX. So far so good, but now I'm facing a problem. I used to inherit from TComponent but now I cannot anymore because my component called TRedistPreview really needs a procedure like this: procedure drawPreview(area: TCanvas); This procedure has to draw something (shapes, lines and colours) somewhere, for example in a TRectangle. I have seen online that TComponent doesn't have the ability to draw, so I should inherit from something else. I have found TWinControl (but that is VCL-only) and TCustomControl (VCL only, too). Could you please tell me what I should inherit from to get a canvas? I mean, I want to replace: TRedistPreview = class(TComponent) end; With: TRedistPreview = class(TSomeClassThatHasCanvas) end; Where I can call procedure drawPreview(area: TCanvas); and draw on a surface (like a TRectangle). I am looking for the lowest possible class in the hierarchy with a Canvas. Since this component is very useful to me under Windows and Android, I am looking for a Firemonkey implementation. From my research, I have seen that I could inherit from TRectangle, which is inside FMX.Objects, but I don't know if this is the right choice. What should I do? Also, if I needed this component to be in VCL, do I have to write another component that inherits from another class? As I've said, this is my first time with visual component writing, so I'd like someone to show me the right way!
Read More

ListView Filter not working after fetching data from datasnap server

I have an application made in Delphi Seattle, and i migrated to Delphi Tokyo. But my searches in ListView are no longer working properly. On a first use, it works correctly, i filter a record and edit it. I send the data to a datasnap server and fetch all records again to refresh the listview. But if I try to search again, it no longer finds the record, however browsing the listview I can find the record. Apparently all records that are not appearing on the screen when I reload the data are not being filtered. If I manually navigate to the record and perform the search, then it works. My Code to retrieve data from datasnap and show on listview: DadosSocio := F_ClientModule.ServerMethods1Client.GetSocio(0); Assert(TFDJSONDataSetsReader.GetListCount(DadosSocio) = 1); mem_Socios.Close; mem_Socios.AppendData(TFDJSONDataSetsReader.GetListValue(DadosSocio, 0)); mem_Socios.Open; lvSocios.ScrollTo(0); lvSocios.ScrollViewPos := 0; I use this code to clean the filter: for I := 0 to lvSocios.Controls.Count-1 do Begin if lvSocios.Controls[I].ClassType = TSearchBox then begin TSearchBox(lvSocios.Controls[I]).Text := ''; end; End; I tried to use this code to clean the filter, but it returns the error Argument out of Range: lvSocios.Items.Filter := nil;
Read More

Rad Studio 10.2.1 Memory Leaks Windows 10 store

It's well know around the Delphi community that there are memory leaks in Rad Studio 10.2.1 FMX. I did find a workaround for it: Workaround for fmx memory leaks I want to know some stuff about it. Does this only affect FMX Windows? Someone told me that if your app is on the windows store the memory leaks aren't a matter since windows store terminates them. Is this true? Here is his exact words: if you publish on Windows Store then it's not needed because all memory is automatically freed by the Store when an app is terminated.
Read More

Decompiling .SO files [on hold]

I created an application for Android using Embarcadero Delphi, then lost source code. But I have an apk file with .so file inside it. I don't need source code any more, but when I wrote this application, I compiled .rc into .res (using brcc32) and Delphi embedded it into lib.so file. Is there a way to extract my *.res file? It's important, 'cause it contains some grahic files that are important to me. Thanks much in advance.
Read More

How can I include an Apple Help Book when building my app for OSX

I have developed a Firemonkey app for Windows and OSX. I have also developed an Apple Help Book containing the help for my application when it is run on OSX. (I have a different help system when running in Windows.) Apple's recommended location for the help bundle is in the app's Contents/Resources folder. I can copy the help bundle there manually but it gets deleted every time I run my app in the IDE or deploy my app. I thought about trying to use the deployment manager but this only allows files to be deployed, not bundles. The help bundle contains a large number of files spread amongst various folders and it would be tedious to set each file up individually in the deployment manager. Moreover, I would have to change the setup every time I added or deleted a page from help since each page is a separate HTML file in the bundle. So for now, I am manually pasting the help bundle into Contents/Resources. Does anyone know of a more efficient method to incorporate the help bundle?
Read More

Delphi Firemonkey OSX how to show properly popup menu on button click?

I have a couple of buttons, which all have to show various popup menus when clicked. I use the following code in the onClick event of the buttons: procedure TForm1.btnExportClick(Sender: TObject); var pt:TPointF; begin pt.X:=0; pt.Y:=btnExport.Height; pt:=btnExport.LocalToAbsolute(pt); pt:=ClientToScreen(pt); mnuExport.Popup(pt.X,pt.y); end; When I click a button and release the mouse, the onClick event is triggered, the button turns blue and the popup menu appears. When I then click another button, without releasing the mouse (so it should not trigger a onclick event yet), the first popup menu vanish, but the popup menu of the other button appear and the onClick event is triggered (I see this in debugger). When I first close the popup menu by clicking somewhere else, then the other button also work as expected, but as long a popup menu is open, the buttons onClick event is triggered even I do not release the mouse button yet. There is definitely something wrong with my code or way to do it. Note: It only happen when running it on Mac OSX, not on Windows using FireMonkey. How to do it properly?
Read More