trichview.com

trichview.support




Re: Getting the text of an item using TCustomRVItemInfo


Return to index


Author

Message

Martin Holmes

Posted: 07/10/2004 1:36:56


Many thanks indeed for this. It's just what I need, and very instructive

too.


Cheers,

Martin


Sergey Tkachenko wrote:

> Here is a function for searching the item of style = RequiredStyle.

> (RVData, ItemNo):

> - on input: location of your new footnote; search will start from the

> previous item and will continue backward

> - on output: location of the found item (if it was found: return

> value=True).

>

> uses CRVData, CRVFData, RVItem;

>

>

> function FindPreviousItem(var RVData: TCustomRVData; var ItemNo: Integer;

>   RequiredStyle: Integer): Boolean;

>    {...................................................}

>    function FindItemInRVData(ARVData: TCustomRVData; AItemNo: Integer):

> Boolean; forward;

>    {...................................................}

>    function FindItemInItem(Item: TCustomRVItemInfo; StoreSub:

> TRVStoreSubRVData): Boolean;

>    var FRVData: TCustomRVData;

>    begin

>      Result := False;

>      if StoreSub=nil then

>        FRVData := TCustomRVData(item.GetSubRVData(StoreSub, rvdLast))

>      else

>        FRVData := TCustomRVData(item.GetSubRVData(StoreSub, rvdPrev));

>      if FRVData<>nil then begin

>        repeat

>          Result := FindItemInRVData(FRVData, FRVData.Items.Count-1);

>          if Result then

>            break;

>          FRVData := TCustomRVData(item.GetSubRVData(StoreSub, rvdPrev));

>        until FRVData=nil;

>      end;

>      StoreSub.Free;

>    end;

>    {...................................................}

>    function FindItemInRVData(ARVData: TCustomRVData; AItemNo: Integer):

> Boolean;

>    var i: Integer;

>    begin

>      ARVData := ARVData.GetRVData;

>      for i := AItemNo downto 0 do begin

>        if ARVData.GetItem(i).StyleNo=RequiredStyle then begin

>          Result := True;

>          ItemNo := i;

>          RVData := ARVData;

>          end

>        else

>          Result := FindItemInItem(ARVData.GetItem(i), nil);

>        if Result then

>          exit;

>      end;

>      Result := False;

>    end;

>    {...................................................}

> var StoreSub: TRVStoreSubRVData;

> begin

>   Result := False;

>   dec(ItemNo);

>   while RVData<>nil do begin

>     Result := FindItemInRVData(RVData, ItemNo);

>     if Result then

>       break;

>     RVData.GetParentInfo(ItemNo, StoreSub);

>     if ItemNo<0 then begin

>       StoreSub.Free;

>       break;

>     end;

>     RVData := RVData.GetAbsoluteParentData;

>     Result := FindItemInItem(RVData.GetItem(ItemNo), StoreSub);

>     if Result then

>       break;

>     dec(ItemNo);

>   end;

> end;

>

>

> Test:

>

> var RVData: TCustomRVData;

>     ItemNo: Integer;

> begin

>   RVData := RichViewEdit1.TopLevelEditor.RVData;

>   ItemNo := RichViewEdit1.TopLevelEditor.CurItemNo;

>   if FindPreviousItem(RVData, ItemNo, 0) then begin

>     RVData := RVData.Edit;

>     TCustomRVFormattedData(RVData).SetSelectionBounds(

>       ItemNo, RVData.GetOffsBeforeItem(ItemNo),

>       ItemNo, RVData.GetOffsAfterItem(ItemNo));

>     TCustomRVFormattedData(RVData).Invalidate;

>   end;

> end;

>

> Note: this function uses undocumented methods.

>

>





Powered by ABC Amber Outlook Express Converter