Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: How to add text between other texts in the middle of a RichEdit or memo?


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 16 - Last Post: Oct 27, 2017 7:47 AM Last Post By: Eduardo Tavares Threads: [ Previous | Next ]
Eduardo Tavares

Posts: 8
Registered: 2/6/06
How to add text between other texts in the middle of a RichEdit or memo?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 22, 2017 3:32 AM
Hi!

I have a richEdit and 3 buttons (Header,Body and Footer buttons) I want to add a text to the top of my RE when I press the header button and I want to add a footer text when I press footer button and I want to add text to the middle of the richedit everytime i hit the body button.

How do I do this?

thank you
Rudy Velthuis (...


Posts: 7,731
Registered: 9/22/99
Re: How to add text between other texts in the middle of a RichEdit or memo?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 22, 2017 11:52 PM   in response to: Eduardo Tavares in response to: Eduardo Tavares
Eduardo Tavares wrote:

Hi!

I have a richEdit and 3 buttons (Header,Body and Footer buttons) I
want to add a text to the top of my RE when I press the header button
and I want to add a footer text when I press footer button and I want
to add text to the middle of the richedit everytime i hit the body
button.

How do I do this?

Create an empty selection at the place you want to insert and then
change the (empty) selection to your text, I guess.

--
Rudy Velthuis http://www.rvelthuis.de

Thoreau's Theories Of Adaptation:

1. After months of training and you finally understand all of
a program's commands, a revised version of the program
arrives with an all-new command structure.
2. After designing a useful routine that gets around a
familiar "bug" in the system, the system is revised, the
"bug" taken away, and you're left with a useless routine.
3. Efforts in improving a program's "user friendliness"
invariable lead to work in improving user's "computer
literacy".
4. That's not a "bug", that's a feature!
Roy Lambert

Posts: 1,063
Registered: 8/7/01
Re: How to add text between other texts in the middle of a RichEdit or memo?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 23, 2017 2:32 AM   in response to: Eduardo Tavares in response to: Eduardo Tavares
Eduardo

I had a google and it looks as though this will be difficult or impossible - one post from 2006

http://borland.newsgroups.archived.at/public.delphi.vcl.components.using.win32/200601/0601241364.html

You may be better off looking at an alternative control that will give you the functionality you want. If you have money to spend I'd look at WPTools or RichView. If not look at TJvRichEdit or the free version of RichView. If you like pain you can try embedding Word.

The only other thing I can suggest is three RichEdits - header, body, footer and merge them together when saving, split when loading. I don't know enough rtf to help - I've been a WPTools user for ages.

Roy Lambert

Rudy Velthuis (...


Posts: 7,731
Registered: 9/22/99
Re: How to add text between other texts in the middle of a RichEdit or memo?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 23, 2017 4:51 AM   in response to: Roy Lambert in response to: Roy Lambert
Roy Lambert wrote:

Eduardo

I had a google and it looks as though this will be difficult or
impossible - one post from 2006


Inserting text in a RichEdit is nearly impossible? Really?

--
Rudy Velthuis http://www.rvelthuis.de

"Don't be so humble - you are not that great."
-- Golda Meir (1898-1978) to a visiting diplomat
Roy Lambert

Posts: 1,063
Registered: 8/7/01
Re: How to add text between other texts in the middle of a RichEdit or memo?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 23, 2017 5:21 AM   in response to: Rudy Velthuis (... in response to: Rudy Velthuis (...
Rudy

I had a google and it looks as though this will be difficult or
impossible - one post from 2006

Inserting text in a RichEdit is nearly impossible? Really?

It depends on how you interpret the post. If all Eduardo wants to to put text in the top, middle, or bottom of a TRichEdit then throw away the buttons and use the mouse. If, however, he wants proper header and footer sections similar to Word then to use Remy Lebeau's exact words <<No>>

Following the link and reading might have made that clear to you.

Roy
Eduardo Tavares

Posts: 29
Registered: 1/17/05
Re: How to add text between other texts in the middle of a RichEdit or memo?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 23, 2017 8:01 AM   in response to: Roy Lambert in response to: Roy Lambert
Roy Lambert wrote:
Rudy

I had a google and it looks as though this will be difficult or
impossible - one post from 2006

Inserting text in a RichEdit is nearly impossible? Really?

It depends on how you interpret the post. If all Eduardo wants to to put text in the top, middle, or bottom of a TRichEdit then throw away the buttons and use the mouse. If, however, he wants proper header and footer sections similar to Word then to use Remy Lebeau's exact words <<No>>

Following the link and reading might have made that clear to you.

Roy

I am trying to do an application kind like a prescription app.When user clicks New Prescription a memo or richedit would insert a header with the name of the doctor prescribing all the exames or medicine.Then the user would add each medicine or exame at a time and everytime he clicked a button to add a medicine that is saved on a database shown in a dbgrid my application would add it to the middle of the Memo one underneath the other. Then after user finished adding medicines or exames he would click another button that would add explanations how to take those medicines. I did this application before and it is working but unfortunately I lost my harddrive with the source code.Now i need to do it again since my boss wants me to update this application.

Roy Lambert

Posts: 1,063
Registered: 8/7/01
Re: How to add text between other texts in the middle of a RichEdit or memo?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 23, 2017 8:22 AM   in response to: Eduardo Tavares in response to: Eduardo Tavares
Eduardo

This may be terminology. Does your header & footer need to appear at the top and bottom on every page printed or just header at the start and footer at the finish? If the latter its just a matter of positioning the cursor which is a lot easier.

My repeat prescription (UK) has a "proper" header with some text at the bottom of th last page printed.

Roy Lambert

Eduardo Tavares

Posts: 29
Registered: 1/17/05
Re: How to add text between other texts in the middle of a RichEdit or memo?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 23, 2017 9:53 AM   in response to: Roy Lambert in response to: Roy Lambert
Roy Lambert wrote:
Eduardo

This may be terminology. Does your header & footer need to appear at the top and bottom on every page printed or just header at the start and footer at the finish? If the latter its just a matter of positioning the cursor which is a lot easier.

My repeat prescription (UK) has a "proper" header with some text at the bottom of th last page printed.

Roy Lambert


Hi Roy!
Every prescription has the name of the doctor and name and some information of the client that is getting the prescription. In the middle of my prescription goes the medicines and at the end of the list of medicines goes how the client must take those prescribed medicines.
Then at the bottom goes date and name of the doctor with a line so he can sign the prescription.

thank you
Eduardo Tavares

Posts: 29
Registered: 1/17/05
Re: How to add text between other texts in the middle of a RichEdit or memo?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 25, 2017 1:02 PM   in response to: Roy Lambert in response to: Roy Lambert
Roy Lambert wrote:
Eduardo

This may be terminology. Does your header & footer need to appear at the top and bottom on every page printed or just header at the start and footer at the finish? If the latter its just a matter of positioning the cursor which is a lot easier.

My repeat prescription (UK) has a "proper" header with some text at the bottom of th last page printed.

Roy Lambert


Roy How would I do this cursor positioning? I guess this is what I´ve done before..
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: How to add text between other texts in the middle of a RichEdit or memo?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 25, 2017 1:46 PM   in response to: Eduardo Tavares in response to: Eduardo Tavares
Eduardo Tavares wrote:

Roy How would I do this cursor positioning?

Use the SelStart and SelLength properties.

Starting with a clear Memo/RichEdit, add the header text and remember
the ending offset of that text. That is where the middle text begins.

Then add the middle text and remember the ending offset of that text.
That is where the footer text begins.

Then add the footer text.

After populating the Memo/RichEdit, whenever you want to change the
header, middle, or footer section without affecting the other sections,
simply set the SelStart and SelLength properties appropriately, set the
SelText property to replace the selected text, and then save the
updated offsets.

--
Remy Lebeau (TeamB)
Eduardo Tavares

Posts: 29
Registered: 1/17/05
Re: How to add text between other texts in the middle of a RichEdit or memo?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 27, 2017 3:50 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:
Eduardo Tavares wrote:

Roy How would I do this cursor positioning?

Use the SelStart and SelLength properties.

Starting with a clear Memo/RichEdit, add the header text and remember
the ending offset of that text. That is where the middle text begins.

Then add the middle text and remember the ending offset of that text.
That is where the footer text begins.

Then add the footer text.

After populating the Memo/RichEdit, whenever you want to change the
header, middle, or footer section without affecting the other sections,
simply set the SelStart and SelLength properties appropriately, set the
SelText property to replace the selected text, and then save the
updated offsets.

--
Remy Lebeau (TeamB)

thank you
Roy Lambert

Posts: 1,063
Registered: 8/7/01
Re: How to add text between other texts in the middle of a RichEdit or memo?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 26, 2017 5:56 AM   in response to: Eduardo Tavares in response to: Eduardo Tavares
Eduardo

As they say when giving directions - I wouldn't start from here <G>

Seriously as I and Remy have suggested I'd use three separate controls - it would be much easier, and with a bit of alignment the user will only see one.

However, if you want to go down the one control route then either as Remy has said, or my approach would be to have a separator (eg a full line of - or _) and then when you want to change simply search down the lines until you find it.

Roy Lambert

Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: How to add text between other texts in the middle of a RichEdit or memo?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 23, 2017 9:44 AM   in response to: Eduardo Tavares in response to: Eduardo Tavares
Eduardo Tavares wrote:

When user clicks New Prescription a memo or richedit would insert a
header with the name of the doctor prescribing all the exames or
medicine.Then the user would add each medicine or exame at a time and
everytime he clicked a button to add a medicine that is saved on a
database shown in a dbgrid my application would add it to the middle
of the Memo one underneath the other. Then after user finished adding
medicines or exames he would click ano ther button that would add
explanations how to take those medicines.

Why are you trying to use a single Memo/RichEdit for this? While it
can be done, it would not be a very good UI experience. I would
suggest using 3 separate controls instead:

- a TMemo/TRichEdit for the doctor's info (unless you really don't need
multiple lines, then use TEdit intead)

- a TListBox or TListView for the list of medicines/exams

- a TMemo/TRichEdit for the directions.

--
Remy Lebeau (TeamB)
Eduardo Tavares

Posts: 29
Registered: 1/17/05
Re: How to add text between other texts in the middle of a RichEdit or memo?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 23, 2017 9:55 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:
Eduardo Tavares wrote:

When user clicks New Prescription a memo or richedit would insert a
header with the name of the doctor prescribing all the exames or
medicine.Then the user would add each medicine or exame at a time and
everytime he clicked a button to add a medicine that is saved on a
database shown in a dbgrid my application would add it to the middle
of the Memo one underneath the other. Then after user finished adding
medicines or exames he would click ano ther button that would add
explanations how to take those medicines.

Why are you trying to use a single Memo/RichEdit for this? While it
can be done, it would not be a very good UI experience. I would
suggest using 3 separate controls instead:

- a TMemo/TRichEdit for the doctor's info (unless you really don't need
multiple lines, then use TEdit intead)

- a TListBox or TListView for the list of medicines/exams

- a TMemo/TRichEdit for the directions.

--
Remy Lebeau (TeamB)

Very good sugestion Remy thank you..I said a memo or richedit because like I said I´ve done this before with a memo and it is working but I haven´t thought about this option before.

thank you very much

Edited by: Eduardo Tavares on Oct 23, 2017 9:56 AM
Roy Lambert

Posts: 1,063
Registered: 8/7/01
Re: How to add text between other texts in the middle of a RichEdit or memo?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 23, 2017 10:00 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Thinking about it a more I wouldn't even bother about the header & footer controls that's stuff needed on a printout not (generally) a screen.

I'd have two labels one showing the patient and one the doctor, a dbgrid with checkbox selection (I prefer them to listboxes).

When the OK button is clicked then merge together as html, rtf ore pdf - whichever is appropriate.

Roy Lambert

Douglas Rudd

Posts: 314
Registered: 5/16/97
Re: How to add text between other texts in the middle of a RichEdit or memo?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 26, 2017 2:49 PM   in response to: Eduardo Tavares in response to: Eduardo Tavares
You can put all your info in separate strings and then recreate the memo every time you push the button:

memo1.text := header + medicine1 + medicine2 + footer;
Eduardo Tavares

Posts: 29
Registered: 1/17/05
Re: How to add text between other texts in the middle of a RichEdit or memo?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 27, 2017 7:47 AM   in response to: Douglas Rudd in response to: Douglas Rudd
Douglas Rudd wrote:
You can put all your info in separate strings and then recreate the memo every time you push the button:

memo1.text := header + medicine1 + medicine2 + footer;

Thank you Douglas very good sugestion too..Thank you very much
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02