programmatically adding subscripted string

General TRichView support forum. Please post your questions here
Post Reply
krctech
Posts: 7
Joined: Tue Jun 03, 2008 4:57 am
Location: San Diego, CA US

programmatically adding subscripted string

Post by krctech » Tue Jun 13, 2017 6:34 am

I want to be able to programmatically add text like H2O where the 2 is subscript. I'm trying to do this with

t.Cells[r, c].AddNLWTag('H'+#$2082+'O', NORMAL, RIGHT, '');

Except I simply see a box where the subscript "2" should be. What am I doing wrong?

Sergey Tkachenko
Site Admin
Posts: 13467
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: programmatically adding subscripted string

Post by Sergey Tkachenko » Tue Jun 13, 2017 6:24 pm

The second parameter of AddNLWTag is the index of RVStyle.TextStyles collection.
Pass the index of item having SubSuperScriptType = rvsssSubScript

See also:
viewtopic.php?f=2&t=8537&p=32795
This topic contains examples how to create text styles with required properties, including sub/superscript.

krctech
Posts: 7
Joined: Tue Jun 03, 2008 4:57 am
Location: San Diego, CA US

Re: programmatically adding subscripted string

Post by krctech » Tue Jun 13, 2017 10:28 pm

Thanks Sergey, that helps. However, I need to be able to add three bits of text into a table cell. The actual string is something like this

'Pressure, in-H2O (a)'

Therefore, I need to add three successive strings:

leftStr := 'Pressure, in-H';
subScriptStr := '2';
rightStr := 'O (a)';

I am able to get add strings in the table cell, but each adds to its own line. I need them on the same line.

Mike

Sergey Tkachenko
Site Admin
Posts: 13467
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: programmatically adding subscripted string

Post by Sergey Tkachenko » Wed Jun 14, 2017 8:30 am

The second and the third string in the line must be added with -1 in ParaNo parameter of AddNLWtag.

PS: before adding content to a cell, clear it: Cell.Clear.

krctech
Posts: 7
Joined: Tue Jun 03, 2008 4:57 am
Location: San Diego, CA US

Re: programmatically adding subscripted string

Post by krctech » Wed Jun 14, 2017 3:20 pm

perfect - thanks Sergey!

Post Reply