[Unit] Moving to the next/previous item

Demos, code samples. Only questions related to the existing topics are allowed here.
Post Reply
Sergey Tkachenko
Site Admin
Posts: 17555
Joined: Sat Aug 27, 2005 10:28 am
Contact:

[Unit] Moving to the next/previous item

Post by Sergey Tkachenko »

Update: a downloading link is removed, because RVGoToItem.pas is included in RichViewActions. It can be found in <TRichView Dir>\RichViewActions\Source\

GoToItem.pas includes functions for moving the caret to the next/previous item meeting the specified criteria. The caret is moved to the end of the found item (the item can be selected optionally).
The functions return True if moving was successful (False if the item was not found in the given direction). The search is started from the current item (i.e. the item containing the caret).

Moving the caret to the next/previous hyperlink:
function GoToNextHyperlink(rve: TCustomRichViewEdit; Select: Boolean=False): Boolean;
function GoToPrevHyperlink(rve: TCustomRichViewEdit; Select: Boolean=False): Boolean;

Moving the caret to the next/previous item of one of the specified types:
function GoToNextItem(rve: TCustomRichViewEdit; ItemTypes: array of Integer; Select: Boolean=False): Boolean;
function GoToPrevItem(rve: TCustomRichViewEdit; ItemTypes: array of Integer; Select: Boolean=False): Boolean;
Example (moving to the next picture):

Code: Select all

GoToNextItem(rve, [rvsPicture, rvsHotPicture])
Moving the caret to the next/previous item, using a user-defined function for checking items:
function GoToNextItemEx(rve: TCustomRichViewEdit; UserData: Pointer; Func: TCheckItemFunction; Select: Boolean=False): Boolean;
function GoToPrevItemEx(rve: TCustomRichViewEdit; UserData: Pointer; Func: TCheckItemFunction; Select: Boolean=False): Boolean;
UserData parameter is passed to Func.
Func is a function for checking items. It must return True if RVData.GetItem(ItemNo) is ok (i.e. the caret should be moved to it).
type TCheckItemFunction = function (RVData: TCustomRVData; ItemNo: Integer; UserData: Pointer): Boolean;
Example (moving to the next text having a colored background):

Code: Select all

function IsColoredText(RVData: TCustomRVData; ItemNo: Integer;
    UserData: Pointer): Boolean;
var StyleNo: Integer;
begin
  StyleNo := RVData.GetItemStyle(ItemNo);
  Result := (StyleNo>=0) and (RVData.GetRVStyle.TextStyles[StyleNo].BackColor<>clNone);
end;
...
  GoToNextItemEx(RichViewEdit1, nil, IsColoredText);
Post Reply