Category: Firemonkey

RestoreCapture FMX – Win32

I took this example of subclassing a Form's HWND as a starting point and then added in jrohde's code from from here that is designed to let you drag a Form by clicking anywhere on it (not on the caption bar). This code fails on the ReleaseCapture()line with this message: E2283 Use . or -> to call '_fastcall TCommonCustomForm::ReleaseCapture() If i comment that line out the code runs and i can move the form by left mouse don and drag, but i can't let go of it. The mouse gets stuck to the form like flypaper. If i replace the ReleaseCapture() with a ShowMessage i can break out but that is obviously not the way to go... What do i need to do allow that RestoreCapture() to run? This is Win32 app. BELOW IS THE CODE i added to the original switch(uMsg) block: // two int's defined above the switch statement static int xClick; static int yClick; // new case added to the switch case WM_LBUTTONDOWN: SetCapture(hWnd); xClick = LOWORD(lParam); yClick = HIWORD(lParam); break; case WM_LBUTTONUP: //ReleaseCapture(); // This is the problem spot <------------------------ ShowMessage("Up"); break; case WM_MOUSEMOVE: { if (GetCapture() == hWnd) //Check if this window has mouse input { RECT rcWindow; GetWindowRect(hWnd,&rcWindow); int xMouse = LOWORD(lParam); int yMouse = HIWORD(lParam); int xWindow = rcWindow.left + xMouse - xClick; int yWindow = rcWindow.top + yMouse - yClick; SetWindowPos(hWnd,NULL,xWindow,yWindow,0,0,SWP_NOSIZE|SWP_NOZORDER); } break; thanks, russ
Read More

Delphi XE (Firemonkey) problem when updating more image on runtime (android)

I cam creating an app for Android with Delphi XE 10.3, Firemonkey. I have tried every possible idea and searched online for days but can't find a solution. I have many PNG images loaded as assets (RT_RCDATA). If I have one button that does the following: .... InStream := TResourceStream.Create(HInstance, 'PngImage_'+inttostr(trunc(TrackBar2.Value)), RT_RCDATA); try Image1.Bitmap.LoadFromStream(InStream); finally InStream.Free; Then every time I click on the button, the image is shown correctly. BUT, If I try to load and show, for example 3 or 4 images,with some delay between them, (like an automatic slideshow), then the image is not updated, so only the last image is shown. I have tried everything, from repaint, refresh methods, hide/show visibility, calling application.processmessages, loading a bitmap and drawing it to form canvas, using a timer, but I can't find a solution. Thanks
Read More

fire event after mouse moves form – FMX C++

I want to run a block of code after my form has been moved on the screen by the traditional "left-mouse down on caption bar and drag to new spot". OnMouseUp only works on the form itself, not for mouse click on the title bar. This is C++ and Win32 app. thanks, russ UPDATE 1: Showing code i implemented based on Remy's answer. I implemented his code from that other post and then added another item to the switch(uMsg) to catch the WM_MOVE message. This didn't work. case WM_MOVE: { ShowMessage("Moved"); } UPDATE 2: I changed the above from WM_MOVE to WM_EXITSIZEMOVE based on Remy's comment and it works great now. Fires 1 time when i get through moving the form. case WM_EXITSIZEMOVE: { ShowMessage("Moved"); } Just what i wanted.
Read More

Firemonkey – How to position a new form under a TComponent

I am developing an application for Windows/Apple with Delphi 10 and Firemonkey. My main form has a TButton. When I press the TButton I would like to create and positioning Form1 exactly under the TButton. Here there is my code: //Transposes the coordinates in the context of the form. myTPointF := TButton.LocalToAbsolute(TButton.Position.Point); //Transposes the coordinates in the context of the screen. myTPointF := ClientToScreen(myTPointF); Form1.Top := FloatToStr(myTPointF.X) + Round(TButton.Height); Form1.Left := FloatToStr(myTPointF.Y); And if the TButton is near the Point(0,0) of the form (not the screen) it works, but the more is away from this point the more Form1 is wrong when i open it. Link for the image: https://ibb.co/85dfr9R https://ibb.co/t2stMHv Thanks in advance for the help.
Read More

IOS: Is their anyway to run a command just after file are deployed?

Is their anyway to run a command just after files are deployed via PASERVER (and before the install/signing process start)? I found some events like pre-build, post-build and pre-link but all those events are fired before the file are deployed. it's related to this bug report: https://quality.embarcadero.com/browse/RSP-22899
Read More

Delphi Firemonkey creating TExpanders and TLabels at runtime

Using Rad Studio 10.3 I am creating TExpanders at runtime based on a FireDAC query. However i am running into an issue setting the Parent of the label to the expander i have just created. I am using the following to create the components procedure TfrmMain.FormCreate(Sender: TObject); var i: integer; begin // Populate previous saved conversions stringgrid FDQuery1.SQL.Clear; FDQuery1.Close; FDQuery1.SQL.Add('SELECT convert from conversions'); FDQuery1.Open; i := 1; while not FDQuery1.Eof do begin // Create Expanders here to display database query to user exp := TExpander.Create(Self); exp.Parent := layoutDBDisplay; exp.Align := TAlignLayout.Top; exp.Name := 'dbExp' + i.ToString; exp.Height := 100; exp.TextSettings.Font.Size := 14; exp.TextSettings.Font.Style := [TFontStyle.fsBold]; // Create TLabel inside of above expander lab := TLabel.Create(Self); lab.Parent := TExpander; lab.Align := TAlignLayout.Top; lab.Name := 'dbResLabel' + i.ToString; inc(i); FDQuery1.Next; end; FDQuery1.Close; end; The issue is lies in this line lab.Parent := expName; Obviously the above won't compile because of the following [dcc32 Error] frmConverter.pas(266): E2010 Incompatible types: 'TFmxObject' and 'class of TExpander' Is there a simple solution to this?
Read More

delphi/IOS: How with PASERVER sign dynamic libraries before to deploy them?

To include a dynamic library in your iOS app, this dynamic library must be signed. When you deploy an app, Delphi automatically signs the app through the PASERVER. Is their anyway to order PASERVER to also sign the included dynamic libraries? (that are in the subfolder Frameworks/ of the app). Or is there any other way to automate this task? Exactly i need to execute this line before to deploy the app : "/usr/bin/codesign" -s "<myProfile>" "/Users/me/PAServer/scratch-dir/ALLiveVideoChatClient.app/Frameworks/WebRTC.framework/WebRTC"
Read More

onMouseMove override keeps onMouseUp from working

I have a TreeViewItem which its onMouseUp is not fired, I tried shrinking my complicated class and I was able to produce a working example of a onMouseUp not working, it seems the onMouseMove override is causing this behavior which is a mystery because I am using onMouseUp and I'm not overriding the onMouseMove! How can I fix this code? unit Unit2; interface uses System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Layouts, FMX.TreeView; type TForm2 = class(TForm) procedure FormCreate(Sender: TObject); private { Private declarations } procedure MouseMove(Shift: TShiftState; X, Y: Single); override; procedure onItemMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Single); public { Public declarations } end; var Form2: TForm2; implementation {$R *.fmx} procedure TForm2.FormCreate(Sender: TObject); var treeView: TTreeView; treeViewItem: TTreeViewItem; begin treeView := TTreeView.Create(nil); treeView.Position.X := 0; treeView.Position.Y := 0; treeView.Width := 200; treeView.Height := 300; treeView.Parent := form2; treeViewItem := TTreeViewItem.Create(nil); treeViewItem.Parent := treeView; treeViewItem.Text := 'This is a test'; treeViewItem.OnMouseUp := onItemMouseUp; end; procedure TForm2.onItemMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X: Single; Y: Single); begin ShowMessage('onItemMouseUp'); end; procedure TForm2.MouseMove(Shift: TShiftState; X: Single; Y: Single); begin end; end.
Read More

Delphi Error creating form: Error reading PastMovesGrid.OnClick: Property OnClick does not exist

Migrating a project from Delphi XE7 to 10.3 Rio. Delphi Rio gives this error: Error creating form: Error reading PastMovesGrid.OnClick: Property OnClick does not exist. PastMovesGrid is a TStringGrid. Sure enough, OnClick is no longer part of TStringGrid in the latest FMX. I've opened the DFM for the form and there is no reference to OnClick for the PastMovesGrid. When I tell Delphi to Ignore the missing property, the form does open, but when I run the app I get a runtime error about the "Property OnClick does not exist." I get the same results with Delphi 10.2.3. How do I get Delphi 10.3 to forget about this missing property?
Read More

Conditional compilation for various Delphi versions

If you are maintaining a library, component or plugin for various Delphi versions you will sooner or later hit a point where it becomes necessary to have different code for some of them. Some examples are: The constants faTemporary and faSymlink are only declared in Delphi 2009 and later, so you have to declare them yourself for older versions. Some Open Tools API function have bugs in some versions so you have to implement a workaround. Some classes or functions have been added to later versions of the RTL so you need to implement them yourself for older versions, but you don’t want to use these implementations for newer versions The traditional way of masking code for some Delphi versions is using the VERxxx symbols which the compiler defines, where xxx is the compiler version multiplied by 10. Note that the compiler versions started with Turbo Pascal, not with Delphi, so VER60 is not Delphi 6 but Turbo Pascal 6, while Delphi 6 is compiler version 14 and therefore defines VER140. By the time of this writing the current Delphi version is 10.3 Rio which contains the compiler version 33. {$IFDEF VER330} // Delphi 10.3 Rio // do some version specific stuff here {$ENDIF} There are various include files that make this more convenient by adding symbols like DELPHInn and DELPHInn_UP so you don’t have to memorize those VERxxx symbols. {$IFDEF DelphiX103} // do some version specific stuff here {$ENDIF} But using these include files has got a major drawback: If you forget to include it into your source code, all your IFDEFS will fail and in the worst case your workaround won’t be active (the best case is that the compiler runs into an error so you will notice the missing include). An alternative is the {$IF } compiler directive which can test for arbitrary Boolean expressions, like const SomeConstantValue = 5; //later on {$IF SomeConstantValue >= 5} // do some stuff here that requires SomeConstValue to be at least 5 {$ENDIF} It was added to the Delphi compiler in Delphi 6, so it covers quite a few Delphi versions. Combined with predefined constants (in the System unit) like CompilerVersion RtlVersion FireMonkeyVersion (in FMX.Types) this is a powerful method for conditional compilation. {$IF CompilerVersion = 330} // Delphi 10.3 Rio // do some version specific stuff here {$ENDIF} It can also replace those additional symbols DELPHInn_UP I mentioned above: “>=” replaces {$IFDEF DELPHInn_UP} and “=” you can “future proof” your code, assuming that code for Delphi 10.3 Rio will also work with all newer versions of Delphi. {$IF CompilerVersion >= 330} // Delphi 10.3 Rio // do some version specific stuff here that will // hopefully also work in the future {$ENDIF} But unfortunately we are back to memorizing compiler and RTL version constants. Even with tools like the IF Directive Expert in GExperts this is a nuisance because if you forget to add a comment (or if you later change the expression and forget to update the comment), you will still have to know those values to understand the code. So, what can be done? An idea that occurred to me today (Yes, I am a bit slow on creativity.) would be to define additional constants which can then be used to compare against the CompilerVersion and RtlVersion constants. unit CompilerAndRtlVersions; interface const CompilerVersionDelphi6 = 14; CompilerVersionDelphi7 = 15; // we all want to forget Delphi 8, but it had compiler version 16 CompilerVersionDelphi2005 = 17; CompilerVersionDelphi2006 = 18; CompilerVersionDelphi2007 = 18.5; // anybody remember Delphi 2007 for dotNET? That one had compiler version 19 CompilerVersionDelphi2009 = 20; // and so on until CompilerVersionDelphiRio = 33; // and of course we would also need the RtlVersions: const RtlVersionDelphi6 = 14; RtlVersionDelphi7 = 15; // and so on until RtlVersionDelphiRio = 33; implementation end. Add the above unit to the uses clause and you can do: {$IF CompilerVersion >= CompilerVersionDelphiRio} // do some version specific stuff here {$ENDIF} These constants should go into a unit rather into an include file so the compiler will complain if you forget to add that unit to the uses clause. In addition a unit will be compiled once and afterwards the compiler will use the DCU file it created, while an include fill will be parsed every single time it is included. This should speed up compilation a (probably tiny) bit. I am not aware if such a unit already exists, but I would probably write it and make it available if not (it’s not excactly rocket science after all). Edit: Here you go, my brand new u_dzCompilerAndRtlVersions unit. I already blogged about using and ab-using ifdef in 2013, if you are interested in this topic.
Read More