Via Cà Matta 2 - Peschiera Borromeo (MI)
+39 02 00704272
info@synaptica.info

FindCmdLineSwitch.. Small thing but maybe someone doesn’t know…

Digital solution partner

FindCmdLineSwitch.. Small thing but maybe someone doesn’t know…

Working in Delphi and looking at many sources I saw that the “paramStr” instruction is used a lot when “FindCmdLineSwitch” could be used which helps and avoids writing useless libraries.

If for example when you launch your application you have a situation like this:

c:\myapp.exe -url "https://chisono.io.me" -port 50443 -clientCert "c:\tmp\miocert.crt"

and you want to intercept the parameters with “FindCmdLineSwitch” it’s very simple you just need for example:

procedure TfrmWebDavDemo.FormCreate(Sender: TObject);
var
  LCertPath: string;
  LswitchVal: string;
  LServerPort: UInt16;
begin
 DebugMode := False;
 SSLHelper := TSSLHelper.Create;
 IdHTTPsrv.OnQuerySSLPort := SSLHelper.QuerySSLPort;


 if FindCmdLineSwitch('-url',LswitchVal,True) then
   edUrl.Text := LswitchVal;

......
end;

I imagine that all those who will read this post are already aware of this instruction, but since it is the third program that I open and find a unit that does the same things as FindCmdLineSwitch, I decided to write this post.

 

Tags: ,