The Unofficial Newsletter of Delphi Users - by Robert Vivrette



Multiple Lines of Text in a String Grid - Improved!

by Chuck Gadd - cgadd@cfxc.com

In issue #23 of UNDU, Paul Harding presented an article on how to draw two lines of text in a string grid. As it turns out, there is a simpler way which is even a bit more powerful. Using this technique, you can write any number of lines of text that are naturally wrapped within the cells bounds. If the cell width is modified, the text re-wraps accordingly.

 

To try this out, start a new project, drop a String Grid on the form and add the following code:

This code is Delphi 3 specific however... Delphi 1 and Delphi 2 can't typecast a String to a PChar, so you'll need to declare a PChar, use GetMem to get the memory for it, StrPCopy the pascal string into it and then pass that PChar into the DrawText Command. Later don't forget to use FreeMem to release the memory.