Delphi中的注释方法?

30

我有一段需要认真记录的代码,并想知道是否有类似于C#/.NET的内置XML文档功能可用于Embarcadero Delphi。 我的目标是以某种方式显示如何正确使用特定方法的信息,以便在Delphi XE3的自动完成中突出显示。

类似于以下内容(C#):

/// <summary>
/// Some useful information helping other developers use this method correctly
/// </summary>
public static void ADocumentedMethod();

Delphi XE3是否支持类似这样的功能?

谢谢您的阅读。


你使用的是哪个版本的Delphi XE3?能否请您在问题中包含这些信息? - TLama
2
@TLama不应该真的有影响,据我所知,自D2010以来,/// XML-doc在所有SKU中都可用,尽管它似乎有点错误... - ain
2
@ain,我在谈论Documentation Insight,据我记得,在Delphi的较便宜的版本中有很大的限制,对吗? - TLama
它也适用于Delphi 2009。 - Andreas Rejbrand
1个回答

41
该功能名为XML文档注释,并且在此处有文档记录。它似乎是紧密模仿了等效的.NET功能,因此您应该感到非常熟悉。
文档包含以下示例:
/// <summary> Removes the specified item from the collection
/// </summary>
/// <param name="Item">The item to remove
/// </param>
/// <param name="Collection">The group containing the item
/// </param>
/// <remarks>
/// If parameter "Item" is null, an exception is raised.
/// <see cref="EArgumentNilException"/>
/// </remarks>
/// <returns>True if the specified item is successfully removed;
/// otherwise False is returned.
/// </returns>
function RemoveItem(Item: Pointer; Collection: Pointer): Boolean;
begin
  // Non-XML DOC comment
  // ...
end;

这导致了帮助洞察提示:

在此输入图片描述

还有其他各种处理和使用文档的方式。


1
这太完美了!非常感谢!我觉得有点傻,没有通过谷歌找到它。 - FLClover
2
此外,为了在外部单元中显示,此XML文档应该存在于一个单元的“interface”部分。 - Paul
注意,您也可以使用<exception cref="EExceptionTypeName">来处理异常。问题是,异常名称(cref)不会显示在提示中。(10.3 Rio)。 - Toon Krijthe
在保罗的评论中添加,上下文链接为https://dev59.com/N6Tja4cB1Zd3GeqPHtLT,所以它类似于在接口、实现中重复出现的一行过程或函数。 - user30478

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接