Category: StackOverflow

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

I need a programme to run on android <= 4 [closed]

I have a firemonkey programme which was written back for Android 3 or 4, which has grown up to be running happily on Android 9. Unfortunately someone wants to run it on Android 5. It shows the "Splash" screen, blinks its little (Samsung) location indicator at the top of the screen s few times, then dies. Is this likely to be fixed on going back to an earlier Android library please? And if so, which one?
Read More

What the purpose of the System.StartUpCopy included in all firemonkey project?

When I create a new mobile app with Delphi, I have this dpr source: program Project1; uses System.StartUpCopy, FMX.Forms, Unit1 in 'Unit1.pas' {Form1}; {$R *.res} begin Application.Initialize; Application.CreateForm(TForm1, Form1); Application.Run; end. I do not understand, what the purpose of the System.StartUpCopy in the use? With System.StartUpCopy.pas, on ios, it's look like the app will copy file from /private/var/containers/Bundle/Application/2BE5407C-4DD9-5A08-110F-C12510C42BF3/myapp.app/StartUp/Documents/ to /private/var/mobile/Containers/Data/Application/2BE5407C-4DD9-5A08-110F-C12510C42BF3/Documents/ but I don't fully understand why because now my app will use twice more disk space, and my app can access both directories so I do not understand why we need to duplicate the resources :(
Read More

What’s the best approach in showing multiple images from Database using TVertScrollBox with 2 columns

I am contemplating on showing number of images using TVertScrollBox with 2 columns and text at the bottom of each images.

Here’s the screenshot of what I wanted to do:

I am thinking of using the TGridLayout and create visual controls l… … Read More

Read More

Can I add a second component editor to a component in Firemonkey?

Delphi IDE has a component editor for TLang component (Language Designer) I wrote a custom component editor to TLang, to help with localization tasks. I registered it in a design time package. RegisterComponentEditor(TLang, TMyLangComponentEditor); This works. Now when I dbl-click the component, I get my flashy component editor. But it hides the original TLang editor. How can I have access to both editors in the right-click menu ? ex: In my component editor I have: function TMyLangComponentEditor.GetVerb(Index: Integer): string; begin case Index of 0: Result := '&Show IDE Lang Designer'; 1: Result := '&Show My Lang Editor'; else raise ENotImplemented.Create('verb not supported'); end; end; procedure TMyLangComponentEditor.ExecuteVerb(Index: Integer); begin case Index of 0: ; // <--- what goes here to open the IDE Language designer ? 1: ShowMyLangForm; else raise ENotImplemented.Create('verb not supported.'); end; end; I'm afraid that, by registering a new component editor, the old one got lost...
Read More

In FMX how to get the current URL of a TWebBrowser control?

I use Delphi 10.3 Community edition. My FireMonkey Android/iOS application has a tab with TWebBrowser control, so users can load and browse the sites from the bookmarked list. When a user clicks on any link (for example, a category, a new product item or a new site) in the already loaded site, the new link is also loaded into the TWebBrowser. How to programmatically determine this new link that the user have just clicked on? Or how to programmatically determine the link of the currently loaded document in the TWebBrowser? That is easy to do for Windows applications, but for mobile applications the TWebBrowser component has very limited functionality. For example: I load first url to TWebBrowser: WebBrowser1.URL := 'site.com' I browse this site and click on a new link site.com/category1 to see category1 page in the same TWebBrowser. After that I try to get current WebBrowser1 document url like this: Label1.Caption := WebBrowser1.URL but Label1.Caption is equal site.com, although it should be site.com/category1. To define a new URL, I used different events like OnDidFinishLoad (starts many times), OnDidStartLoad (starts many times), OnShouldStartLoadWithRequest (never started) end even TButton.Onclick after new link is loaded. But I still couldn’t programmatically get the link site.com/category1.
Read More

Delphi 10.3.3 How to view pdf file on Ubuntu

My app downloads the file from the server and it saves the file in the default download directory. How can I open the file after downloading to view it. try MS := TMemoryStream.Create; try Http.Request.BasicAuthentication:= true; Http.Request.Username := '*****'; Http.Request.Password := '****'; Http.Get('http://'+serverIP+':8080/api/getpdf/'+fType, MS); MS.Position:=0; {$IFDEF MSWINDOWS} MS.SaveToFile(fl); {$ENDIF} {$IFDEF LINUX} MS.SaveToFile(fl); {$ENDIF} {$IFDEF ANDROID} if PermissionsService.IsPermissionGranted(JStringToString(TJManifest_permission.JavaClass.WRITE_EXTERNAL_STORAGE)) then begin MS.SaveToFile(fl); end; {$ENDIF} previewFile(fl,fType);<-------------- finally MS.Free; end; finally Http.Free; end; In windows platform I do: ShellExecute(0, 'open',PChar(fl),nil,nil,0) Any suggestion for Linux?
Read More