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
and/or tiresome.
Requires both Free Pascal
(for hwndio.pas and lclio.pas) and
Lazarus
(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
Messages:
The appended text edit control is an auto-scrolling multi-line child
window.
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.
Main Program:
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)
Files:
-
genetyp.inc1
- include in main program;
include file developed from major rewrite of
Dawkins8 Biomorphs1
(Free Pascal dawkins8.dll callable from both
Pascal and D programs); contains useful CONSTant and
TYPE declarations
-
hwndio.pas
- 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
fpcdll.bat.
hwndio.dll - hwndio.pas dynamic link library
-
lclio.pas -
(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
edit control.
In procedure rmv0_1023 (...) parameter list,
define hEditOutput as type Windows.HWnd; otherwise
will default to LCLType.HWnd.
Compile with modified batch file
fpcdll.bat.
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
rmv0_1023 (...))
|
|
Compiling/Linking
-
open a MS-DOS Command Prompt
-
compile hwndio.pas:
fpcdll hwndio
-
compile lclio.pas -
in addition to the -WR switch, fpcdll.bat will also need the
following switches:
-FuD:\lazarus\lcl\units\i386-win32
-FuD:\lazarus\lcl\units\i386-win32\win32
-FuD:\lazarus\components\lazutils\lib\i386-win32
(the above values reflect my Lazarus installation,
which is on the D: drive, \lazarus directory; be sure to adjust the
additional
switches to reflect your installation):
fpcdll lclio
-
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
called from
Pascal Artificial Life; as an example of
software reuse, degaris1.dll also calls RAN3 (...)
and IRBIT1 (...) in
mathproc.dll
and NNaryIdx2mtrxIdx (...) in
ALlazrs.dll
).
mateWarn (...) generates an output
message and passes both it and the appended text edit control to
HWND_APPND_TEXT (...).
ASCII Chr(13) (or '\r' in D) is a carriage return
(CR),
ASCII Chr(10) (or '\n' in D) is a line feed
(LF).3
|
|
fnameIO.pas
(shown at right) is an Object Pascal unit used for file name
I/O and file error reporting in Object Pascal Windows
applications.
fnameIO is used in Pascal Artificial Life and another
Object Pascal Windows application.
The error reporting procedures fileOpnStat (...),
IOerrMsg (...), and trnsfrMsg (...) call
HWND_APPND_TEXT (...).
missle02.pas
(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
footnotes) in
hedtio.di
and
hedtio.d
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
drag coefficient
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.
|