Bitmaps embedded in a TRichEdit control

Posted on 1998-09-02
Last Modified: 2013-12-03
I'm looking for code snippets, examples, etc. how to implement bitmaps (standard BMP files, e.g. a company logo) in a TRichEdit. I know I'll probably need to use the IRichEditOle interface (it's OK if it's NT only, since that's the only platform this software will be running on). But I haven't the foggiest where to start...
As a quite experienced Pascal programmer but a relative newbie at the Windows API, I could use all help and hints you experts can provide me.

Question by:htw
  • 2

Accepted Solution

ZifNab earned 100 total points
ID: 1338478

This is what I normally would answer, ...

 I don't think it's possible to add any Object into a TRichedit. TRichEdit is limited!! Very Limited! It's descents from Windows Richedit control and doesn't has all the functions!

To try it for yourself, do the following:

1. Create a new document in Word.
2. Type in some text, format it the way you want.
3. Insert some picture.
4. Save the file as Rich Text Format (.RTF)
5. Open the previous RTF file from within your Delphi application, using MyRichEdit.Loadfromfile('xxxxxx.rtf').

Result :
The text will be displayed exactly how you formated it in Word, but the images won't. Thus we can conclude that images aren't supported by TRichEdit..


BUT : Last I read that it is possible with D3 and the richedit comming from IE4... here is the text :

Using Delphi 3 and the RichEdit control which comes with the IE 4 release, it appears that all you absolutely have to do to display graphics and other embedded or linked objects in a RichEdit control is implement one method of IRichEditOLECallback: specifically GetNewStorage. I've attached a TRichEdit descendent which does this (in the file OLERichEdit.pas) as well as a translation of the richole.h file (from BC5) which defines the RichEdit OLE interfaces.

The OLERichEdit file also includes one obvious enhancement to the default behavior. If you enable the VerbMenu define, then when you select a (linked or embedded) object and right click on it, the control will pop up a menu of available verbs for the object. The code used is essentially the same as that in the VCL's TOleContainer.

The implementation of the control included here allows you to edit objects by double clicking on them; it opens whatever application is registered to edit the object type (e.g., double click on a bitmap and Paint opens up).
The RichEdit control will also support in-place activation, provided you implement the right methods of IRichEditOleCallback (I did not try this in the unit included here). It appears to me that alot of the stuff in OLECTNRS.PAS could be used to enable this behavior.

Finally, a warning. This control has not been extensively tested by any means, and there may well be bugs or gotchas that I have not anticipated.
Use with caution. It is intended primarily as a starting point for people interested in extending TRichEdit.

followed by the code of richole... to big to paste it here

another (never tested this) component you can find :


find sources etc at his homepage



LVL 10

Expert Comment

ID: 1338479
Here is something you might want to try.....
procedure TForm1.Button1Click(Sender: TObject);
  bmp : TBitmap;
  Can : TCanvas;
  bmp := TBitmap.Create;
  Can := TCanvas.Create;
    Bmp.LoadFromFile('E:\My Bmps\checked.bmp');
    Can.Handle := GetDC(RichEdit1.Handle);
I hope it helps =)

Viktor Ivanov

Author Comment

ID: 1338480

I too played with the idea to treat the RichEdit control as a canvas, and on screen this approach works OK, but it's a big hassle to print the "embedded" (or should I say overlayed, or is it underlayed? ;-)) graphics on paper.


Author Comment

ID: 1338481

Thanks, on a first glance this looks like the component I need! Good readable source, looks like a decent piece of code, and even if it doesn't work (haven't tried it yet) it should be a great starting point for me to set my teeth in... ;-)

Maybe one caveat: in the past (when I just started with Delphi, coming from a Clipper background) I also tried to embed OLE objects using IRichEditOLECallback (in a _much_ less sophisticated way), and while this worked under Win95, it did absolutely nothing under NT 4.0 ws. If this still is the case it shouldn't be too difficult to alter the component so it uses IRichEditOLECallback under W95 and IRichEditOLE under NT...

Anyway, thanks for the URL. Apparently a lot of great Delphi programmers are living in the eastern part of Europe!


Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question