Considerations for selecting the Ansi or Unicode version of PlusMemo

Introduction

For Delphi 2009 to Delphi XE5, PlusMemo exists only as a Unicode component (TPlusMemo). For previous Delphi and CBuilder versions, PlusMemo exists in both Ansi (8bit characters) and Unicode (16bit characters) versions. The latter is called PlusMemoU. The Ansi version of the component is named TPlusMemo and the Unicode one TPlusMemoU.

They both have the same set of properties and methods, with the difference that most string properties and parameters are changed to WideString in TPlusMemoU. The user interface is the same, except that TPlusMemoU can work with Input Method Editors to enter foreign characters. Also Unicode version of accessory components exists, so all that can be done with TPlusMemo can be done with TPlusMemoU, at the expense of higher system load as discussed below. But the reverse is not true: TPlusMemoU can do things that TPlusMemo cannot, in particular handle multilingual text.

When purchasing the component, you have access to both Ansi and Unicode versions. You can select to use one or the other, or both (more below on this subject). This page contains helpful information to help decide which one to use in your application.

The rules

The most basic rule for deciding which version to use is related to the kind of external files your application works with. If you want your application to work solely with Ansi text files, then PlusMemo is the best choice. If you must work with Unicode text files, PlusMemoU is more appropriate. As explained in a text file accompanying PlusMemoU packages, TPlusMemoU.SaveToStream and LoadFromStream work with Unicode streams, as opposed to their TPlusMemo counterparts, which work with Ansi streams. TPlusMemoU can also work with Ansi streams and files through its Lines or Paragraphs properties. However, this imposes a speed penalty.

If your application is not concerned with external text files, but only with text entered by the user or set programmatically, the basic rule to use is whether you need to handle multilingual text. If so, PlusMemoU is the best bet. But if text is always in the current locale, it is preferable to use PlusMemo.

(Important note: PlusMemo does not handle bi-directional composition, nor does PlusMemoU: it means it is not appropriate at all for Arabic or Hebrew text.

Other considerations also applies:

PlusMemoU is more resource intensive than PlusMemo: memory requirements are higher, parsing, formatting, loading and saving speeds are lower. So it is best to use PlusMemo when the Unicode version is not a necessity.

The programming interface of PlusMemoU uses WideString's where PlusMemo uses string's. But WideString's are not reference counted in Delphi, so parameter passing and property retrievals incur memory allocations and copy operations under the hood, as opposed to string's where no such penalty exists.

Using PlusMemo and PlusMemoU in the same application

First, PlusMemo and PlusMemoU can coexist without problem in your design time environment. You can install both packages Pmemo6Packx.bpl and PmemoU6Packx.bpl and Delphi will not complain. Components from both package will be installed initially on the same "PlusMemo" page, and you will distinguish Unicode version of the components by a small "U" in the upper right of the palette glyph.

As for using both TPlusMemo and TPlusMemoU in your application, there is no problem also, except for the fact that there will be type identifier collisions. For example, both PlusMemo.dcu and PlusMemoU.dcu define type TpmUpdateMode. If you want to assign to property PlusMemo1.UpdateMode in your application, you may receive a compile time error like

"Incompatible types: PlusMemo.TpmUpdateMode and PlusMemoU.TpmUpdateMode"

This is because your uses clause contains PlusMemoU after PlusMemo, so TpmUpdateMode refers to the type defined in unit PlusMemoU. But PlusMemo1.UpdateMode is of the type defined in PlusMemo unit, which is not equivalent to the one defined in unit PlusMemoU (even though they are named the same).

To resolve this issue, you may change the order of PlusMemo and PlusMemoU in your uses clause, but you might then receive such incompatible type errors elsewhere in your code. The most complete solution involves qualifying problematic identifiers with their unit name. For example, the following line

PlusMemo1.UpdateMode:= umImmediate;

would become

PlusMemo1.UpdateMode:= PlusMemo.umImmediate;

Such type incompatibility issues may arise with all types defined in unit PlusMemo and similarly named in PlusMemoU. Those types are

- TpmUpdateMode;

- TplusMemoOption,TplusMemoOptions;

- TplusLineBreak;

- TpmNonPrintChar, TpmNonPrintChars;

- TssOption, TssOptions;

- TExtFontStyles.


Return to:

PlusMemo pages