GetItemText?

General TRichView support forum. Please post your questions here
Post Reply
CrimsonKing
Posts: 7
Joined: Wed Nov 01, 2017 11:13 am

GetItemText?

Post by CrimsonKing » Mon Nov 13, 2017 2:31 am

Hello,
first, I apologize for my poor english.

I try to get a line text in TRichviewEdit, there's a small problem.

a line is, Example...

This is a test line...

S := rve.GetItemText(0) -> result S) This is a test line...

And I Change TextStyle to BOLD(or Underline, etc...) at a word in a line, Example...

This is a test line...

S := rve.GetItemText(0) -> result S) This

and 'is a test line...' is Changed ItemNo = 1.

How get I full line text?

Sergey Tkachenko
Site Admin
Posts: 14228
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: GetItemText?

Post by Sergey Tkachenko » Mon Nov 13, 2017 6:07 am

Items are not lines. One text item can occupy multiple lines. One line can contain multiple items.
Probably, you mean not lines but paragraphs, i.e. text between "Enters".
There are also paragraph sections, i.e. text between "Enters" or "Shift+Enters".

In this case, to get text of a paragraph (or a paragraph section), you need to get text from all items in it.

If you want text for the current paragraph or paragraph section, you can use the functions from RVGetTextW unit (or, if you need ANSI versions of these functions, RVGetText unit):

Code: Select all

function GetCurrentParaSectionText(rve: TCustomRichViewEdit): TRVAnsiString;
function GetCurrentParaText(rve: TCustomRichViewEdit): TRVAnsiString;
If you need a function returning text for a paragraph (or a paragraph section) containing the item having the specified index, let me know, I'll write it here.

CrimsonKing
Posts: 7
Joined: Wed Nov 01, 2017 11:13 am

Re: GetItemText?

Post by CrimsonKing » Mon Nov 13, 2017 8:21 am

Thanks to your kindly answer.

I try to use GetCurrentPara(Section)Text in RxGetText unit, but there's no ParaText function for using specified ItemNo.
I need to get Para(Section)Text for using specified ItemNo.

function example...
function GetPara(Section)Text(rve: TCustomRichViewEdit; ItemNo: Integer): string;

using example...
S := GetPara(Section)Text(rve, 15);

Sergey Tkachenko
Site Admin
Posts: 14228
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: GetItemText?

Post by Sergey Tkachenko » Mon Nov 13, 2017 9:03 am

Code: Select all

function GetItemText(rve: TCustomRichView; ItemNo: Integer): String;
begin
  if rve.GetItemStyle(ItemNo) >= 0 then
    Result := rve.GetItemText(ItemNo)
  else if rve.GetItemStyle(ItemNo) = rvsTab then
    Result := #9
  else
    Result := '';
end;

function GetParaText(rve: TCustomRichView; ItemNo: Integer): String;
var
  i, No1, No2: Integer;
begin
  Result := '';
  rve.RVData.ExpandToPara(ItemNo, ItemNo, No1, No2);
  for i := No1 to No2 do
  begin
    if (i > No1) and rve.IsFromNewLine(i) then
      Result := Result + #13#10;
    Result := Result + GetItemText(rve, i);
  end;
end;

function GetParaSectionText(rve: TCustomRichView; ItemNo: Integer): String;
var
  i, No1, No2: Integer;
begin
  Result := '';
  rve.RVData.ExpandToParaSection(ItemNo, ItemNo, No1, No2);
  for i := No1 to No2 do
    Result := Result + GetItemText(rve, i);
end;
Note that these functions return text only for text items and tabulators. They do not include a text representation of non-text item.

CrimsonKing
Posts: 7
Joined: Wed Nov 01, 2017 11:13 am

Re: GetItemText?

Post by CrimsonKing » Mon Nov 13, 2017 10:43 am

Thx a lot, I solved it! :)

Post Reply