Page 1 of 2
Number of actual lines
Posted: Sun Dec 25, 2011 11:02 am
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.
Posted: Sun Dec 25, 2011 4:06 pm
by Sergey Tkachenko
Code: Select all
LineCount := rv.GetLineNo(rv.ItemCount-1, rv.GetOffsAfterItem(rv.ItemCount-1))
Posted: Fri Dec 30, 2011 3:24 pm
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
Posted: Sat Dec 31, 2011 6:59 am
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.
Posted: Sat Dec 31, 2011 7:52 am
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
Posted: Sat Dec 31, 2011 10:11 am
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;
Posted: Sat Dec 31, 2011 1:41 pm
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.
Posted: Sun Jan 01, 2012 9:43 am
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
Posted: Mon Jan 02, 2012 1:51 pm
by Sergey Tkachenko
Sorry, I do not completely understand. Can you send screenshots?
Happy New Year!
Posted: Tue Jan 03, 2012 10:27 am
by jwinkl
Sorry if I didn't make myself clear. Unfortunately I have no idea how to send pictures to the forum.
Posted: Tue Jan 03, 2012 11:24 am
by jwinkl
OK, I think I've found a way. So look:
Before:
After:
Best regards
Johann
Posted: Tue Jan 03, 2012 3:50 pm
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.
Posted: Wed Jan 04, 2012 7:38 am
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
Posted: Wed Jan 04, 2012 8:23 am
by Sergey Tkachenko
Please send me a sample project.
Posted: Wed Jan 04, 2012 12:45 pm
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.