Posted by John E Goings on 1998-03-03
Attached is a copy of an editor I have written. I've ran it and am
stumped as to why the keys are not doing what I expected.
Backspace, arrows are rewriting lines and they should not.
Please help. I am frustrated and this is due within 48 hours.
Thanks in advance.
JohnG
JE-Goings@xxx.xxx
program editor;
Uses crt;
Const
Rows = 24;
Characters = 79;
Type
Columns = String[Characters];
ScreenArray = array[1..Rows] of Columns;
Var
Screen : ScreenArray;
Line : Columns;
Xcoords,Ycoords : Integer;
Key : Char;
TypeOver : Boolean;
{Procedures}
procedure Initialize;
Var
I,A : Integer;
Begin
ClrScr;
For A := 1 to 24 do
Begin
Screen[A][0] := chr(79);
For I := 1 to 79 do
Screen[A][I] := ' ';
End;
For I := 1 to 79 do
Line[I] := ' ';
Line[0] := chr(79)
End;
procedure SetCursor;
Begin
GotoXY(Xcoords,Ycoords)
End;
procedure Alter;
Var
I : Integer;
Begin
Screen[Ycoords] := Line;
For I := 1 to 79 do
Line[I] := ' '
End;
procedure RedrawRow;
Var
I : Integer;
Begin
GotoXY(1,Ycoords);
For I := 1 to Characters do
Write(Line[I]);
GotoXY(Xcoords,Ycoords)
End;
procedure RedrawScreen;
Var
I,A,Xhold,Yhold : Integer;
Begin
Xhold := WhereX;
Yhold := WhereY;
Clrscr;
For I := 1 to Rows do
Begin
For A := 1 to Characters do
Write(Screen[I][A]);
Writeln
End;
Xcoords := 1{Xhold}; {Repositions cursor to beginning}
Ycoords := 1{Yhold};
SetCursor
End;
procedure EnterKey;
Begin
Alter;
Xcoords := 1;
Ycoords := Ycoords + 1;
SetCursor
End;
procedure MoveRight;
Begin
If Xcoords < 79 then
Xcoords := Xcoords + 1
Else
If Xcoords = 79 then
Begin
Xcoords := 1;
Ycoords := Ycoords + 1
End;
SetCursor
End;
procedure MoveLeft;
Begin
If Xcoords > 1 then
Xcoords := Xcoords - 1
Else
If Xcoords = 1 then
If Ycoords > 1 then
Begin
Xcoords := 79;
Ycoords := Ycoords - 1
End;
SetCursor
End;
procedure MoveUp;
Begin
If Ycoords > 1 then
Ycoords := Ycoords - 1;
SetCursor
End;
procedure MoveDown;
Begin
If Ycoords < 24 then
Ycoords := Ycoords + 1;
SetCursor
End;
procedure ScreenChar;
Begin
If TypeOver Then
Line[Xcoords] := Key
Else
Begin
Insert(Key,Line,Xcoords);
End;
RedrawRow;
MoveRight
End;
procedure BackSpace;
Begin
MoveLeft;
Delete(Line,Xcoords,1);
Insert(' ',Line,79);
Alter;
RedrawRow;
End;
procedure InsertTog;
Begin
If TypeOver = False then
TypeOver := True
Else
TypeOver := False
End;
procedure HandleKey;
Begin
Key := ReadKey;
Case Key of
Chr(27) : ; {Case Checks for Esc-Key and Exits Statement}
chr(13) : EnterKey;
chr(8) : BackSpace;
chr(0) : Begin
Key := ReadKey;
Case Key of
chr(72) : MoveUp;
chr(75) : MoveLeft;
chr(77) : MoveRight;
chr(80) : MoveDown;
chr(82) : InsertTog;
chr(59) : RedrawScreen { F1-Key }
End
End;
Else
ScreenChar;
End
End;
Begin
Initialize;
Xcoords := 1;
Ycoords := 1;
Typeover := False;
Key := ' ';
While Key <> chr(27) do
HandleKey
end.
Previous post | Next post | Timeline | Home