Category: StackOverflow

FMX MacOS64 button click not firing within printing loop

I'm sure this is simple but I've spent hours and am missing the solution. Working in Delphi FMX MacOS64. (This same structure works fine in Delphi VCL). I have a simple while loop that prints a multi-page report. When the report starts, I show a small "cancel printing" form that shows the page number being printed, and has a Tbutton marked "Cancel". I change the page number shown on the form each time through the loop (and that works fine). But the button won't respond unless I click it multiple times to get focus, and then multiple times again to get an actual click event to occur. I assume the OS has taken control and is not giving any cycles to check the button. How do I get around it? I've tried setting "repeat click" to true, and that seems to have an effect, but it is set to not repeat the first time until 1/2 second has passed, which is way too long to stop the printing, even if it works on the first repeat. Here's the code: Printer.BeginDoc; [do some stuff] iI:=1; labelcountI:=1; pageI:=1; while (iI<readfileSS.count) and (pageI<=ToPageI) do begin if readfileSS[iI]<>'' then begin [do some stuff] if isZebraB=false then begin if (labelcountI = 1) and (iI <> 1) and (pageI >= FromPageI + 1) then begin if cancelPrintB=true then endPrintB:=true; //cancelprintB is set to true in the click event if endprintB=false then begin printer.NewPage; cancelprint.page.text:=IntToStr(pageI); //cancelprint is the form; this line works if cancelprint.visible then begin cancelprint.Invalidate; cancelprint.CancelBtn.repaint; //have tried with and without this end else begin cancelprint.show; end; application.processmessages; end else begin cancelprint.close; end; if (pageI >= FromPageI) and (endprintB=false) then begin [print a lot of stuff] end; end; end; inc (iI); end; Here's the code for the button. Pretty simple. procedure TCancelPrint.OKButtonClick(Sender: TObject); begin cancelPrintB:=true; hide; end; I have put a message in the OnClick code, and confirmed that it is not firing. As I said, this must be easy, but apparently not for me. Appreciate any help. Thanks. Scott
Read More

How can I read and set the paper style (aka papername) in Firemonkey MacOS

Working in Delphi Firemonkey for Mac OS64. Trying to read and then set the variable Apple calls the "paperName", which is the paper type (letter, legal, envelope, etc.) I know that it is accessed through NSPrinter.PaperName? but I do not understand how to code FMX to access it. I'm using cookbooked code to get the paper rectangle: FPrintInfo := TNSPrintInfo.Wrap(TNSPrintInfo.OCClass.sharedPrintInfo); FPrintInfo.retain; PMGetAdjustedPaperRect(FPrintInfo.PMPageFormat, @PaperRect); FPrintInfo.release; but I'm not experienced at all with Mac code so my attempts to plug-and-play off of this code to get papername have not been successful. Thanks for your help. Dave, Thanks. Sorry, I didn't really give you enough info. The code I provided does work, to get the paper rectangle. What I am trying to get, in addition, is the paper name, and I can't figure out what function will get me that. I'm trying to use PMGetPageFormatPaper(FPrintInfo.PMPageFormat, @PaperTypeS); but I think I may not be declaring PaperTypeS correctly. What I'm trying is: function getPaperShape: string; var FPrintInfo: NSPrintInfo; PaperRect: PMRect; paperwidth,paperheight:double; paperTypeS:string; begin FPrintInfo := TNSPrintInfo.Wrap(TNSPrintInfo.OCClass.sharedPrintInfo); FPrintInfo.retain; PMGetAdjustedPaperRect(FPrintInfo.PMPageFormat, @PaperRect); PMGetPageFormatPaper(FPrintInfo.PMPageFormat, @PaperTypeS); FPrintInfo.release; paperwidth:= PaperRect.right-PaperRect.left; paperheight:= PaperRect.bottom-PaperRect.top; end; That clearly is not correct, since I get nothing returned in paperTypeS. I've tried declaring paperTypeS as NSPrinter.PaperName, or just as PaperName, or as PMPaperName, but clearly I'm just guessing here and none of those are recognized by FMX as valid types. Does that make more sense? Again, thanks. Scott
Read More

How to use for in with TTabControl in Delphi FMX?

Sorry if this is a duplicate question but I didn't find a solution anywhere. I want to make a for in to search for a specific tag on my many tabbed TTabControl component, but I have no clue on how to do this. My TTabControl named TabControl1 receives its tabitems during runtime by a query. It has to be designed to support from 1 to 100+ tabs if the client wants it. So each tab has a description which is its name and an index on my category table, each time I create a TTabItem, I assign it a tag which is the tab index on my sql table SQL:: DROP TABLE IF EXISTS Category; CREATE TABLE Category ( CAT_ID integer primary key , CAT_Descr Varchar(200) ); Delphi:: FDQ.Close; FDQ.Open('SELECT * FROM Category'); while not FDQ.Eof do begin TabControl1.Add().Tag := FDQ.FieldByName('CAT_ID').AsInteger; FDQ.Next; end; For my testing purposes I have 5 items on the database: ([1, tab1], [2, tab2], [3, tab3], [4, tab4], [5, tab5]) So when I run the code, it creates 5 tabs with a tag from 1 to 5 on them, great, the tag works. But now I need to populate these tabs with items made in runtime also from a query and now is the part where the for in will happen, but that's where I don't know how to make it loop properly on the tabs procedure TfListing.createtabs; var dummytoolbar: TToolBar; dummylabel: TLabel; dummylistbox: TListBox; tabitem: TTabItem; dummylistitem: TListBoxItem; begin // listboxitemlabel // listboxitemdetaillabel for DM.FDQ.FieldByName('CAT_ID').AsInteger in TabControl1.Tabs[].Tag do <<== this is the line with the issue begin try dummytoolbar := TToolBar.Create(tabitem); dummytoolbar.Parent := tabitem; dummytoolbar.Align := TAlignLayout.Top; dummylabel := TLabel.Create(dummytoolbar); dummylabel.Parent := dummytoolbar; dummylabel.Align := TAlignLayout.Contents; dummylabel.StyleLookup := 'toollabel'; dummylabel.Text := DM.FDQ.FieldByName('CAT_Descr').ToString; dummylabel.TextAlign := TTextAlign.Center; dummylistbox := TListBox.Create(tabitem); dummylistbox.Parent := tabitem; dummylistbox.Align := TAlignLayout.Client; dummylistitem := TListBoxItem.Create(dummylistbox); dummylistitem.Parent := dummylistbox; dummylistitem.Height := 44; dummylabel := TLabel.Create(dummylistitem); dummylabel.Parent := dummylistitem; dummylabel.Align := TAlignLayout.MostLeft; dummylabel.StyleLookup := 'listboxitemdetaillabel'; dummylabel.Text := dm.FDQ.FieldByName('PRO_Stock').AsString; dummylabel := TLabel.Create(dummylistitem); dummylabel.Parent := dummylistitem; dummylabel.Align := TAlignLayout.Client; dummylabel.StyleLookup := 'listboxitemlabel'; dummylabel.Text := dm.FDQ.FieldByName('PRO_Name').AsString; finally dummytoolbar.DisposeOf; dummylabel.DisposeOf; dummylistbox.DisposeOf; dummylistitem.DisposeOf; end; end; end; How can I make it work?
Read More

How to read/send data to arduino over headphone jack with Firemonkey?

Is there any source (like document, code samples etc.) or component to read data sent by (and send data to) arduino via audio jack. There are some examples on here, here and here but I couldn't find how to read this data with Delphi (FireMonkey). Added After Codebreaker007's comment I'm trying to communicate Arduino Pro Mini with Android/iOS app (this is an iOT project) to let phone app send some command and device collect some data then send to the phone I don't need to connect my gadget to the PC (it is for just Mobile) serial over usb is not an option because some software/hardware requirements (sort OTG cable, USB Host settings, drivers etc..) so I just want to get data over 3.5mm TRS (3 pin - preferred) or TRRS(4pin) stereo jack. In addition, Arduino Pro Mini has no USB interface and I don't want to use USB to TTL Converter due to its size
Read More

Delphi Firemonkey Programmatic Data File Export to Excel — Where are the units and methods?

TeeChart can export data from the chart editor (tcharteditor). In VCL and (judging from documentation) .net, one can programmatically export using the chart1.export command. I am looking to do the same from TeeChart FireMonkey. What unit adds such a command? Shouldn't there be Chart1.Export?
Read More

Audio playback rate on ios and firemonkey app

I'm looking for the way to change audio playback rate(playback speed) on iOS with firemonkey application. I found MPMediaPlayback interface and setCurrentPlaybackRate procedure in iOSapi.MediaPlayer unit in iOSapi.MediaPlayer.pas, but I couldn't figure out how to use this interface with TMediaPlayer component nor TMPMusicPlayerController class. Environment Windows 10 Home 1809 Delphi 10.3 Update3 26.0.36039.7899 MacBook Pro 13 inch early 2011 macOS Sierra 10.12.6
Read More

How to change a stylebook’s style resource properties from a TStyleBook object runtime

I want to be able to change style resources from a given stylebook object on FMX. I know that I can change a specific object style by using the following commands r1 := aButton.FindStyleResource('backgroundRect') as TRectangle ; if Assigned(r1) then r1.Fill.Color := TAlphaColor(col); However I need this to change for all the objects that have this style resource and not that specific "aButton". How am I able to do it, so that I won't be forced to achieve this by looping through all the objects that i want to be changed?
Read More

What is `External exception A0` and what is the root cause?

On my mobile app, under android, build with Delphi Rio in 64 bit, I have often some exceptions named "External exception XX" like for example : External exception 90 External exception 87 External exception A0 etc... and this a little everywhere in the code, even at very usual place like : Fmx.Types.ArrangeControl(Fmx.Types.IAlignableObject, Fmx.Types.TAlignLayout, Single, Single, Single, Single, var Types.TRectF) or TRectF.Offset(Double, Double) but also in other places. I can not reproduce this problem locally, I receive this error log from client devices and it's on every devices not only on a specific one. for example this is the call stack of one of the report I receive: External exception B0 At address: $0000007FFE2E2270 Call stack: libmyapp.so $000000726EE8F618 Grijjy.Errorreporting.TgoExceptionReporter.GlobalGetExceptionStackInfo(TExceptionRecord*) + 128 libmyapp.so $000000726E61D5E0 Sysutils.Exception.RaisingException(TExceptionRecord*) + 52 libmyapp.so $000000726E647BD4 Sysutils.RaiseExceptObject(TExceptionRecord*) + 64 libmyapp.so $000000726E5FDB60 _RaiseAtExcept(TObject*, Pointer) + 100 libmyapp.so $000000726E61C6AC Internal.Excutils.SignalConverter(NativeUInt, NativeUInt, NativeUInt) + 56 libmyapp.so $000000726EC63E80 Fmx.Types.ArrangeControl(Fmx.Types.IAlignableObject, Fmx.Types.TAlignLayout, Single, Single, Single, Single, var Types.TRectF) + 112 libmyapp.so $000000726EC646BC Fmx.Types.AlignObjects(Fmx.Types.TFmxObject*, Fmx.Types.TBounds*, Single, Single, var Single, var Single, var Boolean).DoAlign(Pointer, Fmx.Types.TAlignLayout) + 556 libmyapp.so $000000726EC64954 Fmx.Types.AlignObjects(Fmx.Types.TFmxObject*, Fmx.Types.TBounds*, Single, Single, var Single, var Single, var Boolean) + 508 libmyapp.so $000000726ECD7AF8 Fmx.Forms.TCustomForm.Realign() + 168 libmyapp.so $000000726ECD391C Fmx.Forms.TCommonCustomForm.Updated() + 36 libmyapp.so $000000726ECD3868 Fmx.Forms.TCommonCustomForm.EndUpdate() + 252 libmyapp.so $000000726ECD892C Fmx.Forms.TCustomForm.EndUpdate() + 20 libmyapp.so $000000726F078090 main.TMainForm.ShowFrame(baseframe.TMainBaseFrame*, Boolean, definition.TShowFrameTransition) + 3304 libmyapp.so $000000726F078A2C main.TMainForm.ShowPreviousFrame() + 1820 libmyapp.so $000000726F0717E4 main.TMainForm.FormKeyUp(TObject*, var Word, var Char, set of Classes.System_Classes__1) + 452 libmyapp.so $000000726ECD2D0C Fmx.Forms.TCommonCustomForm.KeyUp(var Word, var Char, set of Classes.System_Classes__1) + 104 libmyapp.so $000000726EC15978 Fmx.Platform.Ui.Android.TAndroidTextInputManager.KeyUp(var Word, var Char, set of Classes.System_Classes__1, Boolean) + 72 libmyapp.so $000000726EC114B0 Fmx.Platform.Ui.Android.TAndroidTextInputManager.HandleAndroidKeyEvent(AInputEvent*) + 976 libmyapp.so $000000726EC39204 Fmx.Platform.Android.TPlatformAndroid.HandleAndroidInputEvent(Androidapi.Appglue.TAndroidApplicationGlue*, AInputEvent*) + 64 libmyapp.so $000000726E8F723C Androidapi.Appglue.TAndroidApplicationGlue.InputEventHandler(Integer, Integer, Pointer) + 184 libutils.so $0000007312C962D0 android::Looper::pollInner(int) + 936 libutils.so $0000007312C95E90 android::Looper::pollOnce(int, int*, int*, void**) + 64 $0000007310BF4A80 What can cause this error and how can I found the root cause?
Read More

Delphi/Firemonkey How to call Settings.System.canWrite(context) (Android)

I'm using Delphi 10.3 Community Edition and want to use the WRITE_SETTINGS in my application to set the brightness. I could get it managed to implement this procedure to call the settings dialog: procedure RequestWriteSettings; var Intent: JIntent; begin Intent := TJIntent.JavaClass.init(TJSettings.JavaClass.ACTION_MANAGE_WRITE_SETTINGS); TAndroidHelper.Activity.startActivity(Intent); end; I can call this procedure in my application, the dialog appears and I can set the necessary permissions. But I don't want to call this procedure permanently, because that's not user friendly. I need to check if the WRITE_SETTINGS permission is already set, but I don't know how to implement this in Delphi/Firemonkey. What I could find is that one has to call the "Settings.System.canWrite(context)" function, but I only can find samples for java. Calling these kind of java routines in Delphi isn't that easy. I'm searching around already for some weeks and tried "things on my own", but still without success. Can someone provide the code line how this routine has to be called in Delphi? Thanks so much in advance! MPage
Read More

FireMonkey – Distributing Win32 application

I have developed a Win32 FireMonkey app using IBLite embedded database manager. I want to distribute it to other Win32 environments, using Inno Setup. I have configured the Deployment info on Tools > Options according with Port number and IP address suggested by AP-server, set the password to masterkey, tested the connection (which is OK) and make the Deploy. Next, on Inno setup, on Files section, I included all generated files and set DestDir = "{app}\DestPath", where DestPath is the same as in the output dir of the generated Deploy dir. Then I built the script and run the installation file. Every thing is OK on Program Files (x86)\MyApp: all files where correctly copied at their respective directories. Nevertheless the app stacks, because can not get access to the database (I know this is true, because I did the whole process without database access and the main app screen was correctly displayed). The database itself, is placed on C:\Users\Public\Documents. My environment: OS - Windows 10 64 bits (updated) IDE - Rad Studio 10 Rio (version 20) app kind - FireMonkey What I am missing?
Read More