How to get the text of first line

General TRichView support forum. Please post your questions here
Post Reply
edwardloh717
Posts: 3
Joined: Thu Dec 21, 2006 5:04 am

How to get the text of first line

Post by edwardloh717 »

I want to save file and use the first line text as the filename,How to get the text of first line like word does ?
Sergey Tkachenko
Site Admin
Posts: 17534
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Code: Select all

uses CRVData, RVTable;

function GetFirstLineText(RVData: TCustomRVData): String;
var i: Integer;
begin
  i := 0;
  if RVData.GetItemStyle(i)=rvsListMarker then
    inc(i);
  if RVData.GetItemStyle(i)=rvsTable then
    Result := GetFirstLineText(TRVTableItemInfo(RVData.GetItem(i)).Cells[0,0].GetRVData)
  else begin
    Result := '';
    while (i<RVData.ItemCount) and 
      ((i=0) or not RVData.IsFromNewLine(i)) and
      (RVData.GetItemStyle(i)>=0) do begin
      Result := Result + RVData.GetItemTextA(i);
      inc(i)
    end;
  end;
end;

// call
s := GetFirstLineText(RichViewEdit1.RVData);
Last edited by Sergey Tkachenko on Mon Dec 25, 2006 5:31 pm, edited 1 time in total.
edwardloh717
Posts: 3
Joined: Thu Dec 21, 2006 5:04 am

Thanks for help

Post by edwardloh717 »

but it always return the empty string, is there anything I miss ?
Sergey Tkachenko
Site Admin
Posts: 17534
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

You are right, sorry.
I fixed it.
Post Reply