Category: StackOverflow

How to post data with a ContentType of ‘multipart/form-data’ in Delphi REST?

I am trying to send a request to a REST API using multipart/form-data as the content type. I always get "HTTP/1.1 500 Internal Error" as a response. I tried sending requests to methods that require application/x-www-form-urlencoded and had success, though. How can I achieve getting a success response from my API using multipart/form-data? Here is my code: procedure TForm10.Button1Click(Sender: TObject); var RESTClient1: TRESTClient; RESTRequest1: TRESTRequest; strImageJSON : string; Input: TIdMultipartFormDataStream; begin Input := TIdMultipartFormDataStream.Create; Input.Clear; Input.AddFormField('Email', 'tugba.xx@allianz.com.tr'); Input.AddFormField('Password', 'xxxx'); RESTClient1 := TRESTClient.Create('http://192.168.1.172:81/'); RESTRequest1 := TRESTRequest.Create(nil); RESTRequest1.Method := TRESTRequestMethod.rmPOST; RESTRequest1.Resource := 'api/Mobile/MobileLoginControl'; RESTRequest1.AddBody(Input,TRESTContentType.ctMULTIPART_FORM_DATA); RESTRequest1.Client := RESTClient1; RESTRequest1.Execute; strImageJSON := RESTRequest1.Response.Content; end;
Read More

Screen orientation on iOS

Per this question in Delphi an FMX app can be selectively forced into landscape or portrait with code like this: procedure TForm1.Chart1Click(Sender: TObject); begin if Application.FormFactor.Orientations = [TScreenOrientation.Landscape] then Application.FormFactor.Orientations := [TScreenOrientation.Portrait] else Application.FormFactor.Orientations := [TScreenOrientation.Landscape]; end; end; I can't figure out how to translate this code above to C++Builder. I tried the following code based on this post but it gives access violation on both iOS and Android: void __fastcall TForm1::Button1Click(TObject *Sender) { _di_IInterface Intf; if (TPlatformServices::Current->SupportsPlatformService(__uuidof(IFMXScreenService), Intf)) { _di_IFMXScreenService ScreenService = Intf; TScreenOrientations Orientation; Orientation << TScreenOrientation::Landscape; ScreenService->SetScreenOrientation(Orientation); } } Is this even doable in FMX with C++Builder?
Read More

Firemonkey accelerator key

I'm looking for a way to register the accelerator key other than the standard way, that is when the text with the accelerator key is set to the tLabel. I googled a lot and did not find nothing of the sort. Also, in other question, was suggested to set the Label's Text property at Form's creation, after setting the Label's parent, but this does not work because the Label's Text and Parent properties, might be set dynamically at run time. Assuming the form has a TEdit, a TLabel and a TRectangle, named respectively MyEdit, MyLabel and MyRect, follows a brief code example ... interface type tMyForm = class (TForm) ... procedure FormCreate (Sender: tObject); ... end; ... implementation tMyForm.FormCreate (Sender: tObject); begin ... MyLabel.FocusControl := MyEdit; MyLabel.Text := '&Label'; MyLabel.Parent := MyRect; // after this setting // the accelerator key stop working // I need some code here that makes the accelerator key work, no matter where // I set the TLabel's Text and Parent properties ... end;
Read More

Firemonkey Android app keep old version component

I'm doing a Android app with Firemonkey. I had a TImage and I change the multiresbitmap, I change opacity of an TRectangle. When I compil to Windows its ok, but when I compil to android plateforme (debug) I keep the "old" version of the image content and my rectangle keep old opacity. Even if I clear projet, compil to release I have this effect. Its like there are a cache or something like that. Someone already have this problem ? Thanks
Read More

Getting exception: Segmentation fault (11) while showing a secondary form on Android 9

I'm using Delphi 10.3 to develop an Android application. The main form needs to show a login form based on data stored in an INI file. But, when I show the form, I get an exception: Exception class Segmentation fault (11). I'm facing this problem only on Android 9 (Motorola E6s model). On other Android versions, it works fine. Below I have mentioned the simple code: Form1 (Main form): Buttonclick; // After showing the main form begin Form2.Show; end; Also tried with another code: ShowEvent;// On show event begin Form2.Show; end; Please help me, how can I fix this?
Read More

TGraphicControl Equivalent to FMX

I need to create an FMX component, formerly I used TGraphicControl but the architecture has changed a lot for FMX. The component to create is an array, where I determine pixel size being height and width, and the number of pixels per row and column, for example, a 30 row by 45 column array with 15x15 pixel frames each. I would do this in VCL with TGraphicControl, and now in FMX, what is the equivalent?
Read More

Objective-C to Delphi : bug?

I have this protocol: @protocol Once <NSObject> .... @end And I translate it to Once = interface(IObjectiveC) .... end; then I have this function : FOUNDATION_EXTERN id <Once> __nullable CreateOnce(void) API_AVAILABLE(macos(10.11), ios(8.0)) NS_RETURNS_RETAINED; that I translate to function CreateOnce: Once; cdecl; external libOnce name _PU + 'CreateOnce'; The problem is that CreateOnce always returns me nil! If I translate it to function CreateOnce: POINTER; cdecl; external libOnce name _PU + 'CreateOnce'; so I replace Once by POINTER then it's work! Any idea why ? Also how can I convert a pointer to a Once object (Once = interface(IObjectiveC))?
Read More

How to name files to differentiated VCL and FireMonkey code

I have a VCL component that runs on Delphi 7 to 10.3. I am now porting it to FMX. To avoid maintaining two codebases, I will use conditional defines in my source to separate any custom FMX and VCL code. When I compile the component for distribution a script will output either the VCL or FMX source files. My problem is how to make the VCL DCUs and FMX DCUs co-exist on the same system (for users who have both the VCL and FMX versions of my component) as both folders will need to be on the Delphi path. In other words, my VCL units are named: myunit1.pas, myunit2.pas, etc. And the FMX versions: fmx.myunit1.pas, fmx.myunit2.pas, etc (Ideally I would name the VCL ones vcl.myunit1.pas, vcl.myunit2.pas, etc. That way the VCL version of the component would only see the vcl.-.pas files and the FireMonkey only the fmx.-.pas files. Unfortunately I cannot do this because then it won't work on older Delphi versions). Now when I compile a FireMonkey app it tries to use the non-fmx prefixed source files, in preference to the fmx._.pas ones. I need to "hide" the vcl source folder to get it to compile (re-ordering the Delphi paths does not help). If there another way to make FireMonkey avoid using the vcl files? (I fear I will need to write a script to give all the files a new name, e.g. FMXmyunit1.pas and update all of the references in all of the files).
Read More