You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过TWebLabelLink跳转LinkedIn?非Windows应用无法用ShellAPI

在Delphi Web应用中用TWebLinkLabel跳转至LinkedIn主页的解决方案

错误原因

cannot find unit "ShellAPI"

ShellAPI是Windows平台专属的系统单元,你的应用是Web应用,运行在浏览器环境中,不支持Windows原生API,因此会出现该错误。

解决方案

方案一:直接设置控件属性(无需编写代码)

打开Object Inspector,选中你的TWebLinkLabel控件,找到URL属性,直接填入LinkedIn公司主页地址:https://www.linkedin.com/company/companyname/。设置完成后,点击标签即可自动跳转。

方案二:通过OnClick事件代码控制跳转

如果需要通过自定义逻辑控制跳转,可使用浏览器的JavaScript API实现,无需引用任何Windows相关单元。修改代码如下:

uses
  System.SysUtils, System.Classes, JS, Web, WEBLib.Graphics, WEBLib.Controls,
  WEBLib.Forms, WEBLib.Dialogs, WEBLib.StdCtrls, WEBLib.ExtCtrls;

procedure TfrmMain.WebLinkLabel1Click(Sender: TObject);
begin
  // 在新标签页打开链接
  asm
    window.open('https://www.linkedin.com/company/companyname/', '_blank');
  end;

  // 若需在当前页面跳转,替换为以下代码:
  // asm
  //   window.location.href = 'https://www.linkedin.com/company/companyname/';
  // end;
end;

注意事项:

  • 移除uses列表中的Windows、Vcl.StdCtrls、ShellAPI等Windows平台专属单元,Web应用不需要这些依赖。
  • 利用asm块直接调用浏览器原生API,这是Web应用中处理链接跳转的标准方式。

内容的提问来源于stack exchange,提问作者Puffer Fish

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.23 17:22:40