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:
1 |
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
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.