qp.hlp (Table of Contents; Topic list)
Important Notice
The pages on this site contain documentation for very old MS-DOS software, purely for historical purposes. If you're looking for up-to-date documentation, particularly for programming, you should not rely on the information found here, as it will be woefully out of date.
TEXTBOX.PAS
  Example Contents Index                                    Back
 
PROGRAM textbox;
 
{ TEXTBOX.PAS demonstrates the following text procedures and functions:
 
    ClrEol    DelLine    InsLine    WhereX    Window
    ClrScr    GotoXY     ReadKey    WhereY
 
  It also uses the Hi and Lo functions.
}
 
USES
    Crt;
 
CONST
    program_name = 'TEXTBOX ';
    program_desc = 'demonstrates CRT text routines.';
 
VAR
    ch           : Char;
    x_max, y_max : Byte;
    x_min, y_min : Byte;
    init_max     : Word;
    i            : Byte;
    done         : Boolean;
    x, y         : Byte;
 
BEGIN
 
    ClrScr;
    Writeln( program_name, program_desc );
    Writeln;
    Writeln( 'Type into the box.  Your typing will wrap around ' +
             'to the next line when' );
    Writeln( 'you reach the edge. Use the arrow keys to navigate.' );
    GotoXY( 1, Hi( WindMax ) + 1 );
    Writeln( '<F1=Clear to end of line><F2=Insert line>'+
             '<F3=Delete line><ESC = Quit>' );
 
    init_max := WindMax;
 
    { Draw a border around the window area. }
    x_min := 1 + Lo( WindMax ) DIV 4;
    y_min := 1 + Hi( WindMax ) DIV 4;
    x_max := x_min + Lo( WindMax ) DIV 2;
    y_max := y_min + Hi( WindMax ) DIV 2;
    GotoXY( x_min, y_min );
    FOR i := x_min TO x_max DO    { top }
        Write( '_' );
    GotoXY( x_min, y_max );
    FOR i := x_min TO x_max DO    { bottom }
        Write( '-' );
    FOR i := y_min + 1 TO y_max DO
        BEGIN
        GotoXY( x_min, i );
        Write( '|' );    { left side }
        GotoXY( x_max, i );
        Write( '|' );    { right side }
        END;
 
    x_min := x_min + 1;
    x_max := x_max - 1;
    y_min := y_min + 1;
    y_max := y_max - 1;
 
    { Create a window in the center of the screen }
    Window( x_min, y_min, x_max, y_max );
 
    done := False;
 
    REPEAT
        ch := ReadKey;
        CASE ch OF
            #0 : BEGIN { extended key codes }
                 ch := ReadKey;
                 CASE ch OF
                     #59 : { F1 } ClrEol;
                     #60 : { F2 } InsLine;
                     #61 : { F3 } DelLine;
                     #71 : { home }
                           GotoXY( 1, 1 );
                     #72 : { up arrow }
                           GotoXY( WhereX, WhereY - 1 );
                     #75 : { left arrow }
                           GotoXY( WhereX - 1, WhereY );
                     #77 : { right arrow }
                           GotoXY( WhereX + 1, WhereY );
                     #79 : { end }
                           GotoXY( x_max - x_min + 1, y_max - y_min + 1);
                     #80 : { down arrow }
                           GotoXY( WhereX, WhereY + 1 );
                     #83 : { DEL }
                           GotoXY( WhereX - 1, WhereY );
                     END; { function key values }
                 END; { extended key codes }
            #13 : BEGIN
                  x := WhereX; y := WhereY;
                  IF (WhereY = y_max - y_min + 1) THEN
                      BEGIN
                      GotoXY( 1, 1 );
                      DelLine;
                      GotoXY( 1, y_max - y_min + 1 );
                      InsLine;
                      END
                  ELSE GotoXY( 1, WhereY + 1 );
                  END;
            #27 : done := True;
            ELSE Write( ch );
            END; { case }
    UNTIL done;
 
    { Restore initial window }
    Window( 1, 1, Lo( init_max ), Hi( init_max ) );
    ClrScr;
 
END.