Delphi 2009 引入 TLinkLabel,通過 Caption 屬性設置 HTML 格式文本,OnLinkClick 事件響應鏈接點擊,配合 ShellExecute 實現打開網頁/郵件/文件等操作。
效果圖:

unit Unit1;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;
type
TForm1 = class(TForm)
LinkLabel1: TLinkLabel;
procedure FormCreate(Sender: TObject);
procedure LinkLabel1LinkClick(Sender: TObject; Link: string; LinkType: TSysLinkType);
end;
var Form1: TForm1;
implementation {$R *.dfm}
uses ShellAPI;
procedure TForm1.FormCreate(Sender: TObject);
begin
LinkLabel1.Caption := '萬一的 Delphi 博客';
end;
procedure TForm1.LinkLabel1LinkClick(Sender: TObject; Link: string; LinkType: TSysLinkType);
begin
ShellExecute(0, nil, PChar(Link), nil, nil, SW_SHOWNORMAL);
end;
end.
object Form1: TForm1
Left = 23; Top = 87; Caption = 'Form1'
ClientHeight = 122; ClientWidth = 291
object LinkLabel1: TLinkLabel
Left = 24; Top = 24; Width = 53; Height = 17
Caption = 'LinkLabel1'; TabOrder = 0
OnLinkClick = LinkLabel1LinkClick
end
end
要點: Caption 接受標準 HTML `` 標籤;Link 參數直接傳給 ShellExecute 支援 http、mailto、file 等協議。
TRegex 支援的完整元字符、量詞、斷言與 Unicode 分類
Delphi for PHP 深度評測:VCL for PHP 架構剖析與效能實測
GDI+ 進階繪圖教學 (36):TGPPen 線帽樣式設定與互動示範
Delphi 實作冪運算:計算 x 的 y 次方完整範例
多線程編程(16) - WaitableTimer 等待定時器對象(續二):SleepEx 可提醒等待詳解
TListView 拖放檔案實作:WM_DROPFILES 訊息處理與檔案移動
再學GDI+[49]: 路徑基礎屬性查詢 - GetPointCount、GetPathPoints、GetLastPoint、GetBounds