How can I get a QueryString Parameter Variable from the URL using Delphi code?
Let's assume I have a URL as follows: https://www.example.com/index.html?first_name=shaun&last_name=roselt
How do I get first_name
and last_name
from the URL?
I want to do this via Delphi only code and not JavaScript.
There's a function called GetQueryParam
within the WebLib.WebTools
unit that comes with TMS Web Core.
You can use it as follows to get the first_name
and last_name
parameters:
uses WebLib.WebTools;
...
var
FirstName, LastName: String;
begin
FirstName := GetQueryParam('first_name');
LastName := GetQueryParam('last_name');
if (FirstName = '') then
console.log('First Name Not Found!')
else
console.log('First Name is ' + FirstName);
if (LastName = '') then
console.log('Last Name Not Found!')
else
console.log('Last Name is ' + LastName);
end;