1

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.

1 Answer 1

2

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;
Sign up to request clarification or add additional context in comments.

3 Comments

How does it behave on edgy (but legal) cases like https://site.web/?one=1&one=2&one=3?
@AmigoJack It will return the last param which is "3" in your case.
upvote for question and answer, just what I was looking for, thanks Shaun

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.