Formatting & Justifying Text in Table Cell

General TRichView support forum. Please post your questions here
Post Reply
JLuckey
Posts: 12
Joined: Thu Feb 23, 2006 12:22 am

Formatting & Justifying Text in Table Cell

Post 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]
Sergey Tkachenko
Site Admin
Posts: 17534
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post 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.
JLuckey
Posts: 12
Joined: Thu Feb 23, 2006 12:22 am

Post by JLuckey »

Sergey,

Thanks for the insight. It works perfectly!
Post Reply