Category: StackOverflow

FireMonkey Application with Multiple Monitors

I need to get the Screen Scale for the monitor my application is being displayed on. The multi-platform run-time TPlatFormServices has a service called IFMXScreenService that returns the Screen Scale (GetScreenScale). The problem is it only returns it for the primary monitor. I need to get it for whichever monitor my application is being run on. Below is my C++ code for getting the IFMXScreenService. How do I modify it to get the screen service for my active monitor? if (TPlatformServices::Current->SupportsPlatformService(__uuidof(IFMXScreenService)) == true) { pScreenService_ = TPlatformServices::Current->GetPlatformService(__uuidof(IFMXScreenService)); }
Read More

Invoking/Executing a function AFTER caller function finished or returned in FMX or System Library

TMessageManager's 'SendMessage' method does NOT invoke the 'Subscribed' (or associated callback) function AFTER the function that calls the 'SendMessage' is finished. For a usable solution for this problem, I was thinking about using TTimer with least possible time interval (which is 1 millisecond) so that when you Enable the timer in the caller function, the OnTimer event of TTimer will have to be triggered AFTER the function that Enabled it. I think this is a kind of "slow" and ugly workaround to this problem. Is there any Application-wide messaging facility in FMX or System Library that can invoke a callback function AFTER the caller function is finished or returned ? (Other application messages processed/invoked between them is also okey) This is for FMX or Multi-Device Cross Platform development by the way. Not specific to VCL or Windows Environment. (What I really want, is to be able to send a message to the own application similar to the how Windows API function PostMessage behaves. The messages sended by PostMessage appear from windows procedure callback function after PostMessage function is returned.)
Read More

FMX: Vertical Scrollbox scroll programmatically not working

Hello Stack Community, Right now I'm developing an application for Android and iOS. I have a FMX Form with a TabControl. At Runtime I create Tabitems with a TVerticalScrollBox with several custom Panelclasses as Children. I created swipe gestures (left & right) to change between the TabItems, which is working perfectly. But when I want to scroll up and down my Custom Panels are catching the swipe gesture and not the Scrollbox. So I'm catching the swipe gestures (up & down) with my custom panels and try to scroll the VerticalScrollBox by Code, which is not working. I'm able to get the Owner (VerticalScrollbox) of the CustomPanel and parse it to a TVerticalScrollBox Component. But when I'm calling the ScrollBy Procedure of the VerticalScrollbox nothing happens. Any Suggestions or Workarounds? Best Regards some sample code The ScrollBox I create at Runtime: lScrollBox := TVertScrollBox.Create(lItem); lScrollBox.Parent := LItem; lScrollBox.Name := lScrollBox.ClassName + '_' + inttoStr(i); lScrollBox.Align := TAlignLayout.Client; lScrollBox.ShowScrollBars := False; lScrollBox.Visible := True; lScrollBox.Touch.GestureManager := lGesture; lScrollBox.Touch.StandardGestures := [TStandardGesture.sgLeft, TStandardGesture.sgRight,TStandardGesture.sgUp,TStandardGesture.sgDown]; lScrollBox.Touch.InteractiveGestures := [TInteractiveGesture.Pan]; lScrollBox.OnGesture := onGesture; my Custom Panels I Create at Runtime... Test := TjilsDatePanel.Create(lScrollBox); Test.Parent := lScrollBox; Test.TabNumber := i; Test.ObjectNumber := strtoint(jDate.GetValue<string>('key')); Test.Name := 'Test'+ jDate.GetValue<string>('key'); Test.Therapy := jDate.GetValue<string>('Therapie'); Test.Start := jDate.GetValue<string>('Start'); Test.Ende := jDate.GetValue<string>('Ende'); Test.Info := jDate.GetValue<string>('Termin'); Test.Touch.GestureManager := lGesture; Test.Touch.StandardGestures := [TStandardGesture.sgLeft, TStandardGesture.sgRight, TStandardGesture.sgUp, TStandardGesture.sgDown]; Test.Touch.InteractiveGestures := [TInteractiveGesture.pan,TInteractiveGesture.LongTap]; Test.OnGesture := onGesture; Test.setlGesture(lGesture); Test.setTabControl(lTabControl); Test.createObjects(Test.TabNumber); also my onGesture Procedure... procedure TReTinAMainLogicLayer.onGesture(Sender: TObject; const EventInfo: TGestureEventInfo; var Handled: Boolean); begin if Sender.ClassName = 'TVertScrollBox' then begin if EventInfo.GestureID = sgiLeft then ChangeTabActionPrevUpdate; if EventInfo.GestureID = sgiRight then ChangeTabActionNextUpdate; if EventInfo.GestureID = sgiUp then showMessage('TVertScrollBox UP'); if EventInfo.GestureID = sgiDown then showMessage('TVertScrollBox DOWN'); Handled := true; end; if Sender.ClassName = 'TjilsDatePanel' then begin if EventInfo.GestureID = sgiLeft then ChangeTabActionPrevUpdate; if EventInfo.GestureID = sgiRight then ChangeTabActionNextUpdate; if EventInfo.GestureID = igiLongTap then setUpComView(Sender as TjilsDatePanel); if EventInfo.GestureID = sgiUp then showMessage('TjilsDatePanel UP'); if EventInfo.GestureID = sgiDown then scrollUp(Sender as TjilsDatePanel); Handled := true; end; end; and finally my scrollUp Procedure... procedure TReTinAMainLogicLayer.scrollUp(Sender: TjilsDatePanel); var VertBox : TVertScrollBox; begin if Sender.Owner.ClassNameIs('TVertScrollBox') then begin VertBox := Sender.Owner as TVertScrollBox; VertBox.BeginUpdate; VertBox.ViewportPosition := TPointF.Zero; VertBox.ScrollBy(400,400); VertBox.ScrollTo(500,500); VertBox.RealignContent; VertBox.EndUpdate; end; end;
Read More

Is there a csOwnerdrawfixed Style or equivalent available for FMX TCombobox

I am converting a VCL project to FMX to take advantage of multi-platform functionality and add a more modern style to the project. I am using a TCombobox to display a location and an IP Address. In the VCL project I am able to use the csOwnerDrawFixed style that allows me to handle tsv formatted text and display neatly what displays as two columns in the combobox dropdown. I have searched high and low to find a similar method to do the same with the FMX combobox but to no avail. Is this functionality hidden away some place that I have yet to find or is it simply not available in the FMX combobox component? If the latter is the case, is there a way to show tsv formatted text in an FMX combobox. Any help much appreciated.
Read More

Delphi FMX form from a library (dll) into a panel in the main application

I've tried to follow the example of: http://docwiki.embarcadero.com/CodeExamples/Rio/en/FMXEmbeddedForm_(Delphi) but the form elements just don't appear. I'm using Delphi 10.3 and compiling for Windows. If both the form and the panel are in the library project or in the program project, then it works well. It's needed to work both in Windows and MacOS.
Read More

Change the selection opacity of a ListBox

I have trouble changing the selection opacity of the FireMonkey ListBox. In my case I wanted to change the color of the selection, and make it fully opaque. At first I tried to do this by changing the style of de ListBox through a custom style based on the default. The selection part is a TStyleObject with an opacity of 1. I replaced it with a TRectangle filled with the color Red. After I applied my style I noticed that the selection was not the same bright red color that I chose for the selection. So I just dove into the FMX.ListBox code to see what is happening there. To my surprise I found that the opacity of the selection is set to 0.7 hard-coded in the TCustomListBox ApplyStyle procedure. I expected that the style was responsible for how things looked. I don't know if it's the wrong way to think about it, but this is not what I expected. After this I tried changing the selection opacity run-time by implementing the OnApplyStyleLookup event with the following code. procedure TForm1.ListBox1ApplyStyleLookup(Sender: TObject); var SelectionControl: TControl; begin if ListBox1.FindStyleResource<TControl>('selection', SelectionControl) then SelectionControl.Opacity := 1; end; This however has no effect. I tried to do the same thing in a new custom ListBox control by deriving from TCustomListBox and overriding the ApplyStyle method where after the ApplyStyle of TCustomListBox through the inherited keyword I placed the code to set the selection opacity to 1. This too did not have any effect. Am I just going about this the wrong way, am I missing something, or is it just Delphi being weird.
Read More

Delphi firemonkey recieve new sms

I'm new to Delphi fire-monkey and android, i had tried sending new sms and fetching all received sms before successfully . I need a code to read new single sms just same time that android receives it. Its possible to read all received sms in a timer and recognize the changes but probable not good solution because of increasing CPU usage and not being real time. Thank you for any help and guiding.
Read More

Android FMX INDY SSL Works on debugging but not from PlayStore download

I'm facing a weird Delphi Indy SSL problem. I developed an app for Android which connects to an Server with SSL encryption. I provided OpenSSL libraries and it works fine on debugging the device (Samsung A 3 2016). But when I upload the .aab file and download the app from the PlayStore (internal Test), my app is unable to load the SSL libraries. So I tested with different devices to reproduce the bug. Unfortunately it worked on all device I downloaded the app (32bit and 64bit). I'm stuck with these particular device where I cannot reproduce the unable to load SSL Library mistake. Successful tested devices - Samsung S4 Mini (32bit) - Samsung S7 Mini - Sony XPeria XA (64Bit) - Sony XPeria XZ1 Compact ( - Huawei P30 (64Bit) Unsuccessful tested devices - Samsung A3 2016 (32bit) => this device is not able to load the SSL Libraries I provide here is the Code I use to set the path depending from the OS and CPU {$region 'Android'} {$IFDEF ANDROID} {$IFDEF CPU64BITS} FAppPath := TPath.Combine(TPath.GetDocumentsPath,'bit64'); MemoText := '64 bit SSL libs: ' + FAppPath ; Synchronize(doMemoAddLine); {$ELSE} FAppPath := TPath.GetDocumentsPath ; MemoText := '32 bit SSL libs: ' + FAppPath ; Synchronize(doMemoAddLine); {$ENDIF} IdOpenSSLSetLibPath(FAppPath); MemoText := 'IdOpenSSLSetLibPath(' + FAppPath +')' ; Synchronize(doMemoAddLine); MemoText := WhichFailedToLoad; Synchronize(doMemoAddLine); {$ENDIF} {$endregion}
Read More

Delphi Cannot change this property when using LiveBindings

Can anybody explain to me what the error message "Cannot change this property when using LiveBindings" is telling me? I am new to FMX / Live Bindings and I had something working, but I changed a few things and now, I am getting this error when trying to bind the fields of a TFDMemTable to a TGrid. I had the same fields from the same table bound to the grid before!
Read More

not showing icon in virtualtreeview node fmx

I'm working on fmx virtualtreeview and trying to load image in nodes using TImageList but unfortunately image is not showing whereas I tested on vcl and it worked. Any help would be appreciated here is my code: procedure TMainForm.VSTGetImageIndex(Sender: TBaseVirtualTree;Node: PVirtualNode; Kind: TVTImageKind; Column: TColumnIndex;var Ghosted: Boolean; var ImageIndex: TImageIndex); var Data: PVSTData; begin Data := Sender.GetNodeData(Node); if Kind in [ikNormal , ikSelected] then begin ImageIndex :=Data.ImageIndex; end; end; procedure TMainForm.FormCreate(Sender: TObject); var c: char; s: string; DriveType: integer; i: integer; Data:PVSTData; node:PVirtualNode; begin i:=0; VST:= TVirtualStringTree.Create(Self); VST.Parent:= Self; VST.Images:=ImageList1; VST.BorderStyle:=TFormBorderStyle.bsnone; VST.Fill.Color:= TAlphaColorRec.White; VST.Height:= 262; VST.Align:= TAlignLayout.Top; VST.OnInitNode := VSTInitNode; VST.OnFreeNode := VSTFreeNode; VST.OnGetText := VSTGetText; VST.OnGetImageIndex:=VSTGetImageIndex; VST.NodeDataSize := SizeOf(PVSTData); for c:='A' to 'Z' do begin s:=c+':'; DriveType:=GetDriveType(PChar(s)); if DriveType=1 then continue; System.Inc(i); node:=AddChild(nil, s); VST.HasChildren[node]:=True; Data := Vst.GetNodeData(Node); Data.ImageIndex:= i; //Added 4 icons in accordance with drives end; end;
Read More

How to minimize to the tray on FMX

I am creating a launcher for the apps of my work. I want that when I minimize the app, he goes to the tray. I manage to create the icon with a button (the click call the proc), but I don't know what events I need to call the proc, there is no event like Onminized and the event OnHide does not affect. I see some posts about using a Hook ( i am not pretty sure whats is), I try it, but I got an error: [dcc32 Error] UMain.pas(129): E2036 Variable required. This point here: procedure TfrmMain.FormCreate(Sender: TObject); begin SetWindowsHookEx(WH_CALLWNDPROC, @WndProc, 0, GetCurrentThreadId); end; More specific to @wndProc, i try to remove the @ and I got [dcc32 Error] UMain.pas(129): E2009 Incompatible types: 'regular procedure and method pointer' Type... function WndProc(Code: integer; WParam, LParam: LongInt): LRESULT; stdcall; var WndProcHook: THandle; const WM_TRAYICON =WM_USER+1; ------------------------------------------------------ procedure TfrmMain.FormCreate(Sender: TObject); begin SetWindowsHookEx(WH_CALLWNDPROC, @WndProc, 0, GetCurrentThreadId); .... end; function TfrmMain.WndProc(Code: integer; WParam, LParam: LongInt): LRESULT; stdcall; var msg: TCWPRetStruct; begin; if (Code >= HC_ACTION) and (LParam > 0) then begin msg := PCWPRetStruct(LParam)^; if (msg.Message = WM_SIZE) and (msg.WParam = SIZE_MINIMIZED) then begin criaIcone; end; end; result := CallNextHookEx(WndProcHook, Code, WParam, LParam) end; // procedure TfrmMain.CriaIcone; var NotifyIconData: TNotifyIconData; begin with NotifyIconData do begin cbSize := SizeOf; Wnd := AllocateHWnd(WMTrayIcon); uID := 0; uCallbackMessage:= WM_TRAYICON; uFlags := NIF_ICON or NIF_TIP or NIF_MESSAGE; hIcon := GetClassLong(FmxHandleToHWND(self.Handle),GCL_HICONSM); szTip := 'Teste TrayIcon'; end; Shell_NotifyIcon(NIM_ADD, @NotifyIconData); end;
Read More