Jump to content

Leaderboard


Popular Content

Showing content with the highest reputation on 10/30/21 in all areas

  1. Dmitriy M

    Exception classes implementing interfaces

    While assuming that this code snippet is just to demonstrate the point, it always raises a question in my head: why trap every possible exceptions and then re-raise if it's not the one we are expecting, if we could just trap the one we are intrested in. try Parse; except on E: ParsingException do LogSomethingInformative; end;
  2. corneliusdavid

    Android project deployment messed up

    I decided to move up to Delphi 11 and just use their default platform installer for Android. I also decided to retire the old Android ZTE phone. I'm able to compile, debug, and run both Android and iOS apps from Delphi 11 now. I was still getting the weird error listed in my previous post for the DelphiVersions project though, even after deleting all temporary files and recompiling. Finally, I just renamed the project to DelphiVersionsMobileBroken, created a new blank mobile app, added the forms, removed the default form, set up the icons and version info--and it works! Something was seriously amiss--but everything is back working now--and in Delphi 11. Whew!
  3. I had to do this for a password management tray app I wrote for personal use. Here's the technique I ended up with (with lots of help from stack overflow and others.) Step 1: Use EnumWindows with a callback to build up a list of window handles. They will be in the current z-order. It needs to check if the window is visible, unowned, and has WS_EX_APPWINDOW in its style before adding it to your list. Step 2: Loop through the window handles above and find the first one in the list with a thread process id different than your current program. This is done using GetWindowThreadProcessId on each window handle from your enum list and comparing to the results of GetCurrentThreadID. That window handle should be the main window of the app that was last active. I would perform the above whenever my tray app was activated. I'm guessing there are exceptions for "stay on top" apps and such but it seemed to work for my needs. I hope that helps or at least gives a clue! -Mark Update note: Once I get the window handle of the last activated app I would also call GetLastActivePopup on it (as I needed to know if it had a modal popup active.)
  4. That would only qualify as a LTNS version
  5. Any component can be created in code at runtime. Here's the code for your posted set of components: var RESTClient1: TRESTClient; RESTRequest1: TRESTRequest; RESTResponse1: TRESTResponse; begin RESTClient1 := TRESTClient.Create(Self); RESTClient1.Name := 'RESTClient1'; RESTClient1.BaseURL := 'https://api-eu1.XXXXXXXXXXXXXXX/ORD'; RESTClient1.Params := <>; RESTRequest1 := TRESTRequest.Create(Self); RESTRequest1.Name := 'RESTRequest1'; RESTRequest1.AssignedValues := [rvConnectTimeout, rvReadTimeout]; RESTRequest1.Client := RESTClient1; RESTRequest1.Method := rmPOST; with RESTRequest1.Params.Add do begin Kind := pkHTTPHEADER; Name := 'x-api-compleat-key'; Value := '0aXXXXXXXXXXXXXXXXXXXXXX94'; end; with RESTRequest1.Params.Add do begin Kind := pkREQUESTBODY; Name := 'body9BE6CF603159471FB026D7FF6FC3D2DB'; Value := ; ContentType := ctAPPLICATION_JSON; end; RESTRequest1.Response := RESTResponse1; RESTResponse1 := TRESTResponse.Create(Self); RESTResponse1.Name := 'RESTResponse1'; end; The GExperts IDE plugin has a very easy way to generate this. After it's installed, simply right+click on a component and select "Components to Code" and the code to generate the component is copied to the clipboard. Then just paste them into your code editor. It does one component at a time so I had to combine the three RESTxxx components into the VAR section after each one but it's really as simple as that.
×