I'm a newbie at this forum. I've been using Delphi 3.0 for a long time, but have run into some problems I just don't know how to handle.

I'm looking for some coding tips on how to do certain things in Delphi ObjectPascal.

First of all, is Delphi 3.0 hopelessly obsolete? I've been using it at least since 1998 and it seems to work as well on XP as it did on Windows 98 and later 2000.

I am working with foreign language text, building a translation tool, and I have to input text in various languages and the special characters don't always get handled properly.

In particular, certain Unicode characters can be pasted from another site into my program, but when I save them in a Rich Text File (using a Rich Text Editor control gizmo), some of these Unicode characters don't get stored properly or at all. They may look fine on the screen when first pasted, but get converted to a ? internally, so that my program never sees those characters. An example would be the letter e with a single dot over it, as opposed to e with an accent (acute or grave, é, è, ) or an umlaut (ü). I don't even know how to enter such a Unicode character using the U.S. International Keyboard in windows, although I'm sure where there's a will there's a way. So far I've mostly had to deal with characters generated by other people and I cut and paste the text to process through my program.

I'd really love to be able to save Unicode in a file and read it into my Delphi program automatically using the Load From File routine (I forget the exact name). I'm just not sure if the 16-bit Unicode characters can be stored in the Lines array within the Rich Text Editor control in Delphi.

I've been using these routines for many years, since 1998, in fact, since I coded the first Windows version of my existing DOS program, using Delphi 3.0. I also had Delphi 1.0 and 2.0 in the past. Does anyone have any recommendations on upgrading? I saw a free version online that I was afraid to install for fear of messing up my existing installation, which works quite well for me.

Ok, that's one question, is there an easy way to handle these Unicode characters on input and output.

I also would love to know how to highlight specific portions of the text within a Rich Text Editor control, without changing the attributes of all the lines, just some lines or some words within the line. I'd like to highlight unrecognized words in a different color to make them stand out. Any ideas on how to do this easily. I've had very little luck reading the Delphi Help files. It seems like nothing I look for is in the Index, and the help files might as well have been written by aliens from another planet, as they aren't as straightforward and prescriptive as I might like.

I've had good luck winging it on my own thus far, but it's time to ask for help, as I just haven't had any luck solving certain problems with the user interface. I've been coding in Pascal since around 1980, so I know Pascal very well, just am not as familiar with character set issues as I would like to be. Ideally I could handle Cyrillic just as easily as Japanese, or any European language which uses special characters, such as Esperanto, Latvian, Lithuanian, just to name a few that present special challenges. It seems like the RTF format will handle a lot of special characters, but notepad and other editors complain if I try to save a file with even a single Unicode character in it, and I don't know how to modify my program to store all my files in Unicode format.

Any help, ideas, suggestions, code snippets, examples, links, etc, would be greatly appreciated.

Recommended Answers

All 2 Replies

It is unfortunate, but I don't think the Delphi tRichEdit class can do unicode. The lines member is a tStrings object, which uses the string type instead of wideString.

I use Delphi 5.0 and I've been playing around with the rich edit control myself for the past week or so... The tRichEdit component is woefully underpowered. You need to do a lot of stuff yourself.

If you can wait a few days I'll post an example that I think will help you out a lot (well, at least to get you started).

In short though, you'll need to include the RichEdit unit (yes, I know it isn't in the docs) and communicate with the rich edit control yourself using sendMessage. Also, the Win32 Programmer's Reference (win32.hlp) that comes with Delphi is a very useful reference, though not always complete or correct, alas.

You can add input languages from Start --> Settings --> Control Panel --> Regional and Language Options. On the "Languages" tab press "Details" and add the language you like. Thereafter there will be a little button on your taskbar to switch keyboard layouts. Make sure you look up the new layout before switching though...

Other than that, Google is the only other help. Look for things like "rich edit syntax highlight" for the most useful information. Be sure to look through all the Delphi pages too... there are random snippets to do unusual things with a tRichEdit here and there. Unfortunately, you'll still have to sift through a lot of chaff...

Hope this helps (somewhat, at least)...

Since my last post I've been looking around the web to see what I can find out. According to Peter Below (the guy who designed the rich edit stuff in Delphi), you will need to find a unicode rich edit component. [ 1 ]

There appears to be a lot of hubbub about tRichView , which has a trial version, but is not free.

If you don't want to pay money, you'll have to search more than I or roll your own. You can create a unicode rich edit component by using CreateWindowEx() with the appropriate class name (RichEditW, I think), and handle all your own messages. A rich edit control isn't that difficult to handle, just a lot of calls to sendMessage() and a couple message handlers.

Hope this helps.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.