【问题标题】:Find fully qualified unit names quickly?快速找到完全限定的单位名称?
【发布时间】:2019-11-22 07:16:35
【问题描述】:

我喜欢在 Uses 语句中尽可能使用完全限定的单位名称:

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;

但我并不总是知道这一点。例如。在介绍了Min() 函数之后,我不知道 Math 单元的完全限定名称是什么,所以我只是添加了那个

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Math;

有快速找到完全限定名称的技巧吗?

相关:Namespaces in DelphiUse "System.SysUtils" or "SysUtils" in Delphi?

【问题讨论】:

    标签: delphi namespaces


    【解决方案1】:

    只需将鼠标悬停在单位名称上,例如Math,鼠标光标在uses语句中。
    应显示带有完全限定单元名称 (System.Math) 的工具提示。

    【讨论】:

      【解决方案2】:

      用我发现的一个技巧回答我自己的问题,但也许还有其他的

      只需添加“不合格名称”,

      uses
        Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
        Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Math;
      

      ... 然后 Ctrl-单击 新名称。这将打开 Delphi 源文件,光标位于 unit 语句上:

      {*******************************************************}
      {                                                       }
      {           CodeGear Delphi Runtime Library             }
      {                                                       }
      { Copyright(c) 1995-2018 Embarcadero Technologies, Inc. }
      {              All rights reserved                      }
      {                                                       }
      { Copyright and license exceptions noted in source      }
      {                                                       }
      {*******************************************************}
      
      unit System.Math;
      

      【讨论】:

      • 我发现使用Ctrl + Enter key组合在光标处打开文件更快。有时,当您编写代码时,没有时间在鼠标和键盘之间切换。 There you can find more interesting HotKeys ;)
      • 如果您只有 DCU 文件而没有完整的源代码,这是否有效?
      • @NasreddineGalfout,不,如果您没有源 *.pas-files,这将不起作用。 IDE 会告诉你:Unable to locate file "XXX.pas".
      【解决方案3】:

      另一种可能性:

      使用 DelphiDabblers Unit2NS 工具。

      Unit2NS 是 Delphi 程序员查找单元所属命名空间的小工具。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-03-10
        • 1970-01-01
        • 1970-01-01
        • 2016-06-30
        • 1970-01-01
        相关资源
        最近更新 更多