Number of actual lines
Number of actual lines
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.
-
- Site Admin
- Posts: 17559
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Code: Select all
LineCount := rv.GetLineNo(rv.ItemCount-1, rv.GetOffsAfterItem(rv.ItemCount-1))
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
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
-
- Site Admin
- Posts: 17559
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
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
Best regards, Johann
-
- Site Admin
- Posts: 17559
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
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.
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;
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
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
-
- Site Admin
- Posts: 17559
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
-
- Site Admin
- Posts: 17559
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
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
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
-
- Site Admin
- Posts: 17559
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Here it is:
http://www.bggmuend.ac.at/jw/Test.zip
It is a Delphi 7 project, and I've sent an executable along.
http://www.bggmuend.ac.at/jw/Test.zip
It is a Delphi 7 project, and I've sent an executable along.