I tried to save a Snippet to a TMemoryStream in the hope, I could insert the stream on the current topic. The stream is in binary form - I saw it, as I write the stream to my hard disk. Here is a code stripe of my code base for HelpNDoc Pascal-Engine.
The parameter "content" stands for the Current HTML Topic text:
function getCustomHintBoxCode(content: String): String;
var _idx: Integer;
var _txt: String ;
var _tmp: String ;
var _str: String ;
var _arr: THndLibraryItemsInfoArray;
var _inf: THndLibraryItemsInfo;
const _hintbox = 'hintbox';
const _snippet = 'snippet';
begin
_arr := HndLibraryItems.GetItemList([7]); // 7 = Snippets
_str := content;
for _idx := 0 to Length(_arr) - 1 do
begin
_inf := _arr[ _idx ];
_tmp := Trim( Copy(_inf.Caption,Length(_snippet)+2,64));
if (LowerCase(Copy(_inf.Caption,1,7)) = _snippet) then
begin
HndLibraryItems.GetItemContent(_inf.id).SaveToFile('E:\out.tmp');
showmessage('0: ' + _tmp);
end;
end;
result := _str;
end;
Is there a way, to save the stream directly to the current position of the existing topic ? Or: can the stream be saved a HTML or Text ?
I solved the problem in this multiple way:
I have add a Variable to the Items-Library witht the name "hintbox_1"
I set the placeholder string to "pophtml"
I have added a new Variable: "enum -> HintBox=001 | HintBox=002 | ...
I create 001.html file(s) in the sub-directory ".\helpers"
I change the Pascal-Template "topics.pas.htm" file, so it fit my needs. the string "HintBox1=" would be cut, and rest "001" String, I added ".html", so I get: "001.html".
let's compile the Project, give me the text of file 001.html into the current topic position, by replace text.
My helper function shows so:
This bring me the advantage, to set tiny variable name into the Content-Editor instead the big fat boxes like Snippets, ... You would love it :-)
I hope this can be usefull for any others. The code comes as beerware. So, please be fair, and use the code with a little note of this article.