Category: StackOverflow

Delphi FMX TListBox slow with large lists

I'm loading 2,000 names into an FMX TListBox and it is taking far too long (like 35 seconds or more). Here is the test code: procedure TDocWindow.DEBUGAddLotsOfStringsToList; var theTimeAtStart: Integer; J: Integer; begin ListBox1.Clear; theTimeAtStart := TThread.GetTickCount; for J := 1 to 2200 do begin ListBox1.Items.Add(j.toString); end; ShowMessage('There were ' + J.ToString + ' strings added to the list in ' + (TThread.GetTickCount - theTimeAtStart).ToString + ' milliseconds.'); end; Is there something about TListBox that makes it too slow for a few thousand strings?
Read More

No ‘teamID’ specified and no team ID found in the archive

I'm getting following errors while trying to build a distribution version of my firemonkey app. [PAClient Error] Error: E0776 2020-07-21 16:50:36.073 xcodebuild[2035:200954] [MT] IDEDistribution: -[IDEDistributionLogging _createLoggingBundleAtPath:]: Created bundle at path '/var/folders/1d/j6b25yvj6wsg95yjm4m4p3dm0000gn/T/ExpenseClaims_2020-07-21_16-50-36.072.xcdistributionlogs'. [PAClient Error] Error: E0776 error: exportArchive: No 'teamID' specified and no team ID found in the archive [PAClient Error] Error: E0776 Error Domain=IDEFoundationErrorDomain Code=1 "No 'teamID' specified and no team ID found in the archive" UserInfo= {NSLocalizedDescription=No 'teamID' specified and no team ID found in the archive}
Read More

How to rotate a photo in FireMonkey TWebBrowser

I just tried FMX TWebBrowser in Delphi 10.3.3. I could not rotate a photo in img tag. The following page is working in Google Chrome. But it is not working in FireMonkey TWebBrowser of Delphi 10.3.3. What is wrong? Please someone help me! <!DOCTYPE html> <html> <head> <style> img { display: block; width: 300px; height: auto; } </style> </head> <body> <button onclick="rotate();">Rotate 90 degrees</button> <br /> <img src="20190228-1.JPG" id="theID" /> <script> function rotate() { var imgX=document.getElementById("theID"); imgX.style.transform = "rotate(90deg)"; imgX.style.display = "block"; } </script> </body> </html>
Read More

How can i scale the FMX mainform’s canvas?

I’m writing a small 2D RPG video game(like DiabloII) in Delphi, and for cross-platfrom purpose(PC、Android and so on), i’m using FireMonkey for presentation. Actually, all the scene rendering(tiles、images、texts, etc) were performed by the open-source engine PXL. But, i can not zoom-in/out the scene, for example, my cell phone screen is 5.5′, and the resolution is 2340 * 1080, i want to shrink the FMX’s mainform canvas to the size of 1280 * 720, so the game would be looked ok if it runs on the cell phone, otherwise, everything is too small to look.
I looked through the FMX source code, tried, but failed.
So, how can i change the mainform’s canvas’s size” to specific resolution?

// procedure TfrmMain.FormResize(Sender: TObject);
procedure TfrmMain.FormShow(Sender: TObject);
begin
  //
end;

Thanks very much!

Read More

Read More

Why I get access violation error from TBitmap.LoadFromStream method in datasnap ISAPI dll?

I've developed a datasnap rest server application in RAD Studio 10.3.2. In one of my server methods I receive an image from the client app. The image data is a base64 encoded string as a json value. My method is something like this: function TServerMethods1.getImage(JSONobj: TJSONObject): Boolean; var OutputStream : TMemoryStream; InputStream : TStringStream; theImage : TBitmap; begin var imageStr : string := JSONobj.GetValue('Image').Value; InputStream := TStringStream.Create(imageStr); //InputStream.saveToFile('C:\InputStream.txt'); OutputStream := TMemoryStream.Create; theImage := TBitmap.Create; try InputStream.Position := 0; TNetEncoding.Base64.Decode(InputStream, OutputStream); //OutputStream.saveToFile('C:\OutputStream.txt'); OutputStream.Position := 0; theImage.LoadFromStream(OutputStream); // in this line I get an access violation error! finally theStringStream.Free; theMemoryStream.Free; end; . . . end; When I build the project as a standalone firemonkey app (.exe file) everything works fine but when I build an ISAPI dll and deploy it in IIS I got an access violation error in the line that I added a comment to it. What's wrong? I'm really confused! P.S. I saved both InputStream and OutputStream somewhere so that I get sure that I receive the stream and decode it properly and both streams are just fine. The variable theImage: TBitmap; is an object of FMX.Graphics.TBitmap class, because my stand-alone GUI is a firemonkey application.
Read More

Change navigation bar color on Delphi

In every program I write on Delphi for Android the navigation bar is white and no transparent. I have a Galaxy A50 for test, with dark mode enabled. How can I change the color or the transparency on navigation bar. I don't know what is wrong. The mobile, Delphi or the AndroidManifest. I don't know what to try (except the Form.Fullscreen). sample screenshot Thanks.
Read More

How implement FMX HD app zoom-in and zoom-out?

I am a newbie at FireMonkey. Recently i'm using Delphi(FMX) to develop a small 2D game, and i want to add the ZOOM-in/out effect when wheeling mouse, I tried, and searched Idera sample and FMX codes, no gain. So, is there any way to implement ZOOM? and why FMX do not offer easy-use "scale" properties? FMX is not user friendly, and Very lack of mature products, sample codes and discussions. Thanks very much, and forgive me for my poor English. Let it be simple: File-->New-->Multi-Device Application-->Blank Application, click OK, then we should get a FMX HD App, and what i want to do is, when i am wheeling the mouse, the main form's viewport can zoom-in/out. procedure TForm1.FormMouseWheel(Sender: TObject; Shift: TShiftState; WheelDelta: Integer; var Handled: Boolean); begin // ? end; Sorry for my poor description, thank you!
Read More

Delphi FireMonkey iOS Camera Orientation

I'm having an issue with TCameraComponent and orientation on iOS. Here is my code where I create the Camera: Camera:=TCameraComponent.Create(Self); Camera.Name:='Camera'; Camera.OnSampleBufferReady:=CameraSampleBufferReady; Camera.Kind:=FMX.Media.TCameraKind.BackCamera; Camera.FocusMode:=FMX.Media.TFocusMode.ContinuousAutoFocus; Camera.Quality:=FMX.Media.TVideoCaptureQuality.MediumQuality; Camera.Active:=TRUE In CameraSampleBufferReady I have (via a TThread.Synchronize): Camera.SampleBufferToBitmap(ScannerImage.Bitmap,TRUE) to show the frame on a TImageControl that is Client-Aligned to a TabItem on a TTabControl (I switch to this tab when the user starts scanning) In some cases (not always, which is the puzzling thing), the camera appears to get "out of sync" (orientation-wise) with the application, ie. the image on the phone appears rotated 90°, so that when the user moves the phone left/right, the image on the phone moves up/down. Is there a setting I can send to the Camera that forces it to follow the phone's orientation, or can I set the Camera's orientation to a specific setting? The application is set to "Portrait" + "Upside Down" in Orientation setting. The same code works flawlessly on Android.
Read More

How programmatically change IconTintColor of the button if I use a component TStyleBook?

I use Delphi 10.3 Version 26.0.36039.7899. In my Android app to change icon color of the "favorites" button i use this simple trick: procedure TfMain.LinkPropertyToFieldText4AssignedValue(Sender: TObject; AssignValueRec: TBindingAssignValueRec; const Value: TValue); begin sbtnFavorites.StyledSettings := sbtnFavorites.StyledSettings - [TStyledSetting.FontColor]; if Value.AsString = '1' then sbtnFavorites.IconTintColor := TAlphaColors.Hotpink; if Value.AsString = '0' then sbtnFavorites.IconTintColor := TAlphaColorRec.Grey; end; The sbtnFavorites button has StyleLookUp = bookmarkstoolbutton and StyledSettins.FontColor = False. It works nice, the button sbtnFavorites changes its color depending on the value of the field "IsFavor" in the local database. But if I put the component TStyleBook on the form and then assign any style (f.e. AndroidSterling.style) to it, then the method I have already described here does not work. The color of the button sbtnFavorites which has StyleLookUp = bookmarkstoolbutton does not change. And here's my question: how programmatically change the color of the button icon (IconTintColor) if I use a component TStyleBook?
Read More

FireMonkey Android: raised exception class EJNIException with message ‘java.lang.IndexOutOfBoundsException: setSpan (XX … XX) ends beyond length X

I have 2 TNumberBox controls in my page, and their property changes are as follows: MaxValue : 1E9 DecimalDigits: 2 Text: 0.00 KeyBoardType: DecimalNumberpad Also, in both boxes, I call SelectAll() in the OnClick event, eg: procedure TfrmExpenseClaim.numTaxClick(Sender: TObject); begin numTax.SelectAll; end; I also have a TComboBox on the page. I can enter a value on the first TNumberBox and then, based on a certain TComboBox value, the second TNumberBox will get updated. Also, I can update the second TNumberBox value manually, which does not have an effect on the first TNumberBox. First Number Box value : 110 Combo Box value : 10% tax Second TNumberBox value gets updated as 10 = ( NumberBox1.Value – ( NumberBox1.Value / ( 1 + 10/ 100)) The calculations work fine. The problem is, if I change the second TNumberBox value manually, and then quickly change the TComboBox value again and again, and then select the second TNumberBox, it will display the following error: Project ExpenseClaims.apk raised exception class EJNIException with message 'java.lang.IndexOutOfBoundsException: setSpan (6 ... 6) ends beyond length 4'. The setSpan (6 … 6) changes, as sometimes it displays (5 … 5) and (4 … 4). Afterwards, most of the time when I select that second TNumberBox, I will get that error and the values also get updated incorrectly. The only way to recover after getting this error is to close the app and open it again. I tried to capture that error in code, but could not as it comes outside of the Delphi code that I have written. Is this a known error? If so, what can I do to fix it? type TfrmExpenseClaim = class(TForm) numTax: TNumberBox; numInclTax: TNumberBox; cmbTaxCategory: TComboBox; procedure numInclTaxClick(Sender: TObject); procedure numTaxClick(Sender: TObject); procedure numInclTaxChange(Sender: TObject); procedure cmbTaxCategoryChange(Sender: TObject); private FTaxDetailsList : TTaxDetailsList; procedure CalculateTax; end; ... procedure TfrmExpenseClaim.cmbTaxCategoryChange(Sender: TObject); begin CalculateTax; end; procedure TfrmExpenseClaim.numInclTaxChange(Sender: TObject); begin if cmbTaxCategory.Selected.Text <> '' then begin CalculateTax; end; end; procedure TfrmExpenseClaim.numInclTaxClick(Sender: TObject); begin numInclTax.SelectAll; end; procedure TfrmExpenseClaim.numTaxClick(Sender: TObject); begin //This is where the problem occur as I think, but not in delphi code numTax.SelectAll; end; procedure TfrmExpenseClaim.CalculateTax; var I: Integer; var dPriceEx, dTaxVal: Double; begin dPriceEx := 0.00; for I := 0 to FTaxDetailsList.Count - 1 do begin // Filling up the FTaxDetailsList work fine which is done via a API call if (cmbTaxCategory.Selected.Text = FTaxDetailsList[I].RateTitle) then begin if FTaxDetailsList[I].TaxRate = 0.00 then begin numTax.Value := 0.00; end else begin dPriceEx := numInclTax.Value / (1 + FTaxDetailsList[I].TaxRate / 100); dTaxVal := numInclTax.Value; numTax.Value := dTaxVal - dPriceEx; // Example 1 : numInclTax.Value is 110.00 and the FTaxDetailsList[I].TaxRate is 10 (10%). Therefore the numTax.Value should be 10.00; // Example 2 : numInclTax.Value is 110.00 and the FTaxDetailsList[I].TaxRate is 0 (0%). Therefore the numTax.Value should be 0.00; end; end; end; end; The problem won't occur in the first instance. Maybe not until the 5th or 6th instance. But it will occur after a few quick changes. How to produce: First set of Steps: Enter a value to numInclTax.Value (eg : 115.00) By default, the cmbTaxCategory is set to 15% GST. Meaning 15% tax rate. It will calculate the numTax.Value based on the TfrmExpenseClaim.CalculateTax code to 15.00 This works fine. Second set of Steps: Then change the cmbTaxCategory option to Zero based tax (which is no tax) It will calculate the numTax.Value based on the TfrmExpenseClaim.CalculateTax code to 0 Works fine. Third set of Steps: Then update the numTax.Value by swapping across the Number box. It will either increase or reduce the numTax.Value based on the direction you swap (I never went to minus values) Then again change the cmbTaxCategory option, again it should calculate the values. Then numTax.Value by swapping across the Number box again. At some point, by repeating the Third set of Steps again and again, on the 3rd step as soon as you select the numTax.Value the error will occur. I was only able to replicate this on Android. And I think it might be something to do with swapping across the number box. But I'm not sure.
Read More

Handling intent result of multiple selected files from the storage

i have this headache with android Intents. i'm trying to select multiple image from the storage. i made it work till the point to handle the results. my guess is that some sort of For loop of get the path of all files?. The Result in my code returns empty, i don't know what is the problem. my code so far : //Button to launch activity : var Intent: JIntent; begin FMessageSubscriptionID := TMessageManager.DefaultManager.SubscribeToMessage (TMessageResultNotification, HandleActivityMessage); Intent := TJIntent.JavaClass.init(TJIntent.JavaClass.ACTION_PICK); Intent.setType(StringToJString('image/*')); Intent.setAction(TjIntent.JavaClass.ACTION_GET_CONTENT); Intent.putExtra(TJIntent.JavaClass.EXTRA_ALLOW_MULTIPLE, true); SharedActivity.startActivityForResult(Intent, 0); end; //Handling Result : procedure HandleActivityMessage(const Sender: TObject; const M: TMessage); function OnActivityResult(RequestCode, ResultCode: Integer; Data: JIntent): Boolean; ... procedure TForm3.HandleActivityMessage(const Sender: TObject; const M: TMessage); begin if M is TMessageResultNotification then OnActivityResult(TMessageResultNotification(M).RequestCode, TMessageResultNotification(M).ResultCode, TMessageResultNotification(M).Value); end; function TForm3.OnActivityResult(RequestCode, ResultCode: Integer; Data: JIntent): Boolean; var filename : string; list : Tstrings; begin Result := False; TMessageManager.DefaultManager.Unsubscribe(TMessageResultNotification, FMessageSubscriptionID); FMessageSubscriptionID := 0; if RequestCode = ScanRequestCode then begin if ResultCode = TJActivity.JavaClass.RESULT_OK then begin if Assigned(Data) then begin //filename := JStringToString(Data.getStringExtra(StringToJString('RESULT'))); filename := JStringToString(Data.getStringExtra(TJIntent.JavaClass.EXTRA_TEXT)); ShowMessage('Result : '+filename); memo1.Lines.Add(filename); end; //Toast(Format('Found %s format barcode:'#10'%s', [ScanFormat, ScanContent]), LongToast); end; end else if ResultCode = TJActivity.JavaClass.RESULT_CANCELED then begin ShowMessage('No'); end; Result := True; end; used IDE : Delphi 10.3.3 and Android 9
Read More

Delphi detecting image type in TImageControl

I am trying to detect the image type loaded in FMX's TImageControl. I am using Delphi 10.3 Rio. My code is as follows: function DetectImage(BM: TBitmap): string; var MS: TMemoryStream; FirstBytes: AnsiString; begin MS := TMemoryStream.Create; try BM.SaveToStream(MS); SetLength(FirstBytes, 8); MS.Read(FirstBytes[1], 8); if Copy(FirstBytes, 1, 2) = 'BM' then begin Result := 'bmp'; end else if FirstBytes = #137'PNG'#13#10#26#10 then begin Result := 'png'; end else if Copy(FirstBytes, 1, 3) = 'GIF' then begin Result := 'gif'; end else if Copy(FirstBytes, 1, 2) = #$FF#$D8 then begin Result := 'jpg'; end else Result := '?'; finally MS.Free; end; end; procedure TfrmMain.imgTeamAChange(Sender: TObject); begin ShowMessage(DetectImage(imgTeamA.Bitmap)) ; end; So, when I click on the TImageControl to change it, I always get '?' as a result. How do I make this working?
Read More