Let's start with a really exotic bug: The way the RichEdit control stores tables. I stumbled over this one when trying to create a "serial letter" application. It uses a template wirh tags:
This file was created on #date#
#column1# #column2# #column3#
#value11# #value12# #value13#
#value21# #value22# #value23#
In the RTF file (attached), it is a nice table. You can read the whole file into a string, replace the tags with appropriate values, save the result, and voilà, there is a RTF file ready for printing. Code:
include \masm32\MasmBasic\MasmBasic.inc ; download
Init
Let esi=FileRead$("TemplateHashes.rtf") ; read a template into a buffer
Let esi=Replace$(esi, "#date#", Date$) ; replace tags
Let esi=Replace$(esi, "#column1#", "First column")
Let esi=Replace$(esi, "#column2#", "Second column")
Let esi=Replace$(esi, "#column3#", "Third column")
FileWrite "LetterHashes.rtf", esi ; save result
ShEx "LetterHashes.rtf" ; and open it in the default editor
EndOfCodeThe line "This file was created on #date#" works fine. Always.
The
table works fine if your template was saved with certain versions of RichEd20.dll, but it
fails miserably if the template was saved with others :(
System32 ; OK (but C:\Windows\System32\RichEd20.dll is utterly slow and lacks many features)
Office15 ; OK (but has some other bugs)
Office14 ; bad
Office12 ; bad
Office11 ; OK
Why this?
A line of a table gets typically saved as follows:
\pard\intbl\nowidctlpar\cf2\i0 #column1#\cell #column2#\cell #column3#\cell\row\trowd\trgaph70\trleft-30\trpaddl70\trpaddr70\trpaddfl3\trpaddfr3
The interesting part is
\cell #column2#\cell #column3#
After the replacing of tags, it becomes
\cell Second column\cell Third column
Perfect :t
But it fails with the Office12 and Office14 versions of RichEd20.dll because these DLLs save the template as follows:
[code]\cell#column2#\cell#column3#
No blank after the RTF tag! It's probably a feature 8), and it will hit you as a bug only in very exotic situations like the one outlined above: words starting with # in cells of a table. Same for words starting with
$, btw, and maybe others.
Workaround: Use
+ instead of
# or
$.
Here is a list of tested delimiters. OK means even the buggy DLLs insert a space after the rtf tag, bad means they don't.
OK +/-:@[^?
bad $\#§*"'&|