I’ve searched around here and asked Google and I can’t seem to get a clear answer.
There’s a way to look for a specific name used as a query-string arg in the URL.
But I can’t find any way that lets you load whatever comes after the ? on the URL.
I found this example, but I can’t get the value assigned to anything without the IDE saying it’s undefined.
var queryString : string;
. . .
asm
queryString = window.location.search.substring(1);
end;
I don’t know how many ways to ask thie question, but none of them are getting me something that works.
I’ve tried this:
abc := GetQueryParam( 'abc' );
console.log( 'abc=['+abc+']' );
But adding …?abc=123 to the URL (launched with F9) only shows this:
abc=[]
What am I missing?
In unit WEBLib.WebTools.pas, you have 2 helper functions:
function GetQueryParam(AName: string): string;
function HasQueryParam(AName: string; var AValue: string; CaseSensitive: boolean = true): boolean;
I’m using that, as I illustrated.
So if I have ?abc=123 on the URL, what should GetQueryParem(‘abc’) return?
I’m getting an empty string.
I would expect it returns '123'
I can't see any problem
test code:
procedure TForm1.WebButton1Click(Sender: TObject);
var
p: string;
begin
if HasQueryParam('abc',p,true) then
webmemo1.Lines.Add(p);
end;
I used the single parameter version. I’ll try the other one.
Thanks.
it turns out you need to put the ?arg1&arg2… BEFORE the #abc tags in the URL that the run-time system adds when you hit F9.
I’ve rarely worked with those in URLs. I guess the # effictively terminates the URL
The formal reference is RFC 3986, the URI syntax standard. RFC 3986: Uniform Resource Identifier (URI): Generic Syntax
It defines a URI as:
URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
so, the hash should come at the end of the URL.
1 Like