Category: StackOverflow

Working with large bitmaps in Firemonkey causes error

I'm unable to create a bitmap with width or height greater than 8192 pixels. This is the maximum texture size defined by DirectX 10 and set in TCanvasD2D.GetAttribute (DefaultMaxTextureSize = 8192;). The problem is, that's not very big. Many photos are larger than that. Is there a way around it or do I just accept that this is the limit? This is not an issue in VCL, where the limit is 65535. I'm using Delphi 10.4. procedure TForm1.FormCreate(Sender: TObject); var Bmp : TBitmap; begin Bmp := TBitmap.Create; Bmp.SetSize(100, 8193); end;
Read More

FireMonkey iOS ComboBox bug in DropDown?

​ iOS SDK 14.2 There is one combo box on the form. For the purity of the experiment, the form with the combo box is re-created every time after loading data into it and displaying the drop-down list. I load objects (JSONObject) into the combobox in the usual way. for FJSONValue in FJSONArray do Acb.Items.AddObject( (FJSONValue as TJSONObject).GetValue( 'name' ).Value, TObject( FJSONValue.Clone ) ); Also, when cleaning, I delete objects from the combo box. for index := 0 to Acb.Items.Count - 1 do if Acb.Items.Objects[index] <> nil then begin Acb.Items.Objects[index].DisposeOf; Acb.Items.Objects[index]:= nil; end; Acb.Items.Clear; On lap 2-3, after loading the content into the combo box, when you call DropDown (programmatically or via the GUI with a tap / click), the application crashes. I rarely get an error on the TCustomComboBox class in the method function TCustomComboBox.GetItems: TStrings; begin   Result := FListBox.Items; end;   What am I doing wrong? Am I clearing my memory incorrectly? Adding an object incorrectly? Why does it crash when trying to call the dropdown itself? On Win10 and android works without problems. ​
Read More

How to open file in default app on iOS using FireMonkey

I am writing an application in FireMonkey for Android and iOS. I would like to open a file from a URL in the default app on my phone (it could be a PDF, DOC, JPG, etc). On Android, I do it like this: Intent := TJIntent.Create; Intent.setAction(TJIntent.JavaClass.ACTION_VIEW); Intent.setData(StrToJURI(URL)); SharedActivity.StartActivity(Intent); How can I do something like this on iOS?
Read More

Bug in TTextButtonObjectAppearance under TListview (FMX)?

Using TTextButtonObjectAppearance in TListview (FMX), there is a Width property in Object Inspector. However, the Height property is missing. Tracing back the code, it inherits from TListItemDrawable which has both Height & Width properties - it's public fields, not published. property Width: Single index 0 read FWidth write SetOneDimension; property Height: Single index 1 read FHeight write SetOneDimension; How to amend the Delphi source to let Height be published just like Width? Otherwise, it's troublesome to have to always change the Height in the OnUpdateObjects code to set height of a button. I believe this cannot be by deliberate design to allow setting of Width but not Height. Thanks. Delphi 10.4.0
Read More

How to call my APP in IOS/Android from a link?

A user clicks on a link in his message software (whatsapp, telegram etc), eg. www.somedomain123.com/listing/456 the user will have a chance to choose Browser (standard), or my App. whatsapp web api once keyed into browser can call up the whatsapp App, so I know somehow this can be done. If user chooses my App, my app will get the entire URL so that I know to send him the listing with ID=456 How do I register my App in Delphi? Is it to do with associating all URL in "domain123.com" to this App? I have searched but only gotten examples to opening a URL from an app, but I need the reverse of this. Environment : Delphi 10.4 using Firemonkey for android, ios
Read More

Delphi Android – how take screenshot of entire screen programmatically?

I need the code that allowed my to take screenshots programmatically in Delphi. Here is the sulotion: How to programmatically take a screenshot on Android? How can i do this in delphi android app? This is my code but only capture Tcontrols not android screen. function MakeScaleScreenshot(Sender:TControl): TBitmap; var fScreenScale: Single; function GetScreenScale: Single; var ScreenService: IFMXScreenService; begin Result := 1; if TPlatformServices.Current.SupportsPlatformService (IFMXScreenService, IInterface(ScreenService)) then begin Result := ScreenService.GetScreenScale; end; end; begin fScreenScale := GetScreenScale; Result := TBitmap.Create(Round(Sender.Width*fScreenScale), Round(Sender.Height*fScreenScale)); Result.Clear(0); if Result.Canvas.BeginScene then try Sender.PaintTo(Result.Canvas, RectF(0,0,Result.Width,Result.Height)); finally Result.Canvas.EndScene; end; end;
Read More

Optimal Image resizing in TListview and TImage in iOS/Android [closed]

I'm asking this question specifically to Delphi as I don't seem to be able to get more specific answers in general forums. In my app, users normally choose 1-4MB photo (via Photo Gallery or Camera)... but it's not practical for server to send/receive such a large photo. Hence, resizing is needed for the server to store small thumbnails to send to end-user client (ios/android). There are quite a few resizing algorithms around. The question is: choosing photo size vs JPG quality Scenario: I've to display the final photo in a 200w x 150h image to display (either TImage or using TListview's Image) If I resize the 4MB photo to 100w x 75h, from what I read, it will look blurry on retina displays. so if TImage is 100w x 75h, is there a formula to determine what should an ideal thumbnail size be like? Example, go for 2X or 3X the dimension of the display control. Is there some guide on how to balance these trade-offs and the pros and cons of this? Hope to hear from someone's experience.
Read More

Delphi/FireMonkey: Cannot set Android camera to work

I'm trying to reproduce the AccessCameraApp.dproj app but it does not work for the TakePhotoFromCameraAction1, giving me the following error: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.XmlResourceParser android.content.pm.ProviderInfo.loadXmlMetaData(android.content.pm.PackageManager, java.lang.String)' on a null object reference. The odd thing is that the Library button works perfectly... The form looks like this: Form1 and the code is as follows: unit Unit1; interface uses System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, System.Permissions, FMX.Types, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.StdCtrls, System.Actions, FMX.ActnList, FMX.StdActns, FMX.MediaLibrary.Actions, FMX.Objects, FMX.Graphics, FMX.Controls.Presentation; type TForm1 = class(TForm) Image1: TImage; Button1: TButton; ActionList1: TActionList; Button2: TButton; TakePhotoFromLibraryAction1: TTakePhotoFromLibraryAction; TakePhotoFromCameraAction1: TTakePhotoFromCameraAction; procedure TakePhotoFromCameraAction1DidFinishTaking(Image: TBitmap); procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); private { Private declarations } procedure DisplayRationale(Sender: TObject; const APermissions: TArray<string>; const APostRationaleProc: TProc); procedure TakePicturePermissionRequestResult(Sender: TObject; const APermissions: TArray<string>; const AGrantResults: TArray<TPermissionStatus>); private const PermissionCamera = 'android.permission.CAMERA'; PermissionReadExternalStorage = 'android.permission.READ_EXTERNAL_STORAGE'; PermissionWriteExternalStorage = 'android.permission.WRITE_EXTERNAL_STORAGE'; public { Public declarations } end; var Form1: TForm1; implementation {$R *.fmx} procedure TForm1.Button1Click(Sender: TObject); begin TAG := 1; PermissionsService.RequestPermissions([PermissionCamera, PermissionReadExternalStorage, PermissionWriteExternalStorage], TakePicturePermissionRequestResult, DisplayRationale); end; procedure TForm1.Button2Click(Sender: TObject); begin TAG := 2; PermissionsService.RequestPermissions([PermissionCamera, PermissionReadExternalStorage, PermissionWriteExternalStorage], TakePicturePermissionRequestResult, DisplayRationale); end; procedure TForm1.DisplayRationale(Sender: TObject; const APermissions: TArray<string>; const APostRationaleProc: TProc); begin APostRationaleProc; end; procedure TForm1.TakePicturePermissionRequestResult(Sender: TObject; const APermissions: TArray<string>; const AGrantResults: TArray<TPermissionStatus>); begin if (Length(AGrantResults) = 3) and (AGrantResults[0] = TPermissionStatus.Granted) and (AGrantResults[1] = TPermissionStatus.Granted) and (AGrantResults[2] = TPermissionStatus.Granted) then begin if TAG = 1 then TakePhotoFromCameraAction1.Execute else TakePhotoFromLibraryAction1.Execute; end else ShowMessage('Cannot take a photo because the required permissions are not all granted'); end; procedure TForm1.TakePhotoFromCameraAction1DidFinishTaking(Image: TBitmap); begin Image1.Bitmap := Image; end; end.
Read More

Potential issue in TListview – does not recognise DisplayFormat for TDateTimeField

I worked out a simple example. Display Format works for the CustomerAmount (integer) but not CustomerDate (Tdatetime). it seems TDateTime's displayFormat is not respected by TListview. The sample table has 3 fields. The line showmessage( FDMemTable1.FieldByName('CustomerDate').displaytext ); --> this .DisplayText works even without a GetText event it displays the Date format 'dd mmm (ddd)' correctly. But when it goes to TListview, it does not use the DisplayText. But the TIntegerField uses the DisplayText correct in TListview, so there's a difference in how TListview handles .DisplayText for TIntegerField vs TDateTimeField. type TForm1 = class(TForm) ListView1: TListView; Button1: TButton; FDMemTable1: TFDMemTable; BindSourceDB1: TBindSourceDB; FDMemTable1CustomerID: TIntegerField; FDMemTable1CustomerName: TStringField; BindSourceDB2: TBindSourceDB; BindingsList1: TBindingsList; FDMemTable1CustomerDate: TDateTimeField; FDMemTable1CustomerAmount: TIntegerField; procedure Button1Click(Sender: TObject); private FLinkFillControlToField : TLinkFillControlToField; public { Public declarations } end; var Form1: TForm1; implementation {$R *.fmx} procedure TForm1.Button1Click(Sender: TObject); begin with FDMemTable1 do begin Open; Append; FieldByName('CustomerID').AsInteger := 1; FieldByName('CustomerAmount').AsInteger := 1250000; FieldByName('CustomerName').AsString := 'ABC'; FieldByName('CustomerDate').AsDateTime := NOW(); Post; Append; FieldByName('CustomerID').AsInteger := 2; FieldByName('CustomerAmount').AsInteger := 2550000; FieldByName('CustomerName').AsString := 'XYZ'; FieldByName('CustomerDate').AsDateTime := NOW()+1; Post; Append; FieldByName('CustomerID').AsInteger := 3; FieldByName('CustomerAmount').AsInteger := 3250000; FieldByName('CustomerName').AsString := 'XYZ'; FieldByName('CustomerDate').AsDateTime := NOW()+2; Post; (FDMemTable1.FieldByName('CustomerAmount') as TIntegerField).DisplayFormat := '#,###,###'; (FDMemTable1.FieldByName('CustomerDate') as TDateTimeField).DisplayFormat := 'dd yyyy (ddd)'; end; showmessage( FDMemTable1.FieldByName('CustomerDate').displaytext ); // this .DisplayText works but not below if not Assigned(FLinkFillControlToField) then begin FLinkFillControlToField := TLinkFillControlToField.Create(BindingsList1); FLinkFillControlToField.Control := listview1; with FLinkFillControlToField do begin Category := 'Quick Bindings'; Track := False; Direction := linkDataToControl; AutoActivate := False; AutoFill := True; BindSourceDB1.DataSource.Enabled := True; FillDataSource := BindSourceDB1; end; end; with FLinkFillControlToField do begin FillHeaderFieldName := 'CustomerName'; with FillExpressions.AddExpression do begin //SourceMemberName := 'CustomerID'; SourceMemberName := 'CustomerAmount'; ControlMemberName := 'Text1'; end; with FillExpressions.AddExpression do begin SourceMemberName := 'CustomerDate'; ControlMemberName := 'Text2'; end; end; FLinkFillControlToField.Active := True; end; object Form1: TForm1 Left = 0 Top = 0 Caption = 'Form1' ClientHeight = 404 ClientWidth = 763 FormFactor.Width = 320 FormFactor.Height = 480 FormFactor.Devices = [Desktop] DesignerMasterStyle = 0 object ListView1: TListView ItemAppearanceClassName = 'TDynamicAppearance' ItemEditAppearanceClassName = 'TDynamicAppearance' HeaderAppearanceClassName = 'TListHeaderObjects' FooterAppearanceClassName = 'TListHeaderObjects' Position.X = 16.000000000000000000 Position.Y = 24.000000000000000000 Size.Width = 561.000000000000000000 Size.Height = 353.000000000000000000 Size.PlatformDefault = False ItemAppearanceObjects.ItemObjects.ObjectsCollection = < item AppearanceObjectName = 'Text1' AppearanceClassName = 'TTextObjectAppearance' Appearance.Width = 223.000000000000000000 Appearance.Height = 44.000000000000000000 end item AppearanceObjectName = 'Text2' AppearanceClassName = 'TTextObjectAppearance' Appearance.Width = 208.000000000000000000 Appearance.Height = 44.000000000000000000 Appearance.PlaceOffset.X = 326.000000000000000000 end> ItemAppearanceObjects.ItemEditObjects.ObjectsCollection = < item AppearanceObjectName = 'Text1' AppearanceClassName = 'TTextObjectAppearance' end> end object Button1: TButton Position.X = 592.000000000000000000 Position.Y = 24.000000000000000000 Size.Width = 161.000000000000000000 Size.Height = 57.000000000000000000 Size.PlatformDefault = False Text = 'Button1' OnClick = Button1Click end object FDMemTable1: TFDMemTable FetchOptions.AssignedValues = [evMode] FetchOptions.Mode = fmAll ResourceOptions.AssignedValues = [rvSilentMode] ResourceOptions.SilentMode = True UpdateOptions.AssignedValues = [uvCheckRequired, uvAutoCommitUpdates] UpdateOptions.CheckRequired = False UpdateOptions.AutoCommitUpdates = True Left = 576 Top = 128 object FDMemTable1CustomerID: TIntegerField FieldName = 'CustomerID' end object FDMemTable1CustomerName: TStringField FieldName = 'CustomerName' Size = 30 end object FDMemTable1CustomerDate: TDateTimeField FieldName = 'CustomerDate' end object FDMemTable1CustomerAmount: TIntegerField FieldName = 'CustomerAmount' end end object BindSourceDB1: TBindSourceDB DataSet = FDMemTable1 ScopeMappings = <> Left = 576 Top = 192 end object BindSourceDB2: TBindSourceDB DataSet = FDMemTable1 ScopeMappings = <> Left = 576 Top = 248 end object BindingsList1: TBindingsList Methods = <> OutputConverters = <> Left = 20 Top = 5 end end
Read More

Android JNI in C++ Builder

I'm searching for using Android JNI on C++ Builder, and I saw this code: private void doPhotoPrint() { PrintHelper photoPrinter = new PrintHelper(getActivity()); photoPrinter.setScaleMode(PrintHelper.SCALE_MODE_FIT); Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.droids); photoPrinter.printBitmap("droids.jpg - test print", bitmap); } That's a Java code to print (in a thermal printer) a bitmap and I need to use it in C++ Builder, but I don't have idea how to convert it. I saw doing other things by intents or even JNI. I don't want recommendations or something, neither a done code (saying this to avoid judgments that my question is for recommendations), but I want something like this code to help create a function. PS: I didn't found any documentation about Android JNI.
Read More

Unable to use the camera properly

I have a problem using the camera. . . whenever I use the camera and try to zoom in or out the light using the camera tools or use another camera setting before taking the photo, so the photo and the triggered should go back to Application with the image of the photo, but the Application restarts. If you don't use the zoom, and just open the camera and take the picture, the app works normally. But this error of the app restarting is kind of random. I debugged Android Studio, and got the following error: 2020-11-24 17: 51: 39.483 6250-6250 /? I / barcadero.Mone: Late-enabling -Xcheck: jni 2020-11-24 17: 51: 39.530 6250-6250 /? E / barcadero.Mone: Unknown bits set in runtime_flags: 0x8000 2020-11-24 17: 51: 40.309 6250-6250 / com.embarcadero.Money W / ActivityThread: handleWindowVisibility: no activity for token android.os.BinderProxy@f9bc15c 2020-11-24 17: 51: 41.440 6250-6250 / com.embarcadero.Money I / AdrenoGLES: QUALCOMM build: 961b24f, Ib57168459a Build Date: 02/24/20 OpenGL ES Shader Compiler Version: EV031.27.05.06 Branch Location: Remote Branch: Remote Branch: Reconstruct Branch: 2020-11-24 17: 51: 41.440 6250-6250 / com.embarcadero.Money I / AdrenoGLES: Build Config: S L 8.0.12 AArch32 2020-11-24 17: 51: 41.490 6250-6250 / com.embarcadero.Money I / AdrenoGLES: PFP: 0x005ff112, ME: 0x005ff066 2020-11-24 17: 51: 41.559 6250-6265 / com.embarcadero.Money W / System: A resource failed to call close. 2020-11-24 17: 51: 41.560 6250-6265 / com.embarcadero.Money W / System: A resource failed to call release. 2020-11-24 17: 51: 42.343 6250-6250 / com.embarcadero.Money W / Gralloc3: mapper 3.x is not supported Unfortunately I cannot solve this problem. . . I tried API 28 and API 29, Delphi 10.3.3 and Delphi 10.4.1. The error continues. . .. I count on your help ... thanks
Read More