HelpNDoc Pascal Script поддерживает структуры? - PullRequest
0 голосов
/ 29 мая 2019

Я пытаюсь создать структуру:

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 Error

Поясняется API HelpNDoc здесь .

Что-то не так с моим кодом?

1 Ответ

1 голос
/ 29 мая 2019

Я решил пойти другим путем и использовал более простую технику:

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;

Это компилируется, и в конце я получаю отсортированный массив идентификаторов тем. Так что всплывающая подсказка теперь указана как я хочу.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...