Category: Firemonkey

FireMonkey 3D Enterprise Application

You might remember me writing that the FireMonkey framework isn't a full-blown gaming engine and that it's better suited to enterprise applications. (rimshot)This is a follow up to my May the Fourth and Revenge of the Fifth posts. These 3D models are also from mods of Sins of the Solar Empire by a group named Stellar Parallax Studios who created Star Trek Armada 3 (STA3) and Ages of the
Read More

How do I get mouse cursor position behind a control?

I am using C++Builder 10.3 and FMX. There is a TImage control, on which multiple TRectangle controls are generated by some operation. The TRectangles are filled with claLightGray. To get the mouse cursor position, I am using the OnMouseMove event for the TImage control. The problem is that I cannot get the mouse cursor position when the mouse moves into a TRectangle control on the TImage control. How can I get the mouse cursor position for the TImage when it is on a TRectangle? I hope TRectangle is transparent to TImage in terms of mouse cursor position.
Read More

FireMonkey (FMX) code not compiling for Linux, works well on Win64

I want to extract pixel color values from a bitmap into a 2-dimensional array of floating point values for later post processing. This code works fine for me on Win64, but I can't compile this code now for Linux using the FMX framework. type TMyFunction = array of array of Real; var X, Y: Integer; CurrentData : TBitmapData; Color: TAlphaColor; afct : TMyFunction; abmp : TBitmap; if (abmp.Map(TMapAccess.Read, CurrentData)) then begin try for X := 0 to abmp.Width - 1 do for Y := 0 to abmp.Height - 1 do begin Color := CurrentData.GetPixel(X, Y); afct[X, Y] := TColorRec.ColorToRGB(Color).ToSingle; end; finally abmp.Unmap(CurrentData); end; end; The error message goes like this: [DCC Error] numeric.pas(444): E2018 Record, object or class type required I can't change the TMyFunction as used in many places in my project. Why does the assignment / .ToSingle require something different between Windows and Linux?
Read More

Rotation won’t work in firemonkey android app when clipchidren is active

I'm trying to rotate a TRectangle in Delphi 10.3.3. (FireMonkey App) the Trectangle has ClipChildren set to true. The rotation works fine in win32 but when trying in android it has a weird clipped shape. I tried it with different Objects(TPanel,TImage & ... ) and all results same. It seems that there is a bug with rotating shapes and clipchildren property in android. Here is a sample fmx file which works fine in win32 platform but not in ANDROID. object Form1: TForm1 Left = 0 Top = 0 Caption = 'Form1' ClientHeight = 329 ClientWidth = 259 FormFactor.Width = 320 FormFactor.Height = 480 FormFactor.Devices = [Desktop] DesignerMasterStyle = 0 object Rectangle1: TRectangle ClipChildren = True Fill.Color = claChartreuse Position.X = 80.000000000000000000 Position.Y = 104.000000000000000000 RotationAngle = 35.000000000000000000 Size.Width = 105.000000000000000000 Size.Height = 113.000000000000000000 Size.PlatformDefault = False end end Best regards, mohsen
Read More

Saving and Retrieving Boolean Value from Windows Registry

I'm attempting to save/retrieve a Boolean value from the Windows Registry using Delphi Rio (Firemonkey). No matter which state I save, true or false, the code always returns a true value. Here is a sample project that illustrates my method: uses System.IniFiles, System.Win.Registry; const AppRegKey = 'Software\Mycroft\TestApp'; procedure TForm2.btnReadClick(Sender: TObject); var Reg: TCustomIniFile; checked: boolean; begin Reg := TRegistryIniFile.Create(''); checked := False; if Reg.SectionExists(AppRegKey + '\State\BoxChecked') then begin checked := Reg.ReadBool(AppRegKey,'Show', True); end; if checked then ShowMessage('Checked') else ShowMessage('Unchecked'); end; procedure TForm2.btnSaveClick(Sender: TObject); var Reg: TCustomIniFile; begin Reg := TRegistryIniFile.Create(''); Reg.WriteBool(AppRegKey + '\State\BoxChecked', 'Show', chkBrandNew.IsChecked); end; It appears the value is being updated in the Registry, so I'm not sure why it always returns a True value. Can someone please point me in the proper direction?
Read More

Cannot load sqlite libraries in Android with Delphi 10.4

With Delphi 10.4 I get an error in my Android App (same error for both 32bit and 64bit). [FireDAC][Phys][SQLite]-314. Cannot load vendor library [libsqlite.so or libdb_sql.so]. Hint: check it is in the PATH or application EXE directories, and has x86 bitness. It has worked fine in previous versions of Delphi (latest 10.3.3). Is it at bug, or has something changed with Delphi 10.4? constructor TBrDataAccess.Create; var AppDataName: string; DBExists: boolean; begin try FFDGUIxProvider := 'Console'; AppDataName := TPath.GetDocumentsPath + PathDelim + GetFileName; DBExists := FileExists(AppDataName); FConnection:=TFDConnection.Create(nil); FConnection.Params.Add('DriverID=SQLite'); FConnection.Params.Add('Database=' + AppDataName); FConnection.Params.Add('OpenMode=CreateUTF8'); FConnection.Params.Add('DateTimeFormat=String'); FConnection.Params.Add('LockingMode=Normal'); FConnection.Params.Add('Synchronous=Normal'); FConnection.Params.Add('BusyTimeout=7500'); FConnection.Params.Add('SharedCache=False'); FConnection.FetchOptions.Mode := fmAll; // Meget vigtig ved SqLite. FConnection.UpdateOptions.LockWait := True; FConnection.Connected := true; if not DBExists then if FConnection.ExecSQLScalar('pragma schema_version;') = 0 then CreateDb; except on E : Exception do TBrMobileLog.AddLog(TBrLogFileType.LFTDb, 'TBrDataAccess', 'Create', E.Message, True); end; end;
Read More

DecodeBase64 and EncodeBase64 behaves differently in Delphi 10.2 and 10.3

I have following 2 programs: A flex server (Delphi 10.2 program that runs as a service that accepts POST and GET API calls) A mobile app in FireMonkey (Delphi 10.3 multi-device app that gets build to both Android and iOS) Have the following requirement: POST an image via an API call from the mobile app to the flex server. I have used Delphi's Soap.EncdDecd and System.NetEncoding libraries. Current process: Convert the TImage bitmap on the mobile app to a memory stream and convert it to a base64 string. POST the image to the flex server as a string. On the flex server, decode the string back to a memory stream based on base64 decode method in Soap.EncdDecd. On the mobile app, I convert the image to a Base64 string before sending it via the API call. The code looks something like follows: Var FImage: TMemoryStream; sImageBlob : String FAttachedImage.SaveToStream(FImage); // FAttachedImage is a TImage sImageBlob := EncodeBase64(FImage.Memory, FImage.Size) And in the flex server, I use the decode method to decode it back and save it to the DB: Var Serverimage: TMemoryStream; Serverimage := TBytesStream.Create(DecodeBase64(sImageBlob )) Problem: Since the flex server is version 10.2, it decode it back to AnsiString where the mobile app even though if I use the same library (Soap.EncdDecd) it encode it to a string, resulting on a failure to retrieve the correct image back. The main problem, as I see it, is inside Soap.EncdDecd have two Delphi versions. In Delphi 10.2, it decodes the string to an AnsiString and FireMonkey (Delphi 10.3) encode the image memory stream to a string. How ever the Delphi 10.2 flex server works fine with strings that I have sent via web apps which use JavaScript libraries to encode to base64. Can someone please help me with this problem, or provide ANOTHER way to pass an image as a string through an API call? And convert it back to a memory stream in the API server.
Read More

How to give name to column and fill data in row in Tgrid created at runtime; (Delphi)

I am new to Delphi Firemonkey using Embarcadero® RAD Studio 10 Seattle. I create at runtime a Tgrid. How can i give name to column and fill data in row ? My code is below. procedure TForm1.Button1Click(Sender: TObject); var Grid : TGrid; begin Grid := TGrid.Create(Form1); Grid.Visible := True; Grid.Parent := Form1; Grid.Align := Grid.Align.alClient; Grid.RowCount := 5; end;
Read More

bitblt replacement for FMX framework

we are using Delphi with VCL framework with the following code snipet tempBMP := TBitMap.create; tempBMP.SetSize(aLargeRectangle.Width, aLargeRectangle.Height); BitBlt(tempBMP.Canvas.Handle, 0, 0, tempBMP.Width, tempBMP.Height, MyOtherImage.Canvas.Handle, aLargeRectangle.Left, aLargeRectangle.Top, SRCCOPY) we are now working on crossplattform programming with these questions bitblt is part of gdi32.dll , does this mean 32 bit and only good/useable for smaller images ? How to use bitblt with FMX framework ? How to replace bitblt with pure FMX ? better and faster ?
Read More

Adding image to TTabItem in Firemonkey

I have a TTabControl with a single tab that displays an image on the tab when a field in the tab has contents. I've assigned an ImageList to the TTabControl. When I add additional TTabItems to the TTabControl, I am unable to assign an ImageIndex later in the code. Here is how I'm adding the new tab: procedure TfrmAddEditItem.LoadCustomFields; var NewTab: TTabItem; begin ... NewTab := TTabItem.Create(tabPictures); NewTab.Name := 'tab2'; NewTab.Text := FieldByName('FieldName').AsString; NewTab.Visible := True; NewTab.Enabled := True; NewTab.Tag := tabPictures.TabCount + 1; NewTab.Parent := tabPictures; ... end; But in another function in the form, when I try to set the image on the tab I get an Access violation exception: procedure TfrmAddEditItem.LoadDataFields; var FormFieldName: string; DBFieldName: string; begin ... FormFieldName := 'tab' + FieldByName('FieldID').AsString; DBFieldName := 'Field' + FieldByName('FieldID').AsString; Tab := TTabItem(Self.FindComponent(FormFieldName)); if FieldByName(DBFieldName).IsNull then Tab.ImageIndex := -1 else Tab.ImageIndex := 0; ... end; How can I set the ImageIndex value programatically on a TTabItem I added within the code? (Note that there are other events where I will also want to adjust the image based on the value in a database field.)
Read More