FastAddTable Behaviour

  • I have used FastAddTable (the pointer version) extensively throughout a suite of programs (hence I'd like to stick with this method) but as a result of the upgrade, the newly created tables appear at the end of the text rather than at the current position.

    Here's some of my code. Many thanks

    procedure TTemplateTable.CreateTable(rtf: TWPCustomRichText);
    begin
    with rtf do
    try
    Changing;
    TableName := GetNextTableName(rtf);
    BeginTable(TableName,0,0,0); //start out table
    CalculateTableSettings(rtf);
    InsertTableHeader(rtf); //create a header if needed
    InsertTableCell(rtf); //create a table cell
    EndTable; //end our table
    finally
    Refresh;//allow it to be drawn
    end;
    end;

    procedure TTemplateTable.CalculateTableSettings(rtf:TWPCustomRichText);
    var
    i : Integer;
    iCol : Integer;
    fWidth: double;
    begin
    attribs := rtf.Attr; //get attribs

    if CellMatrix then
    begin
    if ActualCellCount > 0 then
    begin
    FreeMem(prp); //before re-initialising it
    GetMem(prp, (ActualCellCount + 1) * SizeOf(TParProps));
    FillChar(prp^, (ActualCellCount + 1) * SizeOf(TParProps), 0);
    SetLength(CWidth,ActualCellCount+1);//don't forget the header
    CWidth[0] := Round(2.55 * (MaterialWidth * 1.0));
    iCol := (255-CWidth[0]) div ActualCellCount;
    for i := 1 to ActualCellCount do
    CWidth[i] := iCol;
    end;
    end
    else
    begin
    FreeMem(prp); //before re-initialising it
    GetMem(prp, TemplateColumns.Count * SizeOf(TParProps));
    FillChar(prp^, TemplateColumns.Count * SizeOf(TParProps), 0);
    SetLength(CWidth,TemplateColumns.Count);
    fWidth := 0;
    //total width is......
    for i := 0 to TemplateColumns.Count-1 do
    fWidth := fWidth + TemplateColumns[i].Width;

    for i := 0 to TemplateColumns.Count-1 do
    begin
    //and fill the array
    CWidth[i] := Round((TemplateColumns[i].Width / fWidth)*255);
    end;
    end;

    end;

    procedure TTemplateTable.InsertTableHeader(rtf: TWPCustomRichText);
    begin
    if not TemplateColumns.isHeaderVisible then
    Exit;
    FormatTableHeader(rtf);
    rtf.FastAddTable(TemplateColumns.Count,prp);
    end;

    procedure TTemplateTable.InsertTableCell(rtf: TWPCustomRichText);
    var
    tbl : TDataSet;
    i : Integer;
    pp : PTParProps;
    begin
    tbl := nil;
    if CellMatrix then
    FormatCellMatrix(rtf,tbl)
    else
    begin
    FormatTableCell(rtf,tbl);
    pp := prp;
    for i := 0 to TemplateColumns.Count-1 do
    begin
    pp^.ParProtected := True;
    Inc(pp);
    end;
    rtf.FastAddTable(TemplateColumns.Count,prp);
    end;

    rtf.ProtectedProp := rtf.ProtectedProp +
    [ppParProtected,ppProtected,ppProtectSelectedTextToo];
    end;

    • Offizieller Beitrag

    Hi,

    FastAddTable is really outdated. I cannot recomend to use it since it only provides a fraction of the possibilities of TableAdd for example.

    This is how this procedure is defined.

    So, to make sure the table is not append to the end (this is done by ActiveText.CreateTable(nil);)

    use this code:

    ActiveParagraph.ParagraphType := wpIsTable;

    this of course requires the current paragraph to be empty.

    InputString(#13+#13); CPMoveBack;
    would make sure this is the case. It depends a bit on the text you create.

    Julian