gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 15:24:45 26 4
gpt4 key购买 nike

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

有没有办法

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

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

感谢您的建议。

enter image description here

最佳答案

要获取鼠标指向的 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;

我找不到此功能的原生方式。

关于delphi - 如何处理 Synedit 表名上的链接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50196662/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com