Science makes it known,
Engineering makes it work,
Art makes it beautiful.
Appending Text to Windows Edit Control in Free Pascal
In some Windows applications it would be useful to have a scrolling
Edit Control to append text messages to. This Edit Control could
be used to display program execution progress/status messages, warnings,
or any area
where using MessageBox (...) would be tedious
Requires both Free Pascal
(for hwndio.pas and lclio.pas) and
(for LCLIntf.ppu). Uses standard Windows API calls.
Using Pascal Artificial Life1 Windows program
as an example, the Edit Control being appended to is the one labeled
The appended text edit control is an auto-scrolling multi-line child
Library hwndio procedure HWND_APPND_TEXT (...)
is used to append text to edit control.
To prevent appended text edit control overflow, Library lclio
procedure rmv0_1023 (...) is used to delete the
leading 1024 characters.
Create appended text edit control hEditOutput (type HWnd)
as shown at right.2 Window is parent Window handle,
IDC_EDIT_OUTPUT is a constant (resource id number).
In addition to any other external procedures,
declare external Library hwndio procedure
HWND_APPND_TEXT (...) and Library lclio
procedure rmv0_1023 (...)
(Programmer's Guide Chapter 12)
- include in main program;
include file developed from major rewrite of
(Free Pascal dawkins8.dll callable from both
Pascal and D programs); contains useful CONSTant and
- collection of Free Pascal general purpose functions for Windows Edit
Controls I/O, field tabbing, etc. procedure
HWND_APPND_TEXT (...) (shown at right) is used to
append text to edit control. Source
code is commented as to purpose. Compile with batch file
hwndio.dll - hwndio.pas dynamic link library
(shown lower right)
uses LCLIntf.ppu (see below); procedure
rmv0_1023 (...) replaces leading 1024 bytes of
appended text edit control with '...', moves caret to end of
In procedure rmv0_1023 (...) parameter list,
define hEditOutput as type Windows.HWnd; otherwise
will default to LCLType.HWnd.
Compile with modified batch file
lclio.dll - lclio.pas dynamic link library
LCLIntf.ppu - Lazarus Component Library (LCL) component unit
description file; contains MAKELONG (...) and
MAXWORD (used by Library lclio procedure
open a MS-DOS Command Prompt
compile lclio.pas -
in addition to the -WR switch, fpcdll.bat will also need the
(the above values reflect my Lazarus installation,
which is on the D: drive, \lazarus directory; be sure to adjust the
switches to reflect your installation):
Compile Pascal Main Program in FPC IDE
Using HWND_APPND_TEXT (...):
At the right is procedure mateWarn (...) from
degaris1.pas1 (compiled into a .dll and
Pascal Artificial Life; as an example of
software reuse, degaris1.dll also calls RAN3 (...)
and IRBIT1 (...) in
and NNaryIdx2mtrxIdx (...) in
mateWarn (...) generates an output
message and passes both it and the appended text edit control to
ASCII Chr(13) (or '\r' in D) is a carriage return
ASCII Chr(10) (or '\n' in D) is a line feed
(shown at right) is an Object Pascal unit used for file name
I/O and file error reporting in Object Pascal Windows
fnameIO is used in Pascal Artificial Life and another
Object Pascal Windows application.
The error reporting procedures fileOpnStat (...),
IOerrMsg (...), and trnsfrMsg (...) call
(not shown; briefly described in
Pascal calling FORTRAN engineering subroutines)
procedure missleErrProc (...) may call
HWND_APPND_TEXT (...) as part of a more
elaborate error reporting. Depending on main program language,
user interface, and
passed paramenters, missleErrProc (...) may
display the error message on the console, output it in a
MessageBox (...), or append it to the
scrolling appended text Edit Control message area.
See function cPopUpMenu (...) (described in
Pascal calling D and FORTRAN
for an example of appending text
in a D function.
Using rmv0_1023 (...):
At the right is a code snippet from plife.pas
(Pascal Artificial Life) WM_COMMAND: processing.
Using SendMessage (...,WM_GETTEXTLENGTH,...) to
get the length of the appended text edit control. In this example,
if it is over 8192 rmv0_1023 (...) is called.
1. Rietman, Edward (1994).
Genesis Redux: Experiments Creating Artificial Life. Windcrest (McGraw-Hill).
Dawkins8 Biomorphs - resembles both L-systems and iterated function systems;
ported from MS-DOS Turbo Pascal main program to
Object Pascal Library
Degaris1 - simple genetic algorithm neural network; ported from MS-DOS
Turbo Pascal main program to Object Pascal Library
2. Below is a D code snippet to create an appended text edit control
(code snippet is now function addMsgCtrl (...) in
D module aero010
and is called by D module aero030).
(D module aero030 estimates the coefficient of friction and
of model rockets and boost-gliders using Object Pascal
procedures and FORTRAN subprograms; have yet to test D calling rmv0_1023 (...),
though it should work)
3. These terms originated with teletype terminals. Control characters got
their name for being Carriage Control characters.