home *** CD-ROM | disk | FTP | other *** search
-
-
- const {single character codes for each of
- the special keys on the keyboard}
- BACKSPC = #8;
- TAB = #9;
- NEWLINE = #13;
- ESC = #27;
-
- F1 = #128;
- F2 = #129;
- F3 = #130;
- F4 = #131;
- F5 = #132;
- F6 = #133;
- F7 = #134;
- F8 = #135;
- F9 = #136;
- F10 = #137;
-
- HOME = #140;
- UP = #141;
- PGUP = #142;
- LEFT = #144;
- RIGHT = #146;
- ENDLINE = #148;
- DOWN = #149;
- PGDN = #150;
- INS = #151;
- DEL = #152;
-
-
- type
- anystring = string[128];
-
-
-
- function getkey: char; {get a key; map special keys into the
- matching symbolic constant}
- var
- c: char;
-
- begin
- read(kbd,c); {read a key}
-
- if (c = ESC) and keypressed then {if this is a funtion key, then
- read the second byte and convert
- it into a special key code}
- begin
- read(kbd,c);
- c := chr(ord(c) + 69); {this makes F1=#128}
- end;
-
- getkey := c;
- end;
-
-
-
-
- procedure edit_string(x,y: integer; {cursor position}
- col: integer; {initial column in buffer}
- var str: anystring; {buffer to input}
- var c: char; {exit character from input}
- maxlen: integer); {max length of input}
- {provide full text editing
- on the contents of a string
- variable; processes most
- editing keys. this is where
- all the time is spent while
- waiting on the user}
- var
- i: integer;
-
- begin
-
- gotoxy(x+length(str),y);
-
- lowvideo;
- for i := length(str) to maxlen do
- write('_');
- {display underscores out to the
- end of the field. this lets
- the user know when he is near
- the end of line}
- normvideo;
-
- repeat
- if col > length(str) then
- col := length(str)+1; {if i am beyond end of string,
- move cursor back to first legal
- position}
-
- gotoxy(x+col-1,y);
- c := getkey; {position the cursor and wait for an
- input from the user}
-
-
- case c of {switch on the key and do what
- ever is needed}
-
- HOME: col := 1;
-
-
- ENDLINE: col := length(str) + 1;
-
-
- TAB: repeat
- col := col + 1;
- until (col mod 4) = 0;
-
-
- LEFT: if col > 1 then
- col := col - 1
- else
- write(^G);
-
-
- RIGHT: col := col + 1;
-
-
- INS: if col <= length(str) then
- begin
- insert(' ',str,col);
- write(copy(str,col,99));
- end;
-
-
- DEL: if col <= length(str) then
- begin
- delete(str,col,1);
- write(copy(str,col,99));
- lowvideo;
- write('_');
- normvideo;
- end
- else
- write(^G);
-
-
- BACKSPC: if col > 1 then
- begin
- col := col - 1;
- delete(str,col,1);
- write(^H+copy(str,col,99));
- lowvideo;
- write('_');
- normvideo;
- end
- else
- write(^G);
-
-
- NEWLINE: col := 1;
-
-
- UP,
- DOWN,
- PGUP,
- PGDN,
- ESC,
- F1..F10: ;
-
-
- else begin
- if col = (maxlen-7) then
- begin
- sound(1200); {make a quick beep when
- getting close to the end
- of a line}
- delay(100);
- nosound;
- end;
-
- if col > length(str) then
- if length(str) < maxlen then
- begin
- str := str + c;
- col := col + 1;
- write(c); {add to end of string
- if there is room}
- end
- else
- write(^G) {beep if no more room}
- else
- begin
- str[col] := c;
- col := col + 1; {replace in middle of string}
- write(c);
- end;
-
- end;
- end;
-
- until c in [UP,DOWN,PGUP,PGDN,NEWLINE,ESC,F1..F10];
-
-
- gotoxy(x+length(str),y);
- clreol; {input is finished, remove the extra
- underscores from the screen}
- end;
-
-
- var
- buffer: anystring;
- key: char;
-
- begin {example}
- clrscr;
- gotoxy(1,1);
- write('Name: [..........]');
-
- edit_string(8,1, 1,buffer, key, 10);
-
- writeln;
- writeln('You typed: <',buffer,'>');
- end.