Page 1 of 1

How to get the text of first line

Posted: Sun Dec 24, 2006 1:11 am
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 ?

Posted: Sun Dec 24, 2006 7:18 am
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);

Thanks for help

Posted: Mon Dec 25, 2006 2:08 am
by edwardloh717
but it always return the empty string, is there anything I miss ?

Posted: Mon Dec 25, 2006 5:31 pm
by Sergey Tkachenko
You are right, sorry.
I fixed it.