Add text with different formats in a cell

General TRichView support forum. Please post your questions here
leandersantosm
Posts: 20
Joined: Fri Jun 03, 2011 8:33 pm

Add text with different formats in a cell

Post by leandersantosm »

Hello!
I would like to know if there is possible to add the follow line into a cell:

Bold Italic

Explanation: I need to write a text with two different styles of formatation in the same line, inside a table cell.

How can I do that?
Thanks.
Sergey Tkachenko
Site Admin
Posts: 17522
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Yes, of course it's possible.

I can create a sample code, but I need more info.
Do you want to create a new document with such table? Or do you want to modify an existing document? If modifying, should it be an editing operation (that the user can undo)?
leandersantosm
Posts: 20
Joined: Fri Jun 03, 2011 8:33 pm

Post by leandersantosm »

Hello Sergey, thanks for help.

I'm trying to use the edit method to modify the content of a table cell.
Using some of examples, I did what I want to.

In my project, I'm using this code:

Code: Select all

         TABLEECOCAR := TRVTableItemInfo.CreateEx(5,6,TLRESULTADOS.DBSRichViewEdit1.RichViewEdit.RVData);
         TABLEECOCAR.BorderWidth     := 0;
         TABLEECOCAR.CellBorderWidth := 0;
         FOR L := 0 TO TABLEECOCAR.RowCount-1 DO
         BEGIN
            FOR C:= 0 TO TABLEECOCAR.ColCount-1 DO
            BEGIN
               TABLEECOCAR.Cells[L,C].Clear;
               TABLEECOCAR.Cells[L,C].Color:=$00DFDFDF;
               TABLEECOCAR.Cells[L,C].VAlign:=rvcMiddle;
            END;
         END;
         {TABLEECOCAR.MergeCells(0,0,6,1,TRUE);
         TABLEECOCAR.MergeCells(1,0,6,1,TRUE);
         TABLEECOCAR.MergeCells(2,0,2,1,TRUE);
         TABLEECOCAR.MergeCells(2,3,2,1,TRUE);
         TABLEECOCAR.MergeCells(2,5,2,1,TRUE);
         TABLEECOCAR.MergeCells(6,3,3,1,TRUE);
         TABLEECOCAR.Cells[0,0].AddNL('Mensuração',6,0);}

         {if (wpeso.Value <> 0) or (WALTURA.Value<>0) then
         begin
            TABLEECOCAR.Cells[1,0].AddNL('Peso: '+ WPESO.Text +' Kgs.'+
                                      '                  Altura: '+WALTURA.Text+ 'm.'  ,0,0); 
         end;}
         TABLEECOCAR.Cells[0,0].AddNL('Mensuração',6,0);
         TABLEECOCAR.Cells[0,2].AddNL('Valores ref.',6,1);
         TABLEECOCAR.Cells[0,5].AddNL('Valores ref.',6,1);

         if (WATRIAOR.Value <> 0) then
         begin
            TABLEECOCAR.Cells[1,0].AddNL('Aorta',6,0);
            TABLEECOCAR.Cells[1,1].AddNL(WATRIAOR.Text+'mm',0,1);
         end;

         if (WATRIESQ.Value<>0)then
         begin
            TABLEECOCAR.Cells[2,0].AddNL('Átrio esquerdo',6,0);
            TABLEECOCAR.Cells[2,1].AddNL(WATRIESQ.Text +'mm' ,0,1);
         end;

         if (WVENTDIR.Value<>0)then
         begin
            TABLEECOCAR.Cells[3,0].AddNL('V.D.',6,0);
            TABLEECOCAR.Cells[3,1].AddNL(WVENTDIR.Text +'mm',0,1);
         end;

         if (WVENTESQDI.Value <> 0 ) then
         begin
            TABLEECOCAR.Cells[4,0].AddNL('V.E.(Diástole)',6,0);
            TABLEECOCAR.Cells[4,1].AddNL(WVENTESQDI.Text +'mm' ,0,1);
         end;

         if (WATRIAOR.Value <> 0) then
         begin
            TABLEECOCAR.Cells[1,2].AddNL(REFAO.Caption,6,1);
         end;

         if (WATRIESQ.Value<>0)then
         begin
            TABLEECOCAR.Cells[2,2].AddNL(REFAE.Caption,6,1);
         end;

         if (WVENTDIR.Value<>0)then
         begin
            TABLEECOCAR.Cells[3,2].AddNL(REFVD.Caption,6,1);
         end;
         
         if (WVENTESQDI.Value <> 0 ) then
         begin
            TABLEECOCAR.Cells[4,2].AddNL(REFVED.Caption,6,1);
         end;

         if (WVENTESQSI.Value <> 0 ) then
         begin
            TABLEECOCAR.Cells[1,3].AddNL('V.E.(Sístole)',6,0);
            TABLEECOCAR.Cells[1,4].AddNL(WVENTESQSI.Text +'mm',0,1);
         end;

         if WSEPTO.Value <> 0 then
         begin
            TABLEECOCAR.Cells[2,3].AddNL('Septo',6,0);
            TABLEECOCAR.Cells[2,4].AddNL(WSEPTO.Text +'mm' ,0,1);
         end;

         if (WPPVENTESQ.Value <> 0) then
         begin
            TABLEECOCAR.Cells[3,3].AddNL('Par. post. V.E.',6,0);
            TABLEECOCAR.Cells[3,4].AddNL(WPPVENTESQ.Text +'mm' ,0,1);
         end;

         if WSEPTO.Value <> 0 then
         begin
            TABLEECOCAR.Cells[2,5].AddNL(REFSEPTO.Caption,6,1);
         end;

         if (WPPVENTESQ.Value <> 0) then
         begin
            TABLEECOCAR.Cells[3,5].AddNL(REFPPVE.Caption,6,1);
         end;

         TABLEECOCAR.BestWidth := -90;
         DBSRichViewEdit1.RichViewEdit.InsertItem('',TABLEECOCAR);
         DBSRichViewEdit1.RichViewEdit.InsertBreak(0,rvbsLine,clWindowText);
Ok, it works fine, the table is created, but when I move the mouse over the table border, I get an error: List index out of bounds (-60)

This error showns up only on table border, not happens in cell borders.
Why is this happening?[/b]
Sergey Tkachenko
Site Admin
Posts: 17522
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Is it possible to reproduce this problem in a simple project (preferably using TRichViewEdit instead of TDBRichViewEdit) and send it to me?
leandersantosm
Posts: 20
Joined: Fri Jun 03, 2011 8:33 pm

Post by leandersantosm »

This is the problem, everything works fine when used in a new project, with the same codes.

This code is executed by a form called from main form.

Any ideia of how can I reproduce this error?
Sergey Tkachenko
Site Admin
Posts: 17522
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Your code looks correct, so I think the error is somewhere in another place.
leandersantosm
Posts: 20
Joined: Fri Jun 03, 2011 8:33 pm

Post by leandersantosm »

I don't know if this can help, but I use the same code on same button to create another 2 tables, and this error does not happens with that tables, just the first one.

The code used to create the first table is a copy of the second table, just like the same.

Other things that can help to discover the error:
- RVStyle is on FPrincipal form;
- DBSRichView is on TLRESULTADOS form;
- Code that creates the table on DBSRichView is on TLUSECOCAR form;

Any suggestion?
Need more details?
Sergey Tkachenko
Site Admin
Posts: 17522
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

How do you create a copy of a table?
leandersantosm
Posts: 20
Joined: Fri Jun 03, 2011 8:33 pm

Post by leandersantosm »

Copy of the code ** I mean

I just copied the code that creates the second table, to create the first (the table that shows up the error when I move the mouse over the border).

The codes are perfectly the same, but just the first table shows the error.
Sergey Tkachenko
Site Admin
Posts: 17522
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

May be you insert the same table object twice?
leandersantosm
Posts: 20
Joined: Fri Jun 03, 2011 8:33 pm

Post by leandersantosm »

No, the only difference between the codes is the variable name.

First's table name is TABLEECOCAR, second's TBAUX.
Sergey Tkachenko
Site Admin
Posts: 17522
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Please post code for creation and insertion of the both tables.
leandersantosm
Posts: 20
Joined: Fri Jun 03, 2011 8:33 pm

Post by leandersantosm »

First table:

Code: Select all

TBAUX := TRVTableItemInfo.CreateEx(5,6,TLRESULTADOS.DBSRichViewEdit1.RichViewEdit.RVData);
         //TBAUX.BorderColor     := $00A98E10;
         //TBAUX.CellBorderColor := $00A98E10;
         TBAUX.BorderWidth     := 0;
         TBAUX.CellBorderWidth := 0;
         {TBAUX.Cells[2,2].BestWidth := 130;
         TBAUX.Cells[2,5].BestWidth := 130;
         TBAUX.Cells[3,0].BestWidth := 90;
         TBAUX.Cells[3,1].BestWidth := 70;
         TBAUX.Cells[3,3].BestWidth := 150;
         TBAUX.Cells[3,4].BestWidth := 70;
         TBAUX.Cells[3,5].BestWidth := 130;}
         FOR L := 0 TO TBAUX.RowCount-1 DO
         BEGIN
            FOR C:= 0 TO TBAUX.ColCount-1 DO
            BEGIN
               TBAUX.Cells[L,C].Clear;
               TBAUX.Cells[L,C].Color:=$00DFDFDF;
               TBAUX.Cells[L,C].VAlign:=rvcMiddle;
            END;
         END;
         {TBAUX.MergeCells(0,0,6,1,TRUE);
         TBAUX.MergeCells(1,0,6,1,TRUE);
         TBAUX.MergeCells(2,0,2,1,TRUE);
         TBAUX.MergeCells(2,3,2,1,TRUE);
         TBAUX.MergeCells(2,5,2,1,TRUE);
         TBAUX.MergeCells(6,3,3,1,TRUE);
         TBAUX.Cells[0,0].AddNL('Mensuração',6,0);}

         {if (wpeso.Value <> 0) or (WALTURA.Value<>0) then
         begin
            TBAUX.Cells[1,0].AddNL('Peso: '+ WPESO.Text +' Kgs.'+
                                      '                  Altura: '+WALTURA.Text+ 'm.'  ,0,0); 
         end;}
         TBAUX.Cells[0,0].AddNL('Mensuração',6,0);
         TBAUX.Cells[0,2].AddNL('Valores ref.',6,1);
         TBAUX.Cells[0,5].AddNL('Valores ref.',6,1);

         if (WATRIAOR.Value <> 0) then
         begin
            TBAUX.Cells[1,0].AddNL('Aorta',6,0);
            TBAUX.Cells[1,1].AddNL(WATRIAOR.Text+'mm',0,1);
         end;

         if (WATRIESQ.Value<>0)then
         begin
            TBAUX.Cells[2,0].AddNL('Átrio esquerdo',6,0);
            TBAUX.Cells[2,1].AddNL(WATRIESQ.Text +'mm' ,0,1);
         end;

         if (WVENTDIR.Value<>0)then
         begin
            TBAUX.Cells[3,0].AddNL('V.D.',6,0);
            TBAUX.Cells[3,1].AddNL(WVENTDIR.Text +'mm',0,1);
         end;

         if (WVENTESQDI.Value <> 0 ) then
         begin
            TBAUX.Cells[4,0].AddNL('V.E.(Diástole)',6,0);
            TBAUX.Cells[4,1].AddNL(WVENTESQDI.Text +'mm' ,0,1);
         end;

         if (WATRIAOR.Value <> 0) then
         begin
            TBAUX.Cells[1,2].AddNL(REFAO.Caption,6,1);
         end;

         if (WATRIESQ.Value<>0)then
         begin
            TBAUX.Cells[2,2].AddNL(REFAE.Caption,6,1);
         end;

         if (WVENTDIR.Value<>0)then
         begin
            TBAUX.Cells[3,2].AddNL(REFVD.Caption,6,1);
         end;
         
         if (WVENTESQDI.Value <> 0 ) then
         begin
            TBAUX.Cells[4,2].AddNL(REFVED.Caption,6,1);
         end;

         if (WVENTESQSI.Value <> 0 ) then
         begin
            TBAUX.Cells[1,3].AddNL('V.E.(Sístole)',6,0);
            TBAUX.Cells[1,4].AddNL(WVENTESQSI.Text +'mm',0,1);
         end;

         if WSEPTO.Value <> 0 then
         begin
            TBAUX.Cells[2,3].AddNL('Septo',6,0);
            TBAUX.Cells[2,4].AddNL(WSEPTO.Text +'mm' ,0,1);
         end;

         if (WPPVENTESQ.Value <> 0) then
         begin
            TBAUX.Cells[3,3].AddNL('Par. post. V.E.',6,0);
            TBAUX.Cells[3,4].AddNL(WPPVENTESQ.Text +'mm' ,0,1);
         end;

         if WSEPTO.Value <> 0 then
         begin
            TBAUX.Cells[2,5].AddNL(REFSEPTO.Caption,6,1);
         end;

         if (WPPVENTESQ.Value <> 0) then
         begin
            TBAUX.Cells[3,5].AddNL(REFPPVE.Caption,6,1);
         end;

         TBAUX.BestWidth := -90;
         DBSRichViewEdit1.RichViewEdit.InsertItem('',TBAUX);
         DBSRichViewEdit1.RichViewEdit.InsertBreak(0,rvbsLine,clWindowText);
Second table:

Code: Select all

TABLEECOCAR := TRVTableItemInfo.CreateEx(5,6,TLRESULTADOS.DBSRichViewEdit1.RichViewEdit.RVData);
         //TABLEECOCAR.BorderColor     := $00A98E10;
         //TABLEECOCAR.CellBorderColor := $00A98E10;
         TABLEECOCAR.BorderWidth     := 0;
         TABLEECOCAR.CellBorderWidth := 0;
         {TABLEECOCAR.Cells[2,2].BestWidth := 130;
         TABLEECOCAR.Cells[2,5].BestWidth := 130;
         TABLEECOCAR.Cells[3,0].BestWidth := 90;
         TABLEECOCAR.Cells[3,1].BestWidth := 70;
         TABLEECOCAR.Cells[3,3].BestWidth := 150;
         TABLEECOCAR.Cells[3,4].BestWidth := 70;
         TABLEECOCAR.Cells[3,5].BestWidth := 130;}
         FOR L := 0 TO TABLEECOCAR.RowCount-1 DO
         BEGIN
            FOR C:= 0 TO TABLEECOCAR.ColCount-1 DO
            BEGIN
               TABLEECOCAR.Cells[L,C].Clear;
               TABLEECOCAR.Cells[L,C].Color:=$00DFDFDF;
               TABLEECOCAR.Cells[L,C].VAlign:=rvcMiddle;
            END;
         END;
         {TABLEECOCAR.MergeCells(0,0,6,1,TRUE);
         TABLEECOCAR.MergeCells(1,0,6,1,TRUE);
         TABLEECOCAR.MergeCells(2,0,2,1,TRUE);
         TABLEECOCAR.MergeCells(2,3,2,1,TRUE);
         TABLEECOCAR.MergeCells(2,5,2,1,TRUE);
         TABLEECOCAR.MergeCells(6,3,3,1,TRUE);
         TABLEECOCAR.Cells[0,0].AddNL('Mensuração',6,0);}

         {if (wpeso.Value <> 0) or (WALTURA.Value<>0) then
         begin
            TABLEECOCAR.Cells[1,0].AddNL('Peso: '+ WPESO.Text +' Kgs.'+
                                      '                  Altura: '+WALTURA.Text+ 'm.'  ,0,0); 
         end;}
         TABLEECOCAR.Cells[0,0].AddNL('Mensuração',6,0);
         TABLEECOCAR.Cells[0,2].AddNL('Valores ref.',6,1);
         TABLEECOCAR.Cells[0,5].AddNL('Valores ref.',6,1);

         if (WATRIAOR.Value <> 0) then
         begin
            TABLEECOCAR.Cells[1,0].AddNL('Aorta',6,0);
            TABLEECOCAR.Cells[1,1].AddNL(WATRIAOR.Text+'mm',0,1);
         end;

         if (WATRIESQ.Value<>0)then
         begin
            TABLEECOCAR.Cells[2,0].AddNL('Átrio esquerdo',6,0);
            TABLEECOCAR.Cells[2,1].AddNL(WATRIESQ.Text +'mm' ,0,1);
         end;

         if (WVENTDIR.Value<>0)then
         begin
            TABLEECOCAR.Cells[3,0].AddNL('V.D.',6,0);
            TABLEECOCAR.Cells[3,1].AddNL(WVENTDIR.Text +'mm',0,1);
         end;

         if (WVENTESQDI.Value <> 0 ) then
         begin
            TABLEECOCAR.Cells[4,0].AddNL('V.E.(Diástole)',6,0);
            TABLEECOCAR.Cells[4,1].AddNL(WVENTESQDI.Text +'mm' ,0,1);
         end;

         if (WATRIAOR.Value <> 0) then
         begin
            TABLEECOCAR.Cells[1,2].AddNL(REFAO.Caption,6,1);
         end;

         if (WATRIESQ.Value<>0)then
         begin
            TABLEECOCAR.Cells[2,2].AddNL(REFAE.Caption,6,1);
         end;

         if (WVENTDIR.Value<>0)then
         begin
            TABLEECOCAR.Cells[3,2].AddNL(REFVD.Caption,6,1);
         end;
         
         if (WVENTESQDI.Value <> 0 ) then
         begin
            TABLEECOCAR.Cells[4,2].AddNL(REFVED.Caption,6,1);
         end;

         if (WVENTESQSI.Value <> 0 ) then
         begin
            TABLEECOCAR.Cells[1,3].AddNL('V.E.(Sístole)',6,0);
            TABLEECOCAR.Cells[1,4].AddNL(WVENTESQSI.Text +'mm',0,1);
         end;

         if WSEPTO.Value <> 0 then
         begin
            TABLEECOCAR.Cells[2,3].AddNL('Septo',6,0);
            TABLEECOCAR.Cells[2,4].AddNL(WSEPTO.Text +'mm' ,0,1);
         end;

         if (WPPVENTESQ.Value <> 0) then
         begin
            TABLEECOCAR.Cells[3,3].AddNL('Par. post. V.E.',6,0);
            TABLEECOCAR.Cells[3,4].AddNL(WPPVENTESQ.Text +'mm' ,0,1);
         end;

         if WSEPTO.Value <> 0 then
         begin
            TABLEECOCAR.Cells[2,5].AddNL(REFSEPTO.Caption,6,1);
         end;

         if (WPPVENTESQ.Value <> 0) then
         begin
            TABLEECOCAR.Cells[3,5].AddNL(REFPPVE.Caption,6,1);
         end;

         TABLEECOCAR.BestWidth := -90;
         DBSRichViewEdit1.RichViewEdit.InsertItem('',TABLEECOCAR);
         DBSRichViewEdit1.RichViewEdit.InsertBreak(0,rvbsLine,clWindowText);
Sergey, is that a good idea to access my computer using Teamviwer (remote access)?
You can see by yourself the error.
Sergey Tkachenko
Site Admin
Posts: 17522
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

I do not have a teamviewer...

What happens if you do not create a second table?
If you create them in a different order?
leandersantosm
Posts: 20
Joined: Fri Jun 03, 2011 8:33 pm

Post by leandersantosm »

The error disappeared.

But when I try to leave the form that contains the RichView, a new error occurs "List index out of bounds (1)"

This error points me to the file Classes, line 2790:

raise EListError.CreateFmt(Msg, [Data]) at ReturnAddr;
Post Reply