Category: StackOverflow

Delphi EIdOSSLUnderlyingCryptoError Exception – SSL3_GET_RECORD Wrong Version Number

I tried using TRESTClient to connect to an HTTPS web service using TLS 1.2. But NO LUCK with sending multipart/form-data. So now I am trying with Indy. I got this "Wrong Version Number" error. I think there is nothing wrong with the code since it worked with HTTP. Probably my Delphi is missing something. What should I install and how? procedure TForm10.Button2Click(Sender: TObject); var HTTP: TIdHTTP; RequestBody: TStream; ResponseBody: string; myssl: TIdSSLIOHandlerSocketOpenSSL; Input: TIdMultipartFormDataStream; begin ResponseBody := ''; try try HTTP := TIdHTTP.Create; try Input := TIdMultipartFormDataStream.Create; try Input.Clear; Input.AddFormField('Email', 'xx@xx.com.tr'); Input.AddFormField('Password', 'xx'); myssl := TIdSSLIOHandlerSocketOpenSSL.Create(HTTP); HTTP.IOHandler := myssl; myssl.SSLOptions.Mode := sslmUnassigned; myssl.SSLOptions.Method := sslvTLSv1_2; myssl.SSLOptions.SSLVersions := [sslvTLSv1_2]; HTTP.HTTPOptions := [hoForceEncodeParams]; HTTP.Request.CustomHeaders.FoldLines := False; ResponseBody := HTTP.Post('https://xxx.com.tr/api/Mobile/MobileLoginControl', Input); finally Input.Free; end; finally HTTP.Free; end; finally end; except ResponseBody := '"-20"'; end; end;
Read More

Delphi deletes iOS64 binary from compiled folder after linking

I'm having troubles on Rad studio 10.3.2 and iOS 13.1 Delphi systematically deletes the binary from the iOSDevice6 debug folder after linking and gives me a compiling succeeded message. Then at the deploy phase it gives me an error message saying the binary is missing.... I managed to install an empty project on my phone, so there is no problem with the provisioning and so on. Also the project option has the same settings as the empty app. Please help.
Read More

How to integrate COM server into FMX project in C++Builder

I am creating a new FMX multi-device application in C++Builder. I would like to integrate a COM server into my application. Any idea on how to do that would be much welcome. Previously, my applications were created in C++ Builder using VCL, where I used to add an ActiveX library and provide the entry path to my application in that. But now, I read that ActiveX is not supported in FMX.
Read More

Firemonkey mobile application high-level design best practices regarding forms / frames / styling. Delphi RIO 10.3

I'm in a phase where I need to make , for my feeling, important high-level design decisions for my application. For the past few days (!), I've been doing some cycles of investigation, test, discover showstoppers and restart... As I've also benifit many times from others people work in the past, I thought I spend the time to share my outcome. Maybe it can help someone to save some time. Or have some valuable feedback from the experts out there :-). I'm answering my own question below. And I'm welcoming comments and especially warnings :-) Regards Dirk
Read More

Troubles calling web services with WSDL Importer

I have built an application that calls a webservice in order to retrieve some information. This application is designed to work both on android and windows (using the firemonkey framework). The object that calls the webservice has been built with a WSDL importer and works great when running the application on windows. Nonetheless, when i try to use my application on an android device, i can only call the webservice two times. On the third time, the application freeze. I have tried to do some debug and it appears that the application freezes when trying to call the web service : genEtq := GetIGenerationEtiquettes(); // Converts a THttpRio as a IGenerationEtiquette object soapattachmnt := genEtq.GetImageEtiquette(idEtiquette); // Calls web service -> freeze on third time // // Do something ... // The webservice is hosted on my computer so i'm sure there is no troubles on the service side. In addition, when i restart the application, i can still call the web service two times. My application has the authorization to access to the internet on my android device so i'm running out of ideas on what's the problem. Also i have tried to monitor the network (via wireshark) and i had been able to see the two first requests but not the third one. Do you have any ideas on how to find the problem ?
Read More

How to send Stream Parameter to EMSDataSetResource

I need to post a pdf file to a firebird database using Rad Server with a TEMSDataSetResource and am trying to send the file as a parameter. I have created a simple table using Firebird 3.0 on Linux Ubuntu 18.04 with a text field and a Blob Binary Field. The SQL in the qryPost is: insert into Table01 (FileName,FileData) values (:FileName,:FileData) I created a sample that connects directly to the DataBase and the following code works to post the blobs. I have a full pot of coffee and will try again using EMSDataSetResource and post an update. procedure THeaderFooterForm.btnGetAllClick(Sender: TObject); begin qryGetAll.Open('Select * From Table01'); end; procedure THeaderFooterForm.btnPostClick(Sender: TObject); var Stream:TMemoryStream; begin qryPost.ParamByName('FileName').AsString := Edit1.Text; stream := TMemoryStream.Create; Try stream.LoadFromFile(edit2.Text); stream.Seek(0,0); qryPost.ParamByName('FileData').LoadFromStream(stream,ftBlob); qrypost.OpenOrExecute; Finally stream.Free; End; end; procedure THeaderFooterForm.SpeedButton1Click(Sender: TObject); begin if OpenDialog1.Execute then Edit2.Text := OpenDialog1.FileName else Edit2.Text := ''; end; I am now adding a new project of a RAD Server Package. Create Package with Resource name of 'Blob' and as a Data Module with DataBase Endpoints and no Sample Endpoints. Select Connection to Database and Select Table01 and FINISH. Same SQL insert into Table01 (FileName,FileData) values (:FileName,:FileData) and set param types both to ptinput and data types to ftstring and ftblob and set default param values. Execute the query at design time and it correctly posts string value to the blob field. Separate issue and side note. I am using Rad Studio 10.3 and compiling the EMS server comes up with error that required package FireDacFBDriver not found. My work around is to remove FireDacFBDriver.dcp from the requires section of the project. Recompile and it asks to add the FireDacIBDriver which seems to work. Here is the complete and amazingly short code for the EMS Server Package. All I changed is the ResourceSuffix name to 'Test'. unit Server_u; // EMS Resource Module interface uses System.SysUtils, System.Classes, System.JSON, EMS.Services, EMS.ResourceAPI, EMS.ResourceTypes, FireDAC.Stan.Intf, FireDAC.Stan.Option, FireDAC.Stan.Error, FireDAC.UI.Intf, FireDAC.Phys.Intf, FireDAC.Stan.Def, FireDAC.Stan.Pool, FireDAC.Stan.Async, FireDAC.Phys, FireDAC.Phys.FB, FireDAC.Phys.FBDef, FireDAC.ConsoleUI.Wait, FireDAC.Stan.Param, FireDAC.DatS, FireDAC.DApt.Intf, FireDAC.DApt, EMS.DataSetResource, Data.DB, FireDAC.Comp.DataSet, FireDAC.Comp.Client; type [ResourceName('Blob')] TBlobResource1 = class(TDataModule) FDConnection1: TFDConnection; qryTABLE: TFDQuery; [ResourceSuffix('Test')] dsrTABLE: TEMSDataSetResource; published end; implementation {%CLASSGROUP 'System.Classes.TPersistent'} {$R *.dfm} procedure Register; begin RegisterResource(TypeInfo(TBlobResource1)); end; initialization Register; end. Setting up the EMS client basically following this tutorial but using Firemonkey multi device. http://docwiki.embarcadero.com/RADStudio/Rio/en/Tutorial:_Implementing_a_FireDAC_RAD_Server_Client_Application The resource on the EMSFireDacClient is set to 'blob/test/' and needs the trailing / Dropped a TGrid and livebinding it to the memtable . Had to modify SQL slightly since the EMSFireDacClient.getdata has to have data returned. insert into Table01 (FileName,FileData) values (:FileName,:FileData) returning Filename,FileData; Tested on client with this procedure to make sure that it works and posts with string parameters. procedure THeaderFooterForm.btnPostClick(Sender: TObject); var Stream:TMemoryStream; begin EMSFireDacClient1.GetEndpoint.Params.Clear; EMSFireDacClient1.GetEndpoint.AddParameter('FileName',edit1.Text); stream := TMemoryStream.Create; Try stream.LoadFromFile(edit2.Text); stream.Seek(0,0); EMSFireDacClient1.GetEndpoint.AddParameter('FileData',Edit2.Text); EMSFireDacClient1.GetData; Finally stream.Free; mtblob.Refresh //refresh memtable End; end; All works well and this is where I am stuck. I can't figure out how to use a stream parameter with TEMSFireDacClient. There is no Loadfromstream for params, only addparameter which takes only string value. Some setstream procedure on parambyname but doesn't seem to work and posts the text value. Here is what I tried and I am stumped. procedure THeaderFooterForm.btnPostClick(Sender: TObject); var Stream:TMemoryStream; begin EMSFireDacClient1.GetEndpoint.Params.Clear; EMSFireDacClient1.GetEndpoint.AddParameter('FileName',edit1.Text); stream := TMemoryStream.Create; Try stream.LoadFromFile(edit2.Text); stream.Seek(0,0); EMSFireDacClient1.GetEndpoint.AddParameter('FileData',edit2.Text); EMSFireDacClient1.GetEndpoint.Params.ParameterByName('FileData').SetStream(stream,ooCopy); EMSFireDacClient1.GetData; Finally stream.Free; mtblob.Refresh //refresh memtable End; end; This seems the correct way to add and access the second param but still no luck. It runs and posts the text field but nothing to the blob field. procedure THeaderFooterForm.btnPostClick(Sender: TObject); var Stream:TMemoryStream; aParam: TRESTRequestParameter; begin EMSFireDacClient1.GetEndpoint.Params.Clear; EMSFireDacClient1.GetEndpoint.AddParameter('FileName',edit1.Text); stream := TMemoryStream.Create; Try stream.LoadFromFile(edit2.Text); stream.position := 0; aParam := EMSFiredacClient1.GetEndpoint.Params.AddItem; aParam.Name := 'FileData'; aParam.SetStream(stream,ooCopy); //also tried ooRest and ooApp EMSFireDacClient1.GetData; Finally //stream.Free; mtblob.Refresh //refresh memtable End; end; I am stumped. Do I need a different approach sending file in header or body of Rest request, but then what do I do on the server side. I can't find any examples at all of the EMSDataSetResouce with blob fields. Thanks for any help.
Read More

Can FMX.Graphics.TBitmap.Canvas safely be created by threads?

I'm maintaining a Delphi 10.2.3 Isapi application that uses FMX.Graphics.TBitmap. Multiple threads are creating their own private bitmap, draw on it, return the binary content to the webrequest handler, and free the bitmap. While debugging access violations are occuring in this stack trace: :760c4742 KERNELBASE.RaiseException + 0x62 System.DynArraySetLength(nil,$407163,16,$F) System.DynArraySetLength($6113648,$5DDE84,1,$6B6FE78) System.Generics.Collections.TListHelper.InternalSetCapacity(8514146) System.Generics.Collections.TListHelper.InternalGrow(???) System.Generics.Collections.TListHelper.InternalGrowCheck(???) System.Generics.Collections.TListHelper.InternalAddManaged((no value)) System.Messaging.TMessageManager.SubscribeToMessage(???,(FMX.Canvas.D2D.TCanvasD2D.ContextLostHandler,$6122F70)) FMX.Canvas.D2D.TCanvasD2D.CreateFromBitmap(???,SystemDefault) FMX.Graphics.TBitmap.GetCanvas Unit1.TWorker.Execute I suspect that this code in the FMX framework code is not threadsafe: // FMX.Canvas.D2D.pas: constructor TCanvasD2D.CreateFromBitmap(const ABitmap: TBitmap; const AQuality: TCanvasQuality); begin inherited; FLastBrushTransform := TMatrix.Identity; CreateResources; FContextLostId := TMessageManager.DefaultManager.SubscribeToMessage(TContextLostMessage, ContextLostHandler); end; It is calling the singleton TMessageManager.DefaultManager and adding a handler to it's internal dictionary, without any locking. That doesn't look very threadsafe. According to the documentation FMX bitmaps can be used in threads when using BeginScene and EndScene, which is fine. But actually creating/destroying a FMX canvas does not seem to be threadsafe because of the subscribe/unsubscribe to the singleton default MessageManager? Is this assumption correct? The strange thing is that it might only raise access violations when any code has been paused and resumed somewhere in the debugger via a breakpoint. When the program is never paused by breakpoints it will run without problems.
Read More

Which stylenames from the stylefile appear in the optionlist of the stylelookup property?

When building a firemonkey application using a stylebook, I'm trying to understand which styles ( stylenames ) from the stylebook appear as an option in the proposed list for the stylelookup property for a firemonkey control. E.g. when using a tlistboxgroupheader inside a tlistbox, you can (only) choose 'listboxplainheader' as style ( although the default style file also contains e.g. listboxgroupheader ). You can edit this property manually and I suppose the related style will be used then but I'm puzzled how this list is determined ? I'm aware of how the default stylename is determined ( via naming conventions ) in case it's not set explicitly, but this is clearly a different story as e.g. the word 'plain' has nothing to do with tlistboxgroupheader. I don't find anything in the ( text ) style file that could link 'listboxplainheader' with tlistboxgroupheader. Is there a way of changing this popup list ( if you wanted to ? e.g. create a custom style and have it appearing as a choice for all your other similar controls for quick use ) Dirk
Read More

How to set the size ( height ) of a tlistboxgroupheader or tlistboxgroupfooter?

I'm building a mobile application using firemonkey. This application has a tlistbox on the main form and I've an issue with setting the height at design time of the tlistboxgroupheader. Although I can set it of course through the size property and see the effect on the form itself ( the platformdefault property becomes false for the size ) , it reverts back to the original size whenever I do something like : -using the style button in the IDE , go from windows style to android -if already in android style, do a F12/F12 cycle ( rerendering the form ). ( I have a specific android style defined in the stylebook ) The size reverts back to 30 but the platformdefault property stays false. This does NOT happen for the normal tlistboxitems. I tried many things ( as I'm fairly new into fmx and styling ), but I think it's a bug ? This happens regardless of a stylename set on the group item or not -In my case, the size always returns to size 30. I'm not sure where that comes from ( the listbox itself has no itemheight defined ) and it it can be changed for all. -If I stick to windows only, it does not happen and it shows correct size at runtime and keeps it at designtime... More in general, I find the link between the various 'classic' style properties ( like VCL ) of the form components itself and the related fmx style,e.g. in this case 'listboxfooter' quite unclear. Like in this case is the size also coming from a styleobject or not ? IF yes, which one as the style is a layout containing other styleobjects and a text object. But also, setting many, many properties of styleobjects in the styleeditor have no impact ( for sure the none visual ones ) but how to know which ones do, and which ones don"t ? Is there a good recent article describing in detail how the styling mechanisms work ? Especially about priorities ? ( what setting overules the other one and takes priority etc..). I'm sure this styling framework is very powerfull, but at the cost of a steep lurning curve coming from VCL ?( Opening my first stylebook was nothing far from 'overwhelming' -- "what do all these things do ?" :-) --.
Read More

Can’t open multiview with tap

I have a TRectangle with a TChart on it (chart Align is on Client). The TChart has HitTest set to false. I have the following code that should open a Multiview when the TChart is tapped on iOS (tap passes through to the rectangle): void __fastcall TForm1::RectanglePlotTap(TObject *Sender, const TPointF &Point) { Form1->MultiViewPlotOptions->ShowMaster(); ShowMessage("tap"); } When i tap the only thing that happens is the "tap" message pops up. The multiview does not appear. So, i added the following click event void __fastcall TForm1::RectanglePlotClick(TObject *Sender) { Form1->MultiViewPlotOptions->ShowMaster(); ShowMessage("click"); } Now, if i tap and drag my finger a short distance i get the "click" message and my multiview appears. If I just tap then I get the "tap" popup and no multiview. What could be the deal? I use that same "tap" approach in several other places in my app and they all work correctly, opening their respective multiviews when I tap. I was just experimenting here and left that "click" event in place and i found this weird behavoir. I can't figure out why the Tap by itself is not working as it does in other places of my app. I'm working in Rad Studio 10.3 (on iOS) and i'm using TeeChart Pro VCL-FMX (build 2019.28) but I don't think that is the issue. I say that because in other places in my app i'm clicking "through" a TChart to fire a Tap event on the underlying control and it works fine (opens its Multiview with just a tap).
Read More