How to insert data at runtime and format text into bold using RichEdit control

Discussion forum about all things Gupta, OpenText and the community.
Viswanadha
India
Posts: 23
Joined: 12 Jul 2018, 10:24
Location: Chennai, India

How to insert data at runtime and format text into bold using RichEdit control

Post by Viswanadha » 02 Aug 2019, 09:08

Hi All,

I have to create a control/use existing where some lines are Bold font and some are normal font. I have tried using RichEdit and Multiline controls where I can make either full text as Bold or normal. Below is the sample format

Employee:
Name
Emp No
Experience:
Company:
ABC
Technology
Centura, .Net, Sql

I got sample from our TD Samples where user need to select the text and change it to Bold but in my case I have to make it automatically bold employee, experience and Technology and rest all normal font.

I want to know how to insert text in RichEdit line by line in RichEdit and make the text bold without selecting word/text.

Any help is much appreciated.

Didiman
Germany
Posts: 330
Joined: 21 Mar 2017, 13:05
Location: Bremen, Germany

Re: How to insert data at runtime and format text into bold using RichEdit control

Post by Didiman » 05 Aug 2019, 10:23

So, there are two ways that i see for you:

1. You programmatically select the part of the Text you want to have formatted in Bold via SalRTFTextSelect() and then SalRTFTextSetStyle(). If you know the Positions of your Keywords, this should work for you.
2. You work with temporary Files, which you can create, manipulate (Search for your Keywords and make them Bold by adding a \b and \b0) and show back in your Control. This will work (and does it for us) with SalRTFDocumentSave() and SalRTFDocumentInsert()

Here is an example:

Code: Select all

Function: sGetData
			Description: Gibt den formatierten Inhalt des Controls als String zurück
			Returns
				Long String:
			Parameters
			Static Variables
			Local variables
				File Handle: hFileTemp
				Long String: lsData
				String: sFilename
				Boolean: bOk
				Number: nSizeOfFile
				String: _sPath
			Actions
				Set bOk = TRUE
				Set _sPath = _VisDosGetTempPath(  )
				!
				Set sFilename = _sPath || '\\' ||DateToStrX(SalDateCurrent(), DATE_Journal)|| SalNumberToStrX(SalNumberRandom(  ),0)|| '.rtf'
				!
				Call SalRTFDocumentSave( hWndItem, sFilename, 0 )
				!
				Set nSizeOfFile = VisFileGetSize( sFilename )
				!
				Set bOk = bOk AND (VisFileOpen( hFileTemp, sFilename, OF_Read ) = VTERR_Ok )
				!
				If bOk
					Call SalSetBufferLength( lsData, nSizeOfFile )
					Call VisFileRead( hFileTemp, lsData,nSizeOfFile  )
				!
				If hFileTemp
					Call VisFileClose( hFileTemp )
				!
				Call VisFileDelete( sFilename )
				!
				Return lsData

Code: Select all

		Function: bSetData
			Description: Setzt den Inhalt des RTF-Controls anhand des übergebenen Strings aus der Datenbank
			Returns
				Boolean:
			Parameters
				Long String: lsData
			Static Variables
			Local variables
				File Handle: hFileTemp
				String: sFilename
				Boolean: bOk
				Number: nSizeOfFile
				String: _sPath
			Actions
				Set bOk = TRUE
				!
				Set _sPath = _VisDosGetTempPath(  )
				!
				! Set sFilename = VisFileCreateTemp( 'RTF' )
				Set sFilename =_sPath || '\\' || DateToStrX(SalDateCurrent(), DATE_Journal)|| SalNumberToStrX(SalNumberRandom(  ),0)|| '.rtf'
				!
				Set bOk = bOk AND (VisFileOpen( hFileTemp, sFilename, OF_Write ) = VTERR_Ok )
				!
				Call VisFileWriteString( hFileTemp, lsData )
				!
				If hFileTemp
					Call VisFileClose( hFileTemp )
				Call SalRTFDocumentInsert( hWndItem, sFilename, TRUE )
				!
				Call VisFileDelete( sFilename )
				!
				Return bOk

Viswanadha
India
Posts: 23
Joined: 12 Jul 2018, 10:24
Location: Chennai, India

Re: How to insert data at runtime and format text into bold using RichEdit control

Post by Viswanadha » 06 Aug 2019, 03:44

Hi Didiman, Thank you very much for your reply. Is there any chance that you can share sample apt or apl file. It will be very helpful for me.

Didiman
Germany
Posts: 330
Joined: 21 Mar 2017, 13:05
Location: Bremen, Germany

Re: How to insert data at runtime and format text into bold using RichEdit control

Post by Didiman » 12 Aug 2019, 10:49

Hi,

at the moment, i can't share an Example, because it is implemented in our objectlibrary. But i think you don't need that at all, the implementation is quite simple.

Greetz

Viswanadha
India
Posts: 23
Joined: 12 Jul 2018, 10:24
Location: Chennai, India

Re: How to insert data at runtime and format text into bold using RichEdit control

Post by Viswanadha » 16 Aug 2019, 09:24

Thanks Didiman. I will try.

User avatar
Steve Leighton
Site Admin
Site Admin
New Zealand
Posts: 137
Joined: 05 Mar 2017, 20:57
Location: Tauranga, New Zealand <--> Stroud, England

Re: How to insert data at runtime and format text into bold using RichEdit control

Post by Steve Leighton » 18 Jan 2020, 02:29

Hello Didiman
Thanks for your insight - really useful, and I like the idea of manipulating the RTF code manually
( e.g. highlighting partial background is difficult, but can just add

Code: Select all

\cf2\highlight1 This Text is highlighted \cf1\highlight0
to the RTF string manually ).
But I wondered if there is any particular reason you copy to and from temporary files to manipulate the RTF format ?

Does the folllowing also do the same job without the file I/O ?
Just checking there is no reason I'm lost about:

Select RTF Text into a string B4 manipulation:

Code: Select all

! Select RTF Text into a string B4 manipulation
If SalRTFTextSelectAll( hWndRTFItem ) 
	If SalRTFTextCopy (hWndRTFItem, lsRtfBuffer, 20000)
		Call SalStrToWideChar(lsRtfBuffer, lsRtfBuffer, ENC_UTF8)
		! Now manipulate  lsRtfBuffer here to add highlighting or what ever.
		! and then copy back
Paste back the manipulated RTF code string:

Code: Select all

! Paste back the manipulated RTF code string
If SalStrToMultiByte( lsRtfBuffer, lsRtfBuffer, ENC_ANSI )
	Call SalRTFTextSelectAll( hWndRTFItem )
	Call SalRTFTextReplace( hWndRTFItem , lsRtfBuffer )
Greetings from New Zealand
Steve Leighton

Bankside Systems Ltd.
UK ♦ Australia ♦ New Zealand

www.banksidesystems.co.uk

Image

Dave Rabelink
Founder/Site Admin
Founder/Site Admin
Netherlands
Posts: 2912
Joined: 24 Feb 2017, 09:12
Location: Gouda, The Netherlands

Re: How to insert data at runtime and format text into bold using RichEdit control

Post by Dave Rabelink » 18 Jan 2020, 09:15

Steve Leighton wrote:
18 Jan 2020, 02:29
Does the following also do the same job without the file I/O ?
Just checking there is no reason I'm lost about:
Yes.

The contents of the control can be set/manipulated without file I/O.

The following WIKI article, though mainly explaining the "border" issue and loads the initial RTF from file, gives a sample how to manipulate the RTF contents.


https://wiki.tdcommunity.net/index.php/ ... play_field
Regards,
Dave Rabelink

Image
Articles and information on Team Developer Tips & Tricks Wiki
Download samples, documents and resources from TD Sample Vault
Videos on TDWiki YouTube Channel

Return to “General Discussion”

Who is online

Users browsing this forum: [Ccbot] and 0 guests