Recent

Author Topic: new to lazarus: how to use openurl  (Read 9103 times)

smitsg

  • New member
  • *
  • Posts: 9
new to lazarus: how to use openurl
« on: June 08, 2011, 12:50:50 pm »
Hello!

I'm new to programming/lazarus.
I would like to build an exe which contains some links to url's. Can anyone provide me some sourcecode for a form with two links and a openfolder-button? When I know the syntax I can probably go on from that basic source.....
Hope I'm not offending anyone with this basic question, I downloaded lazarus yesterday for the first time....

Regards,
Giel

Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Re: new to lazarus: how to use openurl
« Reply #1 on: June 08, 2011, 01:02:53 pm »
Good reference is Lazarus itself. Go to main menu: Help -> About Lazarus -> tab About . There are two links. They are normal labels (TLabel) with OnMouseEnter, OnMouseLeave and OnMouseDown events and OpenURL function.
See the code in ../lazarus/ide/aboutfrm.pas :
Code: [Select]
procedure TAboutForm.URLLabelMouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  OpenURL(TLabel(Sender).Caption);
end;

procedure TAboutForm.URLLabelMouseLeave(Sender: TObject);
begin
  TLabel(Sender).Font.Style := [];
  TLabel(Sender).Font.Color := clBlue;
  TLabel(Sender).Cursor := crDefault;
end;

procedure TAboutForm. URLLabelMouseEnter(Sender: TObject);
begin
  TLabel(Sender).Font.Style := [fsUnderLine];
  TLabel(Sender).Font.Color := clRed;
  TLabel(Sender).Cursor := crHandPoint;
end;
Open folder is also easy. Put TOpenDialog and TButton on your form. Assign OnClick event of Button and code:
Code: [Select]
if OpenDialog1.Execute then
begin
  //here you can do something with OpenDialog1.FileName
end;
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

smitsg

  • New member
  • *
  • Posts: 9
Re: new to lazarus: how to use openurl
« Reply #2 on: June 08, 2011, 02:07:15 pm »
Thanks for your quick reply!
I'm still confused though....

This is what i have done:
  • start new project
  • added label1 and label2 to the form

Then I changed the source code according to your reccomendation:


unit formulier1;

{$mode objfpc}{$H+}

interface

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

type

  { TForm1 }

  TForm1 = class(TForm)
    Label1: TLabel;
    Label2: TLabel;
    procedure Label1Click(Sender: TObject);
  private
    { private declarations }
  public
    { public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.lfm}

{ TForm1 }


 procedure TForm1.URLLabelMouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  OpenURL(TLabel(Sender).Caption);
end;

procedure TForm1.URLLabelMouseLeave(Sender: TObject);
begin
  TLabel(Sender).Font.Style := [];
  TLabel(Sender).Font.Color := clBlue;
  TLabel(Sender).Cursor := crDefault;
end;

procedure TForm1. URLLabelMouseEnter(Sender: TObject);
begin
  TLabel(Sender).Font.Style := [fsUnderLine];
  TLabel(Sender).Font.Color := clRed;
  TLabel(Sender).Cursor := crHandPoint;
end;
end.



When I try to run it I get the messages:

method identifier expected (several times)
Identifier not found "openurl"

I think I miss some lines......

smitsg

  • New member
  • *
  • Posts: 9
Re: new to lazarus: how to use openurl
« Reply #3 on: June 08, 2011, 02:31:08 pm »
I realised that I didn't put the actual link in the code: where do I put the link (e.g. http://www.google.com)??? Is this a variable that I have to put somewhere.....

Thanks in advance.... And sorry for this basic questions.....

Peter_Vadasz

  • New Member
  • *
  • Posts: 35
Re: new to lazarus: how to use openurl
« Reply #4 on: June 08, 2011, 03:11:23 pm »
If you want to use the openurl procedure, you must add the lclintf unit in the uses section. I made a little example for you take a look at the following link: http://dl.dropbox.com/u/2766266/link.zip
OS: Ubuntu 12.04.2 32 bit
Lazarus: 1.0.8
FPC: 2.6.2

smitsg

  • New member
  • *
  • Posts: 9
Re: new to lazarus: how to use openurl
« Reply #5 on: June 08, 2011, 03:48:55 pm »
Thanks!!!!!
I'll check this further, but this looks exactly what I needed!
Regards!!!

 

TinyPortal © 2005-2018