pascalscript - HelpNDoc Pascal 脚本是否支持结构?
问题描述
我正在尝试创建一个结构:
MyTopic
TopicID : String;
HelpID : Integer;
我想创建一个由这些结构组成的数组,以便对它们进行排序。
我曾尝试使用此type
/record
语法,但它失败了。
更新
我定义了这个type
并且procedure
:
type
TMyTopicRecord = record
idTopic : String;
idContextHelp : integer;
End;
procedure GetSortedTopicIDs(aTopics : array of String; size : Integer);
var
aMyTopicRecords : array of TMyTopicRecord;
temp : TMyTopicRecord;
iTopic, i, j : Integer;
begin
// Init the array
SetLength(aMyTopicRecords, size);
// Fill the array with the existing topid ids.
// Get the context ids at the same time.
for iTopic := 0 to size - 1 do
aMyTopicRecords[iTopic].idTopic := aTopics[iTopic];
aMyTopicRecords[iTopic].idContextHelp := HndTopics.GetTopicHelpContext(aTopics[iTopic]);
// Sort the array on context id
for i := size-1 DownTo 1 do
for j := 2 to i do
if (aMyTopicRecords[j-1].idContextHelp > aMyTopicRecords[j].idContextHelp) Then
begin
temp := aMyTopicRecords[j-1];
aMyTopicRecords[j-1] := aMyTopicRecords[j];
aMyTopicRecords[j] := temp;
end;
// Rebuild the original array of topic ids
for iTopic := 0 to size - 1 do
aTopics[iTopic] := aMyTopicRecords[iTopic].idTopic;
end;
该过程在父函数的循环中被调用(代码片段):
function GetKeywordsAsHtml(): string;
var
aKeywordList: THndKeywordsInfoArray;
aAssociatedTopics: array of string;
nBlocLevel, nDif, nClose, nCurKeywordLevel, nCurKeywordChildrenCnt: Integer;
nCurKeyword, nCurKeywordTopic: Integer;
nCountAssociatedTopics: Integer;
sCurrentKeyword, sKeywordLink, sKeywordRelated: string;
sKeywordJsCaption: string;
begin
Result := '<ul>';
nBlocLevel := 0;
try
aKeywordList := HndKeywords.GetKeywordList(False);
for nCurKeyword := 0 to length(aKeywordList) - 1 do
begin
sCurrentKeyword := aKeywordList[nCurKeyword].id;
nCurKeywordLevel := HndKeywords.GetKeywordLevel(sCurrentKeyword);
nCurKeywordChildrenCnt := HndKeywords.GetKeywordDirectChildrenCount(sCurrentKeyword);
sKeywordLink := '#';
sKeywordRelated := '[]';
aAssociatedTopics := HndTopicsKeywords.GetTopicsAssociatedWithKeyword(sCurrentKeyword);
nCountAssociatedTopics := Length(aAssociatedTopics);
if nCountAssociatedTopics > 0 then
begin
GetSortedTopicIDs(aAssociatedTopics, nCountAssociatedTopics);
// Code snipped
end;
end;
finally
Result := Result + '</ul>';
end;
end;
在 HelpNDoc内部编辑器中编译的脚本没有问题。但是当我去实际构建我的 HTML 文档时,我遇到了一个问题:
HelpNDoc API 在这里解释。
我的代码有问题吗?
解决方案
我决定采用不同的方式并使用更简单的技术:
procedure GetSortedTopicIDs(var aTopics : array of String; iNumTopics : Integer);
var
iTopic : Integer;
// List of output
aList: TStringList;
begin
// Init list
aList := TStringList.Create;
// Build a new array of "nnn x"
// - nnn is the help context id
// - x is the topid id
// Note: I know that the context ID values are within the range 0 - 200
for iTopic := 0 to iNumTopics - 1 do
// We pad the context id with 0. We could increase the padding width to
// make the script mre useful
aList.Add(Format('%0.3d %s', [
HndTopics.GetTopicHelpContext(aTopics[iTopic]),
aTopics[iTopic]
]));
// Now we sort the new array (which basically sorts it by context id)
aList.Sort;
// Update original array
for iTopic := 0 to iNumTopics - 1 do
// We ignore the "nnn " part of the string to get just the topic id
aTopics[iTopic] := copy(aList[iTopic],5, length(aList[iTopic])-4);
// Tidy up
aList.Free;
end;
这编译,我在它的末尾得到了主题 ID 的排序数组。所以弹出帮助现在按我的意愿列出。
推荐阅读
- powershell - [Byte[]] 到 [System.Drawing.Image] 到 [Byte[]] 与 Powershell Azure 函数
- python-3.x - python:即使版本存在,pip给出版本也没有找到错误
- django - IntegrityError:关系“table_model”的“column_id”列中的空值违反非空约束
- sequelize.js - Sequelize,当一个表与同一个表有belongsTo和belongsToMany关系时如何使用findAll
- selenium-webdriver - TestNg DataProvider注解我们可以返回Object[][][]。3维数组而不是2?
- php - PHP - 如何获取数组值中的字符数?
- javascript - Javascript中矩形的合理包装
- android-studio - Camera.PictureCallback 返回捕获的图像元数据?
- python - @Jit(nopython=True) TypingError: non-precise type pyobject
- maven - 警告无法激活请求的配置文件“本地”