Page 1 of 1

Ask how to use OnDrawBorder of tables

Posted: Thu Aug 03, 2006 2:10 am
by zhongdee
I write code,but it doesn't work,delphi doesn't execute doDrawBorder.


//Create the table

procedure TForm1.mitInserttable1Click(Sender: TObject);
var table: TRVTableItemInfo;
r,c: Integer;
begin
table := TRVTableItemInfo.CreateEx(4,3, RichViewEdit1.RVData);

table.OnDrawBorder:=DoDrawBorder;

table.BorderStyle := rvtbRaisedColor;
table.CellBorderStyle := rvtbLoweredColor;
table.BorderLightColor := $00FAF1C9;
table.BorderColor := $00A98E10;
table.CellBorderLightColor := $00FAF1C9;
table.CellBorderColor := $00A98E10;
table.Color := $00EAC724;
table.BorderWidth := 5;
table.CellBorderWidth := 2;
table.CellPadding := 5;
table.CellVSpacing := 1;
table.CellHSpacing := 1;
table.BorderVSpacing := 1;
table.BorderHSpacing := 1;

for r := 0 to table.Rows.Count-1 do
for c := 0 to table.Rows[r].Count-1 do
table.Cells[r,c].BestWidth := 100;

table.MergeCells(0,0,3,1, False);
table.MergeCells(1,0,1,3, False);
with table.Cells[0,0] do begin
Color := clInfoBk;
Clear;
AddBulletEx( '',0,il,2);
AddNL(' Example 1 ',1,-1);
AddBulletEx( '',0,il,-1);
AddNL('All cells have 100 pixels width, width of table itself is calculated basing on width of cells.',0,0);
end;

if RichViewEdit1.InsertItem('', table) then begin
end;
end;


//draw border procedure

procedure TForm1.DoDrawBorder(Sender: TRVTableItemInfo;
Canvas: TCanvas; Left,Top,Right,Bottom, Width: Integer;
LightColor, Color, BackgroundColor: TColor;
Style: TRVTableBorderStyle; Printing: Boolean;
VisibleBorders: TRVBooleanRect; Row, Col: Integer;
var DoDefault: Boolean);
begin
if Width=0 then
exit;
inc(Right);
inc(Bottom);
Canvas.Pen.Color := Color;
Canvas.Pen.Style := psInsideFrame;
Canvas.Pen.Width := 1;
Canvas.Brush.Style := bsClear;
Canvas.Rectangle(Left,Top,Right,Bottom);
DoDefault := False;
end;

Posted: Fri Aug 04, 2006 3:54 pm
by Sergey Tkachenko
I added your code in the Editor1 demo, and it works as expected.

May be you mean that this event is not executed when the document is saved to RVF and reloaded?

Events are not stored in RVF files, you need to reassign them in OnItemAction event:

Code: Select all

procedure TForm1.RichViewEdit1ItemAction(Sender: TCustomRichView;
  ItemAction: TRVItemAction; Item: TCustomRVItemInfo; var Text: String;
  RVData: TCustomRVData);
begin
 if (ItemAction=rviaInserted) and (Item.StyleNo=rvsTable) then
   TRVTableItemInfo(Item).OnDrawBorder := DoDrawBorder;
end;

Posted: Thu Aug 17, 2006 2:31 am
by zhongdee
Thank you,Sergey Tkachenko.
I will test it again.