Disclosure Statement: This site contains affiliate links, which means that I may receive a commission if you make a purchase using these links. As an eBay Partner, I earn from qualifying purchases.

How to send link to TinyBrowser2 programmatically?y?

Post Reply
luiz_antoniosp
Posts: 8
Joined: Sat Jun 24, 2023 5:28 am

How to send link to TinyBrowser2 programmatically?y?

Post by luiz_antoniosp »

Hi guys,

I open the .exe of TinyBrowser2, but I want to be able to send a link programmatically through a button but it's not working, can anyone help me?
see how I'm doing it, but it doesn't work..I would like to be able to interact through ExecuteJavaScrip

procedure TForm1.Button1Click(Sender: TObject);
begin
InitializeBrowser('https://www.mercadolivre.com.br');
end;

procedure TForm1.InitializeBrowser(const URL: string);
var
ExecInfo: TShellExecuteInfo;
begin
FillChar(ExecInfo, SizeOf(ExecInfo), 0);
ExecInfo.cbSize := SizeOf(ExecInfo);
ExecInfo.fMask := SEE_MASK_NOCLOSEPROCESS;
ExecInfo.lpFile := 'C:\Users\Luiz\Desktop\Navegator\Win32\Debug\TinyBrowser2.exe';
if ShellExecuteEx(@ExecInfo) then
begin
//Wait for the process to finish if necessary
WaitForSingleObject(ExecInfo.hProcess, INFINITE);
// Close process handle
CloseHandle(ExecInfo.hProcess);
end
else
begin
ShowMessage('Erro ao iniciar o processo');
end;
end;
User avatar
salvadordf
Posts: 4057
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: How to send link to TinyBrowser2 programmatically?y?

Post by salvadordf »

Hi,

This is a pure Delphi question. You need to pass the URL as a parameter and modify TinyBrowser2 to read the parameter.

Perhaps the information in these pages can help you :
https://stackoverflow.com/questions/72601144/execute-a-command-line-application-via-shellexecute-and-get-its-return-value
https://stackoverflow.com/questions/38759198/open-external-application-with-passing-parameters-using-delphi-application
luiz_antoniosp
Posts: 8
Joined: Sat Jun 24, 2023 5:28 am

Re: How to send link to TinyBrowser2 programmatically?y?

Post by luiz_antoniosp »

Once again, thank you very much, Salvador, for your immense attention in helping me. The problem is that I can't make the correct change to TinyBrowser2's code so that it can
receiving the parameter, I've tried several ways. but I can't.
User avatar
salvadordf
Posts: 4057
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: How to send link to TinyBrowser2 programmatically?y?

Post by salvadordf »

Modify uTinyBrowser2.pas and define GDefaultURL before the "implementation" section like this :

Code: Select all

var
  GDefaultURL : string = 'https://www.google.com';

implementation
Then use GDefaultURL in TTinyBrowser2.AfterConstruction like this :

Code: Select all

procedure TTinyBrowser2.AfterConstruction;
var
  TempHandle : TCefWindowHandle;
  TempRect : TRect;
begin
  inherited AfterConstruction;

  FChromium                  := TChromiumCore.Create(nil);
  FChromium.DefaultURL       := GDefaultURL;
  FChromium.OnBeforeClose    := Chromium_OnBeforeClose;
  FChromium.OnBeforePopup    := Chromium_OnBeforePopup;
  FChromium.OnOpenUrlFromTab := Chromium_OnOpenUrlFromTab;

  InitializeWindowHandle(TempHandle);
  FChromium.CreateBrowser(TempHandle, TempRect, 'Tiny Browser 2', nil, nil, True);
end;
Open the project code in TinyBrowser2.dpr and read GDefaultURL like this :

Code: Select all

begin
  CreateGlobalCEFApp;

  if ParamCount > 0 then
    GDefaultURL := ParamStr(1);

  if GlobalCEFApp.StartMainProcess then
    begin
      GlobalCEFApp.RunMessageLoop;
      DestroyTinyBrowser;
    end;

  DestroyGlobalCEFApp;
end.
Read these documents for more information about ParamStr and ParamCount :
https://docwiki.embarcadero.com/Libraries/Sydney/en/System.ParamStr
https://docwiki.embarcadero.com/Libraries/Sydney/en/System.ParamCount
https://stackoverflow.com/questions/1593388/how-do-i-recognize-command-line-parameters-in-my-delphi-program
Post Reply