Page 1 of 1

Formatting & Justifying Text in Table Cell

Posted: Thu Aug 21, 2008 6:36 pm
by JLuckey
Sergey,

I need to write text to a table cell in a TRichView. Each word in the text may have special formatting like bold and or italic. Then I need to write the whole text to a table cell with either left, center, or right justification.

The code snippet below formats each word of the text OK, but I can't get the justification to do what I want.

If I change the third param of AddTextNL to something other than -1, I get the words on new lines. The fourth param doesn't seem have any effect on horizontal alignment.

Code: Select all

Procedure TPgraph.WriteToCell(rtfTableIn: TRVTableItemInfo; iCellRow, iCellCol: Integer);
Var
  i, iRTFStyleNum, KludgeVar: Integer;

begin
  rtfTableIn.Cells[iCellRow, iCellCol].Clear;
  For i := 0 to FTextList.Count - 1 Do Begin
    If TStyleAndText(FTextList[i]).text <> '' Then Begin
      iRTFStyleNum := GetTextStyle(SSVal, TStyleAndText(FTextList[i]).Style);
      rtfTableIn.Cells[iCellRow, iCellCol].AddTextNL(TStyleAndText(FTextList[i]).text, iRTFStyleNum, -1, 17);
    End;  {If}
  End;  {For}

  FTextList.Clear;

End;   {WriteToCell}
What is the best way to do what I need?

Thanks,[/code]

Posted: Fri Aug 22, 2008 5:40 am
by Sergey Tkachenko
The third parameter really defines the paragraph style. You should set it to the index of the paragraph style for the first text item added in the cell, and -1 for others (if you want them to continue the paragraph).

Specifying -1 for the first item in cell/document is a mistake (because the first item cannot continue paragraph), but it is automatically corrected by TRichView (the 0-th paragraph style is used).

As for the last parameter, it defines the paragraph style for the second and other paragraphs added by AddTextNL, if text contains line break characters.

Posted: Fri Aug 22, 2008 4:59 pm
by JLuckey
Sergey,

Thanks for the insight. It works perfectly!