How to insert data at runtime and format text into bold using RichEdit control
How to insert data at runtime and format text into bold using RichEdit control
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.
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.
Re: How to insert data at runtime and format text into bold using RichEdit control
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:
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
Re: How to insert data at runtime and format text into bold using RichEdit control
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.
Re: How to insert data at runtime and format text into bold using RichEdit control
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
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
Re: How to insert data at runtime and format text into bold using RichEdit control
Thanks Didiman. I will try.
-
- Site Admin
- Posts: 463
- Joined: 05 Mar 2017, 20:57
- Location: Stroud, England <--> Tauranga, New Zealand
Re: How to insert data at runtime and format text into bold using RichEdit control
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 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:
Paste back the manipulated RTF code string:
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
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
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

Steve Leighton
Bankside Systems Ltd.
UK ♦ Australia ♦ New Zealand
www.banksidesystems.co.uk

-
- Founder/Site Admin
- Posts: 3522
- 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
Yes.Steve Leighton wrote: ↑18 Jan 2020, 02:29Does the following also do the same job without the file I/O ?
Just checking there is no reason I'm lost about:
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

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

Articles and information on Team Developer Tips & Tricks Wiki
Download samples, documents and resources from TD Sample Vault
Videos on TDWiki YouTube Channel
Who is online
Users browsing this forum: [Ccbot] and 1 guest