Recent

Author Topic: Does Lazarus have a URI sensitive label or text component?  (Read 10583 times)

vfclists

  • Hero Member
  • *****
  • Posts: 1013
    • HowTos Considered Harmful?
Does Lazarus have a URI sensitive label or text component?
« on: September 08, 2010, 03:34:24 pm »

Does Lazarus have a URI sensitive label or text component, one that will open up a browser or an email client when clicked?

Lazarus 3.0/FPC 3.2.2

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4460
  • I like bugs.
Re: Does Lazarus have a URI sensitive label or text component?
« Reply #1 on: September 08, 2010, 04:10:55 pm »
No but it is easy to implement with TStaticText and OpenURL.
You can set StaticText properties so it better resembles a link.
IIRC OpenURL is implemented in Lazarus trunk version, 0.9.29.
Place TStaticText on your form and do something like the following. WebUrl is the URL you want to open.


procedure TForm1.FormCreate(Sender: TObject);
begin
  StaticText1.Caption:=WebUrl;
end;

procedure TForm1.StaticText1Click(Sender: TObject);
begin
  OpenURL(WebUrl);
end;
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: Does Lazarus have a URI sensitive label or text component?
« Reply #2 on: September 08, 2010, 04:27:36 pm »
Or:

Code: [Select]
procedure TForm1.Label1Click(Sender:TObject);
begin
  OpenURL(Label1.Caption);
end;

procedure TForm1.Label1MouseEnter(Sender:TObject);
begin
  Label1.Cursor := crHandPoint;
  Label1.Font.Color := clBlue;
  Label1.Font.Style := [fsUnderline];
  if Pos('http://www.', Label1.Caption) = 0 then
    Label1.Caption := 'http://www.' + Label1.Caption;
end;

procedure TForm1.Label1MouseLeave(Sender:TObject);
begin
  Label1.Font.Style := [];
  if Pos('http://www.', Label1.Caption) > 0 then
    Label1.Caption := Copy(Label1.Caption, Pos('http://www.', Label1.Caption) + Length('http://www.'), Length(Label1.Caption));
end;             
« Last Edit: September 08, 2010, 04:33:25 pm by typo »

mica

  • Full Member
  • ***
  • Posts: 196
Re: Does Lazarus have a URI sensitive label or text component?
« Reply #3 on: September 08, 2010, 06:12:08 pm »

vfclists

  • Hero Member
  • *****
  • Posts: 1013
    • HowTos Considered Harmful?
Re: Does Lazarus have a URI sensitive label or text component?
« Reply #4 on: September 10, 2010, 08:16:35 am »
The wiki page has been edited today.

Was that you?

Thanks

TOvcURL from Orpheus Port?
http://wiki.lazarus.freepascal.org/OrphPort

Lazarus 3.0/FPC 3.2.2

Raf20076

  • Full Member
  • ***
  • Posts: 173
    • https://github.com/Raf20076
Re: Does Lazarus have a URI sensitive label or text component?
« Reply #5 on: October 11, 2014, 10:56:56 pm »
Put on your form StaticText component then in uses put  lclintf, then use 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.

 

TinyPortal © 2005-2018