我正在使用 Delphi 中的 TSynEdit 使用 Sql 编辑器。
我在荧光笔和自动完成的表名中有我的对象名称(表、存储过程、域等),它们以蓝色和下划线显示,这是我想要的,但我想知道我是否可以将这些链接到一个事件我实际上可以打开那个对象。

有没有办法

a) 当鼠标悬停在这样的关键字上时,将光标更改为 handPoint?

b) 单击此类关键字时执行事件、过程、函数?

感谢您的任何建议。

delphi - 如何处理 Synedit 表名上的链接?-LMLPHP

最佳答案

要获取鼠标指向的 token 信息,您可以编写例如像这样的辅助方法:

type
  TSynEditHelper = class helper for TSynEdit
  public
    function GetTokenInfo(const CursorPos: TPoint; out TokenType: Integer; out TokenText: UnicodeString): Boolean; overload;
    function GetTokenInfo(const LineCharPos: TBufferCoord; out TokenType: Integer; out TokenText: UnicodeString): Boolean; overload;
  end;

{ TSynEditHelper }

function TSynEditHelper.GetTokenInfo(const CursorPos: TPoint; out TokenType: Integer; out TokenText: UnicodeString): Boolean;
begin
  Result := GetTokenInfo(DisplayToBufferPos(PixelsToRowColumn(CursorPos.X, CursorPos.Y)), TokenType, TokenText);
end;

function TSynEditHelper.GetTokenInfo(const LineCharPos: TBufferCoord; out TokenType: Integer; out TokenText: UnicodeString): Boolean;
var
  I: Integer;
  A: TSynHighlighterAttributes;
begin
  Result := GetHighlighterAttriAtRowColEx(LineCharPos, TokenText, TokenType, I, A);
end;

并在 OnMouseCursor 中使用它们来设置光标和 OnClick 用于关键字导航:
procedure TForm1.SynEdit1Click(Sender: TObject);
var
  TokenType: Integer;
  TokenText: UnicodeString;
begin
  if TSynEdit(Sender).GetTokenInfo(TSynEdit(Sender).ScreenToClient(Mouse.CursorPos), TokenType, TokenText) and
    (TokenType = Ord(tkTableName)) then
  begin
    ShowMessage(Format('Table token clicked: %s', [TokenText]));
  end;
end;

procedure TForm1.SynEdit1MouseCursor(Sender: TObject; const ALineCharPos: TBufferCoord; var ACursor: TCursor);
var
  TokenType: Integer;
  TokenText: UnicodeString;
begin
  if TSynEdit(Sender).GetTokenInfo(ALineCharPos, TokenType, TokenText) and (TokenType = Ord(tkTableName)) then
    ACursor := crHandPoint;
end;

我找不到此功能的本地方式。

10-07 19:21
查看更多