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
11.3k Views 2 users read 2 min
support

Hi,

FastAddTable will add to the current table. So if you use TayblleAdd to create a table first that will be extended.

But see the code in WPCtrRich.pas:
TWPCustomRichText.FastAddTable

the line
wptable := ActiveText.CreateTable(nil);

can be changed into

wptable := ActiveParagraph.CreateTable(nil);

that will create the table after the current paragraph.

Julian

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