Code: Select all
procedure TfrmTest.Button8Click(Sender: TObject);
var
s: string;
List : TStringList;
m : TMemoryStream;
begin
RichViewEdit1.Style := RvStyle1;
s := MergeRTF3(_Artikel.getLangBezRTF, _KuText.getLangTextRTF); [color=red]// Different to Button7Click[/color]
RichViewEdit1.Clear;
List := TStringList.Create;
m := TMemoryStream.Create;
try
List.Text := s;
List.SaveToStream(m);
m.Position := 0;
RichViewEdit1.LoadRTFFromStream(m);
finally
FreeAndNil(List);
FreeAndNil(m);
end;
RichViewEdit1.Format;
end;
// This works fine
function TfrmTest.MergeRTF3(aRTFString1, aRTFString2: string): string;
var
List: TStringList;
m : TMemoryStream;
rv : TRichViewEdit;
ItemNo, Offs: Integer;
begin
rv := RichViewEdit1; [color=red] // The different RichViewEdit is on the Form [/color]
// Load RTFString1 in RichviewEdit
List := TStringList.Create;
m := TMemoryStream.Create;
try
List.Text := aRTFString1;
m.Position := 0;
List.SaveToStream(m);
m.Position := 0;
rv.LoadRTFFromStream(m);
rv.Format;
finally
FreeAndNil(List);
FreeAndNil(m);
end;
// Move Caret to the end
ItemNo := rv.ItemCount-1;
Offs := rv.GetOffsAfterItem(ItemNo);
rv.SetSelectionBounds(ItemNo,Offs,ItemNo,Offs);
// Insert RTFString2 in RichviewEdit
List := TStringList.Create;
m := TMemoryStream.Create;
try
List.Text := aRTFString2;
m.Position := 0;
List.SaveToStream(m);
m.Position := 0;
rv.InsertRTFFromStreamEd(m);
rv.Format;
finally
FreeAndNil(List);
FreeAndNil(m);
end;
// New RTFString
List := TStringList.Create;
m := TMemoryStream.Create;
try
m.Position := 0;
rv.SaveRTFToStream(m, false);
m.Position := 0;
List.LoadFromStream(m);
Result := List.Text;
finally
FreeAndNil(List);
FreeAndNil(m);
end;
end;
-------------------------------------------------------------------------------------
This is what I want, but this is not working, the style is lost
Code: Select all
procedure TfrmTest.Button7Click(Sender: TObject);
var
s: string;
List : TStringList;
m : TMemoryStream;
begin
RichViewEdit1.Style := RvStyle1;
s := MergeRTF2(_Artikel.getLangBezRTF, _KuText.getLangTextRTF);
RichViewEdit1.Clear;
List := TStringList.Create;
m := TMemoryStream.Create;
try
List.Text := s;
List.SaveToStream(m);
m.Position := 0;
RichViewEdit1.LoadRTFFromStream(m);
finally
FreeAndNil(List);
FreeAndNil(m);
end;
RichViewEdit1.Format;
end;
// This don't work.
function TfrmTest.MergeRTF2(aRTFString1, aRTFString2: string): string;
var
List: TStringList;
m : TMemoryStream;
rv : TRichViewEdit;
ItemNo, Offs: Integer;
begin
rv := TRichViewEdit.Create(Self); [color=red] // The different create RichViewEdit [/color]
try
rv.Parent := Self;
rv.Style := RvStyle1;
// Load RTFString1 in RichviewEdit
List := TStringList.Create;
m := TMemoryStream.Create;
try
List.Text := aRTFString1;
m.Position := 0;
List.SaveToStream(m);
m.Position := 0;
rv.LoadRTFFromStream(m);
rv.Format;
finally
FreeAndNil(List);
FreeAndNil(m);
end;
// Move Caret to the end
ItemNo := rv.ItemCount-1;
Offs := rv.GetOffsAfterItem(ItemNo);
rv.SetSelectionBounds(ItemNo,Offs,ItemNo,Offs);
// Insert RTFString2 in RichviewEdit
List := TStringList.Create;
m := TMemoryStream.Create;
try
List.Text := aRTFString2;
m.Position := 0;
List.SaveToStream(m);
m.Position := 0;
rv.InsertRTFFromStreamEd(m);
rv.Format;
finally
FreeAndNil(List);
FreeAndNil(m);
end;
// New RTFString
List := TStringList.Create;
m := TMemoryStream.Create;
try
m.Position := 0;
rv.SaveRTFToStream(m, false);
m.Position := 0;
List.LoadFromStream(m);
Result := List.Text;
finally
FreeAndNil(List);
FreeAndNil(m);
end;
finally
FreeAndNil(rv);
end;
end;