我试图将一个片段保存到一个TMemoryStream中,希望能在当前主题上插入流。流是二进制格式的-我看到它,当我将流写到我的硬盘。下面是我的HelpNDoc Pascal引擎代码库的代码条。参数"content“表示当前的HTML主题文本:
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;是否有一种方法,将流直接保存到现有主题的当前位置?或者:流可以保存为HTML或文本吗?
发布于 2022-08-26 03:52:58
我以多种方式解决了这个问题:
中创建001.html文件
,将文件001.html的文本放到当前主题位置
我的助手函数显示如下:
// ------------------------------------------------------------------------
// this is the root path of the HelpNDoc documentation
// files. Some sub-folders will be include later ...
// ------------------------------------------------------------------------
const BASE_PATH = 'E:\HelpNDoc\mozilla\';
// ------------------------------------------------------------------------
// @brief Get the variable, that is set in the content text (editor), and
// give back the contents of the variable that was defined in the
// template settings.
//
// @param content - String: Body text for current topic.
//
// @return String, that would be append to the current position of compiler
// processor. It replace the "hintbox" variable with files that will
// be involved as external files.
//
// @author Jens Kallup
// ------------------------------------------------------------------------
function getCustomHintBoxCode(content: String): String;
var _idx: Integer;
var _len: Integer;
var _txt: String ;
var _tmp: String ;
var _str: String ;
var _arr: THndLibraryItemsInfoArray;
var _inf: THndLibraryItemsInfo;
var _lst: TStringList;
const _hintbox = 'hintbox';
begin
_arr := HndLibraryItems.GetItemList([5]);
_str := content;
for _idx := 0 to Length(_arr) - 1 do
begin
_inf := _arr[ _idx ];
_tmp := Trim( Copy(_inf.Caption,Length(_hintbox)+2,64));
if (LowerCase(Copy(_inf.Caption,1,7)) = _hintbox) then
begin
_tmp := HndLibraryItems .GetItemContentAsText (_inf.id);
_txt := HndGeneratorInfo.GetCustomSettingValue(_tmp);
_txt := StringReplace(_txt,'HintBox=','',[rfReplaceAll]);
_txt := _txt + '.html';
_lst := TStringList.Create;
try
try
_lst.LoadFromFile(BASE_PATH + 'helpers\' + _txt);
except
on E: Exception do begin
ShowMessage('Error occur during read the file: ' + #13#10 +
BASE_PATH + 'helpers\' + _txt);
end;
end;
if _lst.Count > 0 then
begin
_str := StringReplace(
_str, // old content
_tmp, // mark
_lst.Text, // new text
[rfReplaceAll]);
end;
finally
_lst.Clear;
_lst.Free;
end;
end;
end;
result := _str;
end;这给我带来的好处是,在内容编辑器中设置微小的变量名,而不是像代码片段这样的大胖框,.你会喜欢的:-)
我希望这对任何其他人都有帮助。代码以beerware的形式出现。因此,请公平地使用这段代码,并注意这篇文章。
https://stackoverflow.com/questions/73495354
复制相似问题