我已经编写了一个根据输入填充RichEdit组件的过程。
procedure LoadCPData(ResName: String);
begin
ResName := AnsiLowercase(ResName) + '_data';
rs := TResourceStream.Create(hInstance, ResName, RT_RCDATA);
try
rs.Position := 0;
info.reMeta.Lines.LoadFromStream(rs);
finally
rs.Free;
end;
end;注意:上述过程存储在一个名为Functions的外部.pas文件中。
当我调用表单中的过程时,RichEdit保持为空。但是,如果我将代码块放在表单本身中,RichEdit组件就会像预期的那样毫无问题地填充数据。现在,我可以将上面的代码块放在表单本身中,但我计划在case语句中多次使用该过程。
为了让我的过程正常工作,我需要包含哪些内容?
非常感谢您的支持!
发布于 2012-10-05 10:45:03
我们使用TJvRichEdit控件代替TRichEdit,这样我们就可以支持嵌入式OLE对象。这与TRichEdit的工作原理非常相似。
procedure SetRTFData(RTFControl: TRichEdit; FileName: string);
var
ms: TMemoryStream;
begin
ms := TMemoryStream.Create;
try
ms.LoadFromFile(FileName);
ms.Position := 0;
RTFControl.StreamFormat := sfRichText;
RTFControl.Lines.LoadFromStream(ms);
ms.Clear;
RTFControl.Invalidate;
// Invalidate only works if the control is visible. If it is not visible, then the
// content won't render -- so you have to send the paint message to the control
// yourself. This is only needed if you want to 'save' the content after loading
// it, which won't work unless it has been successfully rendered at least once.
RTFControl.Perform(WM_PAINT, 0, 0);
finally
FreeAndNil(ms);
end;
end;我改编自另一个例程,所以它不是我们使用的完全相同的方法。我们从数据库中流式传输内容,所以我们永远不会从文件中读取。但我们确实将字符串写入内存流,以便将其加载到RTF控件中,因此这在本质上做了相同的事情。
https://stackoverflow.com/questions/12738523
复制相似问题