CreateTable with borders

  • I want to display a table within a TWPRichText component. Because the content for the table will come from a database table it would seem that CreateTable would be the most efficient method, using CreateRow with each loop through the data table.

    But I can't find an example showing how to add borders to the table or otherwise style the cells. TableAdd has such examples but this seems less efficient as the callback function must locate the required row in the database table with each call.

    Am I correct in choosing the CreateTable method. If so, can someone offer a simple example with borders and a styled cell?

    Thanks.

  • I was barking up the wrong tree. It seems that borders are not an attribute of a table as I expected. Rather they are attached to the table row.

    Here is an example of how I am applying borders to my table in case anyone want to recommend a better approach.

    with rteMain.Memo.DisplayedText.CreateTable(nil) do
    begin
    with CreateRow(nil, True) do
    begin
    ASet(WPAT_BorderFlags, WPBRD_DRAW_All4);
    ASet(WPAT_BorderWidth, 10);
    InputCell.SetText('Year');
    InputCell.SetText('Age');
    EndRow(ThisRowStyle);
    end;
    with CreateRow(nil, True) do
    begin
    ASet(WPAT_BorderFlags, WPBRD_DRAW_All4);
    ASet(WPAT_BorderWidth, 10);
    InputCell.SetText('2011');
    InputCell.SetText('39');
    EndRow(ThisRowStyle);
    end;
    end;
    rteMain.Refresh;

    • Offizieller Beitrag

    Actually TableAdd is very efficient since it uses the current cell adress for the callback - it does not have to a locate each cell.

    Code
    if assigned(CallBackForText) then CallBackForText(rownr, c, cell);

    Borders are properties of the cells, not the rows or tables.

    If you don't know the count of rows in advance You can use a large number and sel WPRichText.FAbortTableAdd := true when You know that the current row should be the last.

    Your code is fine. CreateRow(nil, True) returns a style which will be used for all cells.

    Julian