Recent

Author Topic: How to open a URL from Lazarus  (Read 27057 times)

motaz

  • Sr. Member
  • ****
  • Posts: 495
    • http://code.sd
How to open a URL from Lazarus
« on: December 26, 2009, 08:05:08 am »
Hello
I want to open a link in an About book using the default browser, the same like Delphi's ShellExecute(0, 'open', 'http://www....'

Any body can help?

Vincent Snijders

  • Administrator
  • Hero Member
  • *
  • Posts: 2661
    • My Lazarus wiki user page
Re: How to open a URL from Lazarus
« Reply #1 on: December 26, 2009, 09:20:13 am »
In lazarus 0.9.29, you can use OpenUrl

motaz

  • Sr. Member
  • ****
  • Posts: 495
    • http://code.sd
Re: How to open a URL from Lazarus
« Reply #2 on: December 27, 2009, 09:52:08 am »
Thanks but which unit should I add in uses clause?

Vincent Snijders

  • Administrator
  • Hero Member
  • *
  • Posts: 2661
    • My Lazarus wiki user page
Re: How to open a URL from Lazarus
« Reply #3 on: December 27, 2009, 09:55:44 am »
Did you open the link? The unit is in the right left corner: "Reference for unit 'LCLIntf'".

motaz

  • Sr. Member
  • ****
  • Posts: 495
    • http://code.sd
Re: How to open a URL from Lazarus
« Reply #4 on: December 27, 2009, 11:17:15 am »
Sory I didn't open the link.
But now I can't find OpenURL function in lclintf.pas file.
I've an old snapshot for windows 0.9.29 (15-9-2009), should I update to the latest snapshot


Vincent Snijders

  • Administrator
  • Hero Member
  • *
  • Posts: 2661
    • My Lazarus wiki user page
Re: How to open a URL from Lazarus
« Reply #5 on: December 27, 2009, 11:18:27 am »
Yes.

Raf20076

  • Full Member
  • ***
  • Posts: 184
    • https://github.com/Raf20076
Re: How to open a URL from Lazarus
« Reply #6 on: October 11, 2014, 10:50:29 pm »
Put on your form StaticText component, in uses put lclintf then command OpenUrl see my code.

Code: [Select]
unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, lclintf;

type

  { TForm1 }

  TForm1 = class(TForm)
    StaticText1: TStaticText;
    procedure StaticText1Click(Sender: TObject);
    procedure StaticText1MouseEnter(Sender: TObject);
    procedure StaticText1MouseLeave(Sender: TObject);
  private
    { private declarations }
  public
    { public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.lfm}

{ TForm1 }



procedure TForm1.StaticText1Click(Sender: TObject);
begin
  OpenURL('http://www.lazarus.freepascal.org');
{when you click StaticText it will connect to website using default browser.}
end;

procedure TForm1.StaticText1MouseEnter(Sender: TObject);
begin
  StaticText1.Cursor := crHandPoint;
{cursor changes into handshape when it is on StaticText}
  StaticText1.Font.Color := clBlue;
{StaticText changes color into blue when cursor is on StaticText}
end;

procedure TForm1.StaticText1MouseLeave(Sender: TObject);
begin
  StaticText1.Font.Color := clDefault;
{when cursor is not on StaticText then color of text changes into default color}
end;

end.

Raf20076

  • Full Member
  • ***
  • Posts: 184
    • https://github.com/Raf20076
Re: How to open a URL from Lazarus
« Reply #7 on: October 12, 2014, 09:32:28 am »
How to search text from Lazarus in google? Put on your form TEdit component and TButton. In uses put lclintf to use command OpenUrl, set up variables, see my code

Code: [Select]
unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, lclintf,
  StdCtrls;

type

  { TForm1 }

  TForm1 = class(TForm)
    Button1: TButton;
    Edit1: TEdit;
    procedure Button1Click(Sender: TObject);
  private
    { private declarations }
  public
    { public declarations }
  end;

var
  Form1: TForm1;

implementation


{$R *.lfm}

{ TForm1 }

procedure TForm1.Button1Click(Sender: TObject);

  var
  search_text : WideString;{initiate variable for searched text}
  google_address : WideString;{initiate variable for base google address}
  web_address : WideString;{initiate variable for the whole google address}

begin
  google_address := 'https://www.google.com/?gws_rd=ssl#q=';
{setting up variable for  base google address}
  search_text := Edit1.Text;
{setting up variable for text taken from Edit1 component}
  web_address := google_address + search_text;
{adding search text to base google address}
  OpenURL (web_address);
{open default browser and search text in google}

end;

end.

 

TinyPortal © 2005-2018