我使用以下方法连接两个单独的RTF文本,最后在TcxCustomRichEdit
控件上显示结果。它从多年来完美地运作。现在我需要在RTF文本中支持图像。
问题是当TcxCustomRichEdit
控件中有图像时,它会连接但只是排除图像。
我怎样才能做到这一点?
示例代码:示例代码取自http://delphi.about.com/od/tmemotrichedit/a/richedit-append.htm并已修改
在代码中,您可以看到放置了两个TcxCustomRichEdit
,最后在连接后,结果显示在第一个TcxCustomRichEdit
控件上。
Procedure AppendFromRichEdit(FromRch,ToRch: TcxCustomRichEdit); // Function to append rich edit text from source to Destination
var
MemStream: TMemoryStream;
rtfStream: TEditStream;
function EditStreamReader(
dwCookie: DWORD;
pBuff: Pointer;
cb: LongInt;
pcb: PLongInt): DWORD; stdcall;
begin
result := $0000;
try
pcb^ := TStream(dwCookie).Read(pBuff^, cb) ;
except
result := $FFFF;
end;
end; (*EditStreamReader*)
begin
MemStream := TMemoryStream.Create;
try
with FromRch as TcxCustomRichEdit do Begin
Lines.SaveToStream( MemStream );
end;
MemStream.Position := 0;
rtfStream.dwCookie := DWORD(MemStream) ;
rtfStream.dwError := $0000;
rtfStream.pfnCallback := @EditStreamReader;
Try
ToRch.InnerControl.Perform(
EM_STREAMIN,
SFF_SELECTION or SF_RTF or SFF_PLAINRTF, LPARAM(@rtfStream)
) ;
if rtfStream.dwError <> $0000 then
raise Exception.Create(TranslateQBMessage('QBToolsErrorAppendingRTFData'));
except
On E: Exception do
// do nothing MsgBox(E.Message)
end;
finally
MemStream.Free;
end;
end;
procedure ConcatenateAndShow;
var
redTemp: TcxRichEdit;
begin
try
redTemp := TcxRichEdit.Create(memTesto.Owner);
redTemp.Parent := memTesto.Parent;
redTemp.Visible := False;
redTemp.Clear;
redTemp.Text := MySecondRichEditControl.Text; //Text in Second Rich Edit Control
AppendFromRichEdit(redTemp, memTesto);
finally
redTemp.Free;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
FirstRicheditControl.lines.Append('This is My Text in First Richedit Control');
FirstRicheditControl.lines.Append('And Finally after concatenation it will show in Same Control');
ConcatenateAndShow;
end;
答案 0 :(得分:1)
在函数ConcatenateAndShow中添加redTemp.properties.AllowObjects = True可以解决问题因为allowobejcts属性的dault值为false,所以它不允许RTF中的图像对象
Try
redTemp := TcxRichEdit.Create(memTesto.Owner);
redTemp.Parent := memTesto.Parent;
redTemp.Visible := False;
redtemp.Properties.AllowObjects := True;
.
.