Hola,
Cita:
Empezado por Troy
(...) usa un componente de la libreria SynEdit el cual cumple con lo que necesitas.
|
Ya lo creo que cumple... acaso hasta demasiado.
A ver qué les parece este componente muy basado en los que se citan y en "TRichEdit":
Código Delphi
[-]
unit UDecRichEdit;
interface
uses
Windows, ComCtrls, RichEdit,
Classes, Controls, Messages,
SysUtils, ShellApi;
type
TDecRichEditClicUrl = procedure(Sender: TObject; const url: string) of object;
type
TDecRichEdit = class(TRichEdit)
private
FAutoAbrirUrls: boolean;
FOnClicUrl: TDecRichEditClicUrl;
procedure CNNotify(var Msg: TWMNotify); message CN_NOTIFY;
protected
procedure CreateWnd; override;
procedure AbrirUrl(const url: string);
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property OnClicUrl: TDecRichEditClicUrl read FOnClicUrl write FOnClicUrl;
property AutoAbrirUrls: boolean read FAutoAbrirUrls write FAutoAbrirUrls default true;
end;
procedure Register;
implementation
constructor TDecRichEdit.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FAutoAbrirUrls := true;
end;
destructor TDecRichEdit.Destroy;
begin
inherited Destroy;
end;
procedure TDecRichEdit.AbrirUrl(const url: string);
begin
if url <> EmptyStr then
ShellExecute(Handle, 'open',
PChar(url), nil, nil, SW_NORMAL);
end;
procedure TDecRichEdit.CreateWnd;
begin
inherited CreateWnd;
SendMessage(Handle, EM_AUTOURLDETECT, 1, 0);
SendMessage (Handle, EM_SETEVENTMASK, 0, ENM_LINK);
end;
procedure TDecRichEdit.CNNotify(var Msg: TWMNotify);
type
PENLink = ^TENLink;
var
RT: TextRange;
begin
case Msg.NMHdr^.code of
EN_LINK:
begin
if (PENLink(Msg.NMHdr).Msg=WM_LBUTTONDOWN) then
begin
RT.chrg := PENLink(Msg.NMHdr).chrg;
GetMem(RT.lpstrText, RT.chrg.cpMax - RT.chrg.cpMin + 2);
try
SendMessage(Handle, EM_GETTEXTRANGE, 0, Integer(@RT));
if Assigned(FOnClicUrl) then
FOnClicUrl(Self, RT.lpstrText);
if FAutoAbrirUrls then AbrirUrl(RT.lpstrText);
finally
FreeMem(RT.lpstrText);
end;
end;
Msg.Result := 0;
end;
else
inherited;
end;
end;
procedure Register;
begin
RegisterComponents('Samples', [TDecRichEdit]);
end;
end.