Special Lists: Multiline Edit Box

Memo

A multiline edit box appears to the user as an edit box with multiple lines. To the developer it is a list in which every line is a separate entry. To fill an edit box from a file use the ADD_ENTRY command and to select data from an edit box to be written to a file use the SELECTLIST command.

A multiline edit box has to contain at least one column sourced from a field which is used to store the data. Set the ColumnRole property of this column to Data. Optionally a column can be used to store the line number (ColumnRole LineNumber). If you are using the AddEntryProperty MultiplePerRow you would usually also have a column for the row number (ColumnRole LineContinuation).

When the data is fetched from a file to the edit box or extracted from the edit box, the AddEntryMode of the edit box is used to specify whether to process one entry per line (OnePerLine) or whether to process multiple entries per line (MultiplePerLine).

The length of the line is set using the MaximumLineLength property. With AddEntryMode OnePerLine the line cannot be longer than the field from which the data column is sourced.

When a file is updated from the multiline edit box and the AddEntryMode is MultiplePerLine, the SELECTLIST command gets the data from the edit box in chunks equal to the length of the source field and the original line number is recorded in the field with the ColumnRole of LineNumber and the row number is recorded in the field with the ColumnRole LineContinuation. When data is written from the file to the edit box, the entries are packed together to fill the line.

The multiline edit box has a Modified property. This property is set to True when any changes are made to the contents of the box. The value of this property is not reset automatically, so in your application you need to set it to False after you have dealt with the changes.

A multiline edit box has methods which you often need in an editor such as cut, copy and paste, print, undo and redo. It also has properties which you can use to, for instance, determine the current line and the position of the cursor on it, to display a vertical or horizontal scroll bar and to control whether line numbers are shown.

The following code shows how you carry out the basic multiline edit box operations. The examples use a NoteFile file which consists of these fields:

Field

Description

Type

Length and Decimals

Key

NoteNo

Number identifying this particular note

Packed

7,0

1

LineNo

Line number

Packed

7,0

2

RowNo

Row number

Packed

7,0

3

Text

The text

Alpha

50

 

 

 

The name of the multiline edit box is #MeditBox. It is set up like this:

Property

Value

AddEntryMode of #MeditBox

MultiplePerLine

MaximumLineLength of #MeditBox

1000

ShowLineNumbers

True

WordWrap of #MeditBox

True

 

 

#MeditBox has these columns:

Column

Source Field

ColumnRole Property

Column 1

Text

Data

Column 2

LineNo

LineNumber

Column 3

RowNo

LineContinuation

 

 

memo2

The Note Number field from the NoteFile is used to identify the note.

On the left, the form has buttons to:

The buttons have these Click event routines:

* This code deletes any previous text and writes the contents of the

* edit box to the file:

EVTROUTINE HANDLING(#UPDATEB.Click)

if '#meditbox.modified *eq True'

delete from_file(notefile) with_key(#noteno)

selectlist #meditbox

insert fields(#noteno #lineno #rowno #text) to_file(notefile) val_error(*next)

endselect

endif

ENDROUTINE

*This  fetches the text lines of a note from the file:

EVTROUTINE HANDLING(#GETBTN.Click)

select fields(#text #lineno #rowno) from_file(notefile) with_key(#noteno)

add_entry (#MEditBox)

ENDSELECT

ENDROUTINE

*This  clears the edit box:

EVTROUTINE HANDLING(#CLEARBTN.Click)

clr_list (#meditbox)

ENDROUTINE

*This deletes the entry from the database and clears the edit box:

EVTROUTINE HANDLING(#DELETEBTN.Click)

dowhile '#io$sts *ne NR'

delete from_file(notefile) with_key(#noteno)

endwhile

clr_list (#meditbox)

ENDROUTINE

On the right there are several buttons used to invoke the methods of a multiline edit box. They contain these event routines:

EVTROUTINE HANDLING(#SELECTALL.Click)

   invoke #meditbox.selectall

ENDROUTINE 

EVTROUTINE HANDLING(#CUT.Click)

   invoke #meditbox.cut

ENDROUTINE 

EVTROUTINE HANDLING(#COPY.Click)

   invoke #meditbox.copy

ENDROUTINE 

EVTROUTINE HANDLING(#PASTE.Click)

   invoke #meditbox.paste

ENDROUTINE 

EVTROUTINE HANDLING(#UNDO.Click)

   invoke #meditbox.undo

ENDROUTINE 

EVTROUTINE HANDLING(#REDO.Click)

   invoke #meditbox.redo

ENDROUTINE 

EVTROUTINE HANDLING(#FIND.Click)

   invoke #meditbox.find

ENDROUTINE 

EVTROUTINE HANDLING(#REPLACE.Click)

   invoke #meditbox.replace

ENDROUTINE 

EVTROUTINE HANDLING(#PRINT.Click)

   invoke #meditbox.print

ENDROUTINE