memo1.SelText := UpperCase(memo1.SelText)
in TRichViewEdit will be:
rv1.InsertText(UpperCase(memo1.GetSelText));
But if the selection contain pictures, tables, or multiple fonts, it will be lost.
To avoid it, more complex processing it required - item by item. Some text may be Unicode, it must be taken into account.
Below is a fragment of RVCharCase.pas from RichViewActions (a key function changing the character case).
Code: Select all
procedure RVChangeCharCase(rve: TCustomRichViewEdit; CharCase: TRVCharCase);
var i, ItemNo1, ItemNo2, Offs1, Offs2: Integer;
AItemNo1, AItemNo2, AOffs1, AOffs2: Integer;
TextStyles: TFontInfos;
ItemOptions: TRVItemOptions;
s, s1, s2: String;
begin
TextStyles := rve.Style.TextStyles;
rve := rve.TopLevelEditor;
rve.BeginUndoGroup(rvutModifyItem);
rve.SetUndoGroupMode(True);
LockWindowUpdate(rve.Handle);
try
rve.GetSelectionBounds(ItemNo1, Offs1, ItemNo2, Offs2, True);
rve.GetSelectionBounds(AItemNo1, AOffs1, AItemNo2, AOffs2, False);
if ItemNo2<>ItemNo1 then begin
if rve.GetItemStyle(ItemNo1)>=0 then begin
ItemOptions := rve.GetItem(ItemNo1).ItemOptions;
s := rve.GetItemText(ItemNo1);
s1 := RVU_Copy(s, 1, Offs1-1, ItemOptions);
s2 := RVU_Copy(s, Offs1, Length(s), ItemOptions);
if s2<>'' then begin
s2 := ChangeCharCase(s1, s2, TextStyles[rve.GetItemStyle(ItemNo1)], CharCase);
rve.SetItemTextEd(ItemNo1, s1+s2);
end;
end;
for i := ItemNo1+1 to ItemNo2-1 do
if rve.GetItemStyle(i)>=0 then begin
s := rve.GetItemText(i);
s := ChangeCharCase('', s, TextStyles[rve.GetItemStyle(i)], CharCase);
rve.SetItemTextEd(i, s);
end;
if rve.GetItemStyle(ItemNo2)>=0 then begin
ItemOptions := rve.GetItem(ItemNo2).ItemOptions;
s := rve.GetItemText(ItemNo2);
s1 := RVU_Copy(s, 1, Offs2-1, ItemOptions);
s2 := RVU_Copy(s, Offs2, Length(s), ItemOptions);
if s1<>'' then begin
s1 := ChangeCharCase('', s1, TextStyles[rve.GetItemStyle(ItemNo2)], CharCase);
rve.SetItemTextEd(ItemNo2, s1+s2);
end;
end
end
else begin
ItemOptions := rve.GetItem(ItemNo1).ItemOptions;
s := rve.GetItemText(ItemNo1);
s1 := RVU_Copy(s, 1, Offs1-1, ItemOptions);
s2 := RVU_Copy(s, Offs2, Length(s), ItemOptions);
s := RVU_Copy(s, Offs1, Offs2-Offs1, ItemOptions);
s := ChangeCharCase(s1, s, TextStyles[rve.GetItemStyle(ItemNo1)], CharCase);
rve.SetItemTextEd(ItemNo1, s1+s+s2);
end;
finally
LockWindowUpdate(0);
rve.SetUndoGroupMode(False);
rve.SetSelectionBounds(AItemNo1, AOffs1, AItemNo2, AOffs2);
end;
end;