Category: StackOverflow

Instructions for working with the TGrid component from the FireMonkey library

I’m trying to find some instructions for working with the TGrid component from the FireMonkey library. All I found were two sentences from the documentation. http://docwiki.embarcadero.com/Libraries/Sydney/en/FMX.Grid.TGrid But this is too little. Does anyone know any other links to the description of this component? I can’t even understand, TGrid is a Data-aware or not a Data-aware component.
Read More

how to make all cells readonly in TMSFMXGrid (in Firemonkey)?

I am using Embarcadero® RAD Studio 10 Seattle Version 23.0.20618.2753 To make column read-only I used Grid_All_Party.Columns[2].ReadOnly := True; and to make cell read-only I used Grid_All_Party.ReadOnlys[1,0] := True; but how to make all cells of grid read-only without using the below code personally for all columns. Grid_Name.Columns[column_number].ReadOnly := True;
Read More

How do I get Mobile Numbers using Delphi FMX Address Book component

Delphi 10.3. Cross platform application. Android & IOS. I am using the TAddressbook component and the following code adapted from the Delphi code examples. I am able to get the names and photos but cannot workout the syntax for the phone numbers. The code fills the Listview with firstname / surname & image but the Contact.Phones seems to be an array. I found this in the documentation Phones.AddPhone(TContactPhone.TLabelKind.Mobile, '+33-6-46-51-3531'); So I need somthing like this Phones.Extract(TContactPhone.TLabelKind.Mobile); // Does not work. procedure TformMain.FillContactList(Source: TAddressBookSource); var I: Integer; Contacts: TAddressBookContacts; begin Contacts := TAddressBookContacts.Create; try AddressBook1.AllContacts(Source, Contacts); ListViewContacts.BeginUpdate; try ListViewContacts.Items.Clear; for I := 0 to Contacts.Count - 1 do AddListViewItem(Contacts.Items[I]); //AddListViewItem(Contacts.Items[I].Phones[0].Number) finally ListViewContacts.EndUpdate; end; finally Contacts.Free; end; end; procedure TformMain.AddListViewItem(Contact: TAddressBookContact); var ListViewItem: TListViewItem; eMails: TContactEmails; phones: TContactPhones; c : TAddressBookContact; begin phones := Contact.Phones; if Contact.DisplayName.Length > 0 then begin ListViewItem := ListViewContacts.Items.Add; try // ListViewItem.Data['Text2'] := Contact.Phones.Extract(TContactPhone.SupportedLabelKinds('Mobile')); // ListViewItem.Data['Text2'] := Phones.ExtractItem.LabelText. (TContactPhone.TLabelKind.Mobile, '+33-6-46-51-3531'); //ListViewItem.Data['Text2'] := Phones.ex ExtractItem AddPhone(TContactPhone.TLabelKind.Mobile, '+33-6-46-51-3531'); ListViewItem.Data['Text1'] := Contact.DisplayName; ListViewItem.Data['Text2'] := '07446944654'; // from sample eMails.AddEmail(TContactEmail.TLabelKind.Work, edtWorkMail.Text); // TLabelKind = (Custom, Home, Mobile, Work, iPhone, FaxWork, FaxHome, FaxOther, Pager, Other, Callback, Car, CompanyMain,ISDN, Main, Radio, Telex, TTYTDD, WorkMobile, WorkPager, Assistant); // ListViewItem.Data['Text2'] := c.Phones.First.LabelKind.Mobile.t;// Phones.IndexOf('Mobile'); // ListViewItem.Data['Text2'] := Contact.Phones.ExtractItem('Mobile'); // ListViewItem.Data['Text2'] := Contact.Phones.Extract.LabelKind('Mobile'); // ListViewItem.Data['Text2'] := Contact.Phones.ExtractAt.LabelKind.Mobile;//('Mobile'); // phones := Contact.Phones.ExtractItem.LabelKind.Mobile; //.TLabelKind.Mobile;// .Phones.Extract(Mobile); // ListViewItem.Data['Text2'] := phones.ExtractAt.LabelKind.Mobile;// Extract.LabelKind.Mobile;// ExtractItem.LabelKind.Mobile;// Contact.Phones.Extract('Mobile').ToString;// Phones.Extract.TLabelKind.; // ListViewItem.Data['Text2'] := phones.Extract.LabelKind.Mobile;// Contact.Phones Items[0].TLabelKind. .Number;// .Items[0]; ListViewItem.Data['Image3'] := Contact.PhotoThumbnail; ListViewItem.Tag := Contact.ID; finally ListViewItem.Free; end; end; end;
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