Number of actual lines

General TRichView support forum. Please post your questions here
jwinkl
Posts: 25
Joined: Thu Nov 09, 2006 10:09 am

Number of actual lines

Post by jwinkl »

A long text, added with AddNL to a table cell of a TRichview component, is wrapped into several lines. Now I would like to know if there is a way for the program to find out the number of these lines.
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Code: Select all

LineCount := rv.GetLineNo(rv.ItemCount-1, rv.GetOffsAfterItem(rv.ItemCount-1))
jwinkl
Posts: 25
Joined: Thu Nov 09, 2006 10:09 am

Post by jwinkl »

Thanks, that works, but doesn't help very much.

My problem is: I want to write text of variable length into the cells; if it wraps into too many lines, it should be cut after the last line, and the rest of the text should be written into the next cell. Only at run time and after formatting the actual number of lines in the cells is known.

Any idea how to achieve this?

Best wishes for 2012

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

Post by Sergey Tkachenko »

Text flow from one cell to another is not supported. If you want a smooth editing of this kind, it's not possible.
But if you need to modify an existed document after formatting it, by moving extra lines to another cell, it's possible.
jwinkl
Posts: 25
Joined: Thu Nov 09, 2006 10:09 am

Post by jwinkl »

Thanks, that would help of course, if you would only tell me how. I would need to have access to the single lines as they are formatted, not as the items that have been entered into the cell originally. Then I could transfer the superfluous lines from one cell to the next. I would be obliged for a more detailed explanation.

Best regards, Johann
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

It requires undocumented properties (DrawItems).

The code below assumes that the first item in RichViewEdit1 is a table, and this table has at least 2 columns. It moves the content of the first cell, starting from the third line, to the second cell.
This code uses editing methods (DeleteSelection and InsertRVFFromStreamEd), so it requires TRichViewEdit. If you need to implement this function without editing methods, let me know.

Code: Select all

var table: TRVTableItemInfo;
    RVData1, RVData2: TCustomRVFormattedData;
    i, LineCount, FirstDItemNo, FirstItemNo, Offs: Integer;
    Stream: TMemoryStream;
const MAXLINECOUNT = 2;
begin
   table := (RichViewEdit1.GetItem(0) as TRVTableItemInfo);
   RVData1 := TRVTableCellData(table.Cells[0,0].GetRVData);
   LineCount := 0;
   FirstDItemNo := -1;
   for i := 0 to RVData1.DrawItems.Count-1 do
     if RVData1.DrawItems[i].FromNewLine then begin
       inc(LineCount);
       if LineCount>MAXLINECOUNT then begin
         FirstDItemNo := i;
         break;
       end;
     end;
   if FirstDItemNo<0 then
     exit;
   RVData1 := TCustomRVFormattedData(RVData1.Edit);
   RVData1.DrawItem2Item(FirstDItemNo, RVData1.GetOffsBeforeDrawItem(FirstDItemNo),
     FirstItemNo, Offs);
   RVData1.SetSelectionBounds(FirstItemNo, Offs,
     RVData1.ItemCount-1, RVData1.GetOffsAfterItem(RVData1.ItemCount-1));
   Stream := TMemoryStream.Create;
   RichViewEdit1.SaveRVFToStream(Stream, True);
   RichViewEdit1.DeleteSelection;
   Stream.Position := 0;
   RVData2 := TCustomRVFormattedData(table.Cells[0,1].Edit);
   RVData2.SetSelectionBounds(0, RVData2.GetOffsBeforeItem(0),
     0, RVData2.GetOffsBeforeItem(0));
   RichViewEdit1.InsertRVFFromStreamEd(Stream);
   Stream.Free;
end;
jwinkl
Posts: 25
Joined: Thu Nov 09, 2006 10:09 am

Post by jwinkl »

Thanks a lot for the prompt and lengthy reply; I'll try it out next year ;)

RichViewEdit should be no problem, though I don't need the editing functions myself, but certainly I can make the RichviewEdit ReadOnly.
jwinkl
Posts: 25
Joined: Thu Nov 09, 2006 10:09 am

Post by jwinkl »

Hi Sergey,

I've tried it and it works fine, except that if you make the width of the cells so that the second line just fits and there is no empty space at its end, the first word of the third line will remain in the third line of the left cell. It seems that the routine works only if there ist enough room in line 2 for the following space.

Best wishes for the new year

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

Post by Sergey Tkachenko »

Sorry, I do not completely understand. Can you send screenshots?
Happy New Year!
jwinkl
Posts: 25
Joined: Thu Nov 09, 2006 10:09 am

Post by jwinkl »

Sorry if I didn't make myself clear. Unfortunately I have no idea how to send pictures to the forum.
jwinkl
Posts: 25
Joined: Thu Nov 09, 2006 10:09 am

Post by jwinkl »

OK, I think I've found a way. So look:

Before:

Image

After:

Image

Best regards

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

Post by Sergey Tkachenko »

It happens because of the columns widths.
If widths of columns are undefined (Cell.BestWidth=0 for all cells in the column), empty columns are narrower a bit than columns having text.

I suggest to assign equal nonzero values to Cell[0,0].BestWidth and Cell[0,1].BestWidth.
jwinkl
Posts: 25
Joined: Thu Nov 09, 2006 10:09 am

Post by jwinkl »

I've assigned value 408 both to Cell[0,0].BestWidth and Cell[0,1].BestWidth, which makes the second line just fit as shown in the picture. Nevertheless, the result is the same as before, so this can't be the reason. The problem also occurs with values 409 and 410; there is no problem with 411.

Your routine for drawing the lines seems to deal with the last line of the text differently than with lines within the text. As I have observed a similar behaviour with other applications - e. g. my webmail editor - this may well be due to a bug in a third party component you are using.

Best regards

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

Post by Sergey Tkachenko »

Please send me a sample project.
jwinkl
Posts: 25
Joined: Thu Nov 09, 2006 10:09 am

Post by jwinkl »

Here it is:

http://www.bggmuend.ac.at/jw/Test.zip

It is a Delphi 7 project, and I've sent an executable along.
Post Reply