WPCubed Product Support

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;

#1 ♥ 0
3.3k Views 2 users read 3 min
support

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.

procedure TWPCustomRichText.FastAddTable(col: Integer; Pprp: PTParProps);
var wptable: TParagraph;
  wprowstyle: TWPTableRowStyle;
  cell: TParagraph;
  i: Integer;
begin
  if col <= 0 then exit;
  cell := nil;
  wptable := Table;
  if (wptable = nil) or FBeginTable and FBeginTableCreate then
  begin
    CheckActiveText;
    wptable := ActiveText.CreateTable(nil);
    FBeginTableCreate := FALSE;
    wptable.Name := FBeginTableName;
  end;
  wprowstyle := wptable.CreateRow(nil, true);
  try
    for i := 0 to col - 1 do
    begin
      cell := wprowstyle.InputCell;
      if Pprp <> nil then
      begin
        FastApplyPProp(cell, Pprp^);
        if Pprp.Width_PC <> 0 then
          cell.ASet(WPAT_COLWIDTH_PC, Pprp.Width_PC)
        else if Pprp.Width_TW <> 0 then
          cell.ASet(WPAT_COLWIDTH, Pprp.Width_TW)
        else if Pprp.CWidth <> 0 then
          cell.ASet(WPAT_COLWIDTH_PC, MulDiv(Pprp.CWidth, 10000, 255))
        else cell.ASet(WPAT_COLWIDTH_PC, 10000 div col);
        FastSetText(cell, Pprp^);
        inc(Pprp);
      end;
    end;
    Memo.Cursor.MoveTo(cell, 0);
  finally
    wptable.EndRow(wprowstyle);
  end;
end;

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

#2 ♥ 0
This category is archived. No new posts are possible.