Sign in Join
Wiki copytemporary

ChemText

About

ChemText demo TChemText is a TCustomLabel descendant which can display chemical formulas and reaction equations with automatically placed subscripts and superscripts.

Authors

The code is based on "chemtxt" written by Patrick Spanel. It was adapted to Lazarus and extended by Werner Pamler.

License

Modified LGPL (with linking exception, like Lazarus LCL)

Download and Installation

Release version

A zip file with the most recent release version can be found at Lazarus CCR at SourceForge. Unzip the file into any folder.

The current release version is 0.1.5

Development version

Use an svn client to download the current trunk version from svn://svn.code.sf.net/p/lazarus-ccr/svn/components/chemtext/

Installation

In Lazarus, go to "Package" > "Open Package File .lpk". Navigate to the folder with the callite sources, and select laz_chemtext.lkp. Click "Compile", then "Use" > "Install". This will rebuild the IDE (it may take some time). When the process is finished the IDE will restart, and you'll find TChemLabel in the component palette Misc as this new icon: ChemText palette icon

Usage

TChemLabel

Simply drop a TChemLabel component on the form and type the chemical formula/reaction into the property Caption.

The formulas are written in a straightforward way. The "2" in H<sub>2</sub>O is automatically subscripted, and the + in H<sup>+</sup> is automatically displayed as superscript. A period "." is converted to a "hydrate dot" •. Note that multiple-charge ions must repeat the charge sign, i.e. the double-negatively charged oxygon ion must be written as O--, not as O2-.

For cases in which aligned subscripts and superscripts are required a special syntax with code symbols is available:

The size and offset of sub-/superscripts is determined by the following global integer variables:

For chemical reactions, arrows can be entered as -->, <-- or <-->. The property Arrow of the TChemLabel determines whether this simple ASCII symbol is to be replaced by a nice UTF8 symbol:

Note that the UTF8 characters may not be available in any font.

If the ChemLabel contains other text besides the chemial formula the processing of numerical digits, +, - and arrows may be undesired. Therefore, the characters '0'..'9', '+', '-', '<', and '>' can be escaped by writing a backslash in front of them. And the backslash itself can be used by doubling it.

Examples

Using the painting routine in other controls

The main painting routine of TChemLabel is available as a global function and can be called in any owner-draw code of other components, e.g. a StringGrid.

pascal
function ChemTextOut(ACanvas: TCanvas;  X, Y:integer; const AText: String;
  Arrow: TChemArrow = caAsciiSingle; Measure: Boolean = false): TSize;

In addition, the following functions can be used to determine the size of the text bounding box:

Demos

The installation folder contains the following demon projects:


From the Free Pascal wiki, page "ChemText", as it stood on 2021-03-12 after a change by Wp, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.

Revision 1, last changed by WikiArchive .

Talk about this page

Nobody has opened a bench for this page yet. Sign in to open one.