How to recognize delimited word and replace with a new word
-
- Site Admin
- Posts: 17557
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
-
- Site Admin
- Posts: 17557
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Here is the example of what you asked originally.
When the user clicks any text inside [], it selects it (including []), displays some form (a message box in this test) and replace it to a new value.
This demo uses OnRVMouseUp event.
Limitation: this keyword, including [], must be written using the same font.
When the user clicks any text inside [], it selects it (including []), displays some form (a message box in this test) and replace it to a new value.
This demo uses OnRVMouseUp event.
Limitation: this keyword, including [], must be written using the same font.
Code: Select all
function SelectFld(rve: TCustomRichViewEdit): Boolean;
var s: String;
ItemNo, Offs, Offs1, Offs2: Integer;
begin
Result := False;
if rve.SelectionExists then
exit;
rve := rve.TopLevelEditor;
ItemNo := rve.CurItemNo;
Offs := rve.OffsetInCurItem;
if (rve.GetItemStyle(ItemNo)<0) or
(Offs<=rve.GetOffsBeforeItem(ItemNo)) or (Offs>=rve.GetOffsAfterItem(ItemNo)) then
exit;
s := rve.GetItemText(ItemNo);
Offs1 := Offs;
while (Offs1>=1) and (s[Offs1]<>'[') do
dec(Offs1);
if Offs1<1 then
exit;
Offs2 := Offs;
while (Offs2<=Length(s)) and (s[Offs2]<>']') do
inc(Offs2);
if Offs2>Length(s) then
exit;
rve.SetSelectionBounds(ItemNo, Offs1, ItemNo, Offs2+1);
Result := True;
end;
procedure TForm3.RichViewEdit1RVMouseUp(Sender: TCustomRichView;
Button: TMouseButton; Shift: TShiftState; ItemNo, X, Y: Integer);
begin
if SelectFld(RichViewEdit1) then begin
Application.MessageBox(PChar('Here you can display a form to edit '+RichViewEdit1.GetSelText), 'Test', 0);
RichViewEdit1.InsertText('New value');
end;
end;
-
- Site Admin
- Posts: 17557
- Joined: Sat Aug 27, 2005 10:28 am
- Contact: