Free Pascal CRT 单元常量、变量、函数、过程详解

  • 格式:doc
  • 大小:57.00 KB
  • 文档页数:9

类型,变量,常量:颜色定义:Black = 0;Blue = 1;Green = 2;Cyan = 3;Red = 4;Magenta = 5;Brown = 6;LightGray = 7;DarkGray = 8;LightBlue = 9;LightGreen = 10;LightCyan = 11;LightRed = 12;LightMagenta = 13;Yellow = 14;White = 15;Blink = 128;杂项常数:TextAttr: Byte = $07;TextChar: Char = ' ';CheckBreak: Boolean = True;CheckEOF: Boolean = False;CheckSnow: Boolean = False;DirectVideo: Boolean = False;LastMode: Word = 3;WindMin: Word = $0;WindMax: Word = $184f;ScreenWidth = 80;ScreenHeight = 25;一些变量与Turbo Pascal兼容,但在Free Pascal中,他们没有用处。

varcheckbreak : boolean;checkeof : boolean;checksnow : boolean;以下常量定义在DOS系统屏幕模式:Constbw40 = 0;co40 = 1;bw80 = 2;co80 = 3;mono = 7;TextAttr变量控制被写入屏幕字符的属性。

var TextAttr : byte;DirectVideo变量控制控制在屏幕上书写。

如果为True,游标通过直接设置端口访问,如果为False,然后使用BIOS,这只是DOS下的定义。

Lastmode变量告诉你哪种模式是最后被屏幕选择的,它的定义只是基于DOS。

var lastmode : Word;过程和函数:1、Procedure AssignCrt (Var F: Text);AssignCrt指定一个文件F到屏幕。

写入文件F一切转到屏幕代替。

如果屏幕包含一个窗口,全部写在窗口代替。

注:功能接近于Writeln。

例子:Program Example1;uses Crt;varF : Text;beginAssignCrt(F);Rewrite(F);WriteLn(F,'This is written to the Assigned File');Close(F);end.2、Procedure CursorBig;使光标(不是鼠标图形)成为大矩形,在LINUX上不可用。

如果不明白的话,运行下面这个程序:Program df;BeginReadln;End.仔细观察效果后,在运行下面这个程序:Program df;Uses crt;BeginCursorBig;Readln;End.仔细对比后你就会知道什么意思了。

例子:Program Example9;uses Crt;{ Program to demonstrate the ClrEol function. }var I,J : integer;beginFor I:=1 to 15 doFor J:=1 to 80 dobegingotoxy(j,i);Write(j mod 10);end;Window(5,5,75,12);Write('This line will be cleared from',' here till the right of the window');GotoXY(27,WhereY);ReadKey;ClrEol;WriteLn;end.3、Procedure ClrScr;ClrScr清除当前窗口(使用当前的颜色),并设置在当前窗口左上角的光标。

(就是清屏)例子:Program Example8;uses Crt;{ Program to demonstrate the ClrScr function. }beginWriteln('Press any key to clear the screen');ReadKey;ClrScr;Writeln('Have fun with the cleared screen');end.4、Procedure CursorOff;隐藏光标。

在LINUX上无效。

5、Procedure CursorOn;显示光标。

在LINUX上无效。

6、Procedure Delay (DTime: Word);延迟等待指定的毫秒数。

指定的秒数是个近似值(即可能有偏差),如果系统负载高,可能被关闭。

例子:Program Example15;uses Crt;{ Program to demonstrate the Delay function. }vari : longint;beginWriteLn('Counting Down');for i:=10 downto 1 dobeginWriteLn(i);Delay(1000); {Wait one second}end;WriteLn('BOOM!!!');end.7、Procedure DelLine;DelLine删除当前行。

当前行一下的自动向上移动一行,并且在当前窗口底部插入一空行,光标不移动。

例子:Program Example10;uses Crt;{ Program to demonstrate the InsLine function. }beginClrScr;WriteLn;WriteLn('Line 1');WriteLn('Line 2');WriteLn('Line 2');WriteLn('Line 3');WriteLn;WriteLn('Oops, Line 2 is listed twice,',' let''s delete the line at the cursor postion');GotoXY(1,3);ReadKey;DelLine;GotoXY(1,10);end.8、Procedure GotoXY (X: Byte; Y: Byte);光标移动到(x,y)处,x指横坐标,y指纵坐标(从窗口顶部开始不包括标题栏)。

原来的位置(程序编译后一运行时)是(1,1),窗口的左上角。

例子:Program Example6;uses Crt;{ Program to demonstrate the GotoXY function. }beginClrScr;GotoXY(10,10);Write('10,10');GotoXY(70,20);Write('70,20');GotoXY(1,22);end.9、Procedure HighVideo;高亮显示文本(不是窗口中的所有文本,执行该过程后,读入输出的文本才高亮显示)它设置的视频属性高强度位。

例子:Program Example14;uses Crt;{ Program to demonstrate the LowVideo, HighVideo, NormVideo functions. } beginLowVideo;WriteLn('This is written with LowVideo');HighVideo;WriteLn('This is written with HighVideo');NormVideo;WriteLn('This is written with NormVideo');end.10、Procedure InsLine;InsLine在当前光标位置插入一个空行,当前行以下的自动向下滚动一行,最后一行从窗口中消失,光标不移动。

例子:Program Example10;uses Crt;{ Program to demonstrate the InsLine function. }beginClrScr;WriteLn;WriteLn('Line 1');WriteLn('Line 3');WriteLn;WriteLn('Oops, forgot Line 2, let''s insert at the cursor postion'); GotoXY(1,3);ReadKey;InsLine;Write('Line 2');GotoXY(1,10);end.11、Function KeyPressed : Boolean;KeyPressed函数扫描键盘缓冲区,确认是否有键按下。

如果有,则返回True,如果没有,则返回False。

Shift、Alt、Ctrl不包括在内。

例子:Program Example2;uses Crt;{ Program to demonstrate the KeyPressed function. }beginWriteLn('Waiting until a key is pressed');repeatuntil KeyPressed;{ The key is not Read,so it should also be outputted at the commandline}end.12、Procedure LowVideo;低亮度显示文本。

13、Procedure NormVideo;NormVideo以正常亮度显示文本,为默认值。

14、Procedure NoSound;让扬声器停止发出声音。

并不是所有操作系统都支持。

例子:Program Example16;uses Crt;{ Program to demonstrate the Sound and NoSound function. }vari : longint;beginWriteLn('You will hear some tones from your speaker');while (i<15000) dobegininc(i,500);Sound(i);Delay(100);end;WriteLn('Quiet now!');NoSound; {Stop noise}end.15、Function ReadKey : Char;ReadKey从键盘缓冲区读取一个键并返回。