ScaleRichViewEdit and MarkSubString

ScaleRichView support and discussion (TRichView add-on for WYSIWYG editing)
Post Reply
Jan
Posts: 14
Joined: Sat Dec 05, 2009 4:06 pm

ScaleRichViewEdit and MarkSubString

Post by Jan »

Hello Dear

I use ScaleRichViewEdit version 4.0.3 and RichView v13.0.5
and try to use the MarkSubStringW function from MarkSearch.pas.
See: http://www.trichview.com/forums/viewtopic.php?t=57

I create a new form and drop a SRichViewEdit.
The FormCreate event looks so:

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
begin
  SRichViewEdit1.Clear;
  SRichViewEdit1.RichViewEdit.LoadText(ExtractFilePath(Application.ExeName)+'Unit1.pas', 0, 0, False);
  SRichViewEdit1.Format;
  MarkSubStringW('TForm1', clBlack, clRed, false, false, SRichViewEdit1.RichViewEdit, nil);
end;
The file is loaded accurate but if I add the MarkSubStringW funktion
I get a "List index out of bounds (-1).".

Can anyone provide me a simple example how to use the MarkSubStringW with ScaleRichViewEdit?

Best regards
Jan
Sergey Tkachenko
Site Admin
Posts: 17521
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Move SRichViewEdit1.Format after MarkSubStringW.
Jan
Posts: 14
Joined: Sat Dec 05, 2009 4:06 pm

Post by Jan »

Hello Sergey

Thanks for your response.
Sergey Tkachenko wrote:Move SRichViewEdit1.Format after MarkSubStringW.
That's right but after SRichViewEdit1.Format the marks are persistent.
How can I remove the marks again?
Sergey Tkachenko
Site Admin
Posts: 17521
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Unfortunately, no. Only by reloading.
Jan
Posts: 14
Joined: Sat Dec 05, 2009 4:06 pm

Post by Jan »

Is there another solution for highlighting of searched text?
Removing of marked words with AddictSpell works also.
Sergey Tkachenko
Site Admin
Posts: 17521
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Well, there is a solution. This feature is not supported officially, but I know some users use it.
The idea is in using the same mechanism as it's used for live spelling. You can create another type of marks (instead of drawing a waved line), for example drawing a rectangular frame (unfortunately, you cannot use a background color, because marks are drawn after the text).

I'll try to create an example later in this week.
Sergey Tkachenko
Site Admin
Posts: 17521
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

http://www.trichview.com/support/files/rectmarks.zip contains a unit with the following functions:

procedure AddRectMark(RVData: TCustomRVData; ItemNo, Offs, Len: Integer; Color: TColor); - adds a mark at the specified position. A mark is displayed as a rectangle of the specified Color.

procedure MarkSubstring(rv: TCustomRichView; const s: String; Color: TColor); - marks all occurences of s. This is a sample function, it does not have necessary options (case sensitivity, whole words, etc.). You can modify it yourself.

procedure ClearRectMarks(rv: TCustomRichView); - clears all marks.

Example:

Code: Select all

procedure TForm3.ToolButton69Click(Sender: TObject);
begin
  MarkSubstring(SRichViewEdit1.RichViewEdit, 'the', clRed);
  SRichViewEdit1.UpdateBuffer;
end;

// OnChange event
procedure TForm3.SRichViewEdit1Change(Sender: TObject);
begin
  ClearRectMarks(SRichViewEdit1.RichViewEdit);
end;
Jan
Posts: 14
Joined: Sat Dec 05, 2009 4:06 pm

Post by Jan »

Hello Sergey

Thank you very much for your solution.
I changed it a little bit and implement the SearchOptions like below:

Code: Select all

procedure TRVMarkTextPainter.EnumItemsAdd(RVData: TCustomRVData; ItemNo: Integer;
  var UserData1: Integer; const UserData2: String; var ContinueEnum: Boolean);
var
  s: String;
  pc, pcfound: PChar;
  SearchOptions: TStringSearchOptions;
begin
  if RVData.GetItemStyle(ItemNo) < 0 then exit;
  s := RVData.GetItemText(ItemNo);
  pc := PChar(s);
  SearchOptions := [soDown];
  Include(SearchOptions, soMatchCase); // if MatchCase
  Include(SearchOptions, soWholeWord); // if WholeWord
  pcfound := SearchBuf(pc, lstrlen(pc), 0, 0, UserData2, SearchOptions);
  while pcfound <> nil do
    begin
//      Inc(FoundCount); for return value
      AddRectMark(RVData, ItemNo, pcfound-pc+1, System.Length(UserData2), TColor(UserData1));
      pcfound := SearchBuf(pcfound, lstrlen(pcfound), 1, 0, UserData2, SearchOptions);
    end;
  ContinueEnum := True;
end;
Post Reply