Delphi ActiveX
Delphi ActiveX
Example: Http.SetUrlVar method
Demonstrates the HTTP SetUrlVar method.Chilkat Delphi ActiveX Downloads
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Chilkat_TLB;
...
procedure TForm1.Button1Click(Sender: TObject);
var
success: Integer;
http: TChilkatHttp;
url: WideString;
sbJson: TChilkatStringBuilder;
statusCode: Integer;
begin
success := 0;
http := TChilkatHttp.Create(Self);
url := 'https://finnhub.io/api/v1/quote?symbol={$symbol}&token={$api_key}';
// When the request is sent, the {$symbol} is replaced with "MSFT"
// and the {$api_key} is replaced with "1234567890ABCDEF"
http.SetUrlVar('symbol','MSFT');
http.SetUrlVar('api_key','1234567890ABCDEF');
sbJson := TChilkatStringBuilder.Create(Self);
success := http.QuickGetSb(url,sbJson.ControlInterface);
if (success = 0) then
begin
Memo1.Lines.Add(http.LastErrorText);
Exit;
end;
statusCode := http.LastStatus;
if (statusCode <> 200) then
begin
Memo1.Lines.Add('Status code: ' + IntToStr(statusCode));
Memo1.Lines.Add('Error Message:');
Memo1.Lines.Add(sbJson.GetAsString());
end
else
begin
Memo1.Lines.Add('JSON Stock Quote:');
Memo1.Lines.Add(sbJson.GetAsString());
end;
// Output:
// JSON Stock Quote:
// {"c":522.98,"d":0.5,"dp":0.0957,"h":524.51,"l":520.86,"o":524.28,"pc":522.48,"t":1755271948}
end;