Free Pascal CRT 单元常量、变量、函数、过程详解_第1页
Free Pascal CRT 单元常量、变量、函数、过程详解_第2页
Free Pascal CRT 单元常量、变量、函数、过程详解_第3页
Free Pascal CRT 单元常量、变量、函数、过程详解_第4页
Free Pascal CRT 单元常量、变量、函数、过程详解_第5页
已阅读5页,还剩8页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、类型,变量,常量:颜色定义: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 = Tru

2、e;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系统屏幕模式

3、: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一切转到屏幕代

4、替。如果屏幕包含一个窗口,全部写在窗口代替。注:功能接近于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

5、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 righ

6、t 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

7、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

8、:=10 downto 1 dobeginWriteLn(i;Delay(1000; Wait one secondend;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

9、9;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指纵坐标(从窗口顶部开始不包括标题栏。原来的位置(程序编译后一运行

10、时是(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 de

11、monstrate 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在当前光标位置插入一个空行,当前行以下的自动向下滚动一行,最后一行从窗

12、口中消失,光标不移动。例子: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'GotoX

13、Y(1,10;end.11、Function KeyPressed : Boolean;KeyPressed函数扫描键盘缓冲区,确认是否有键按下。如果有,则返回True,如果没有,则返回False。Shift、Alt、Ctrl不包括在内。例子:Program Example2; uses Crt; Program to demonstrate the KeyPressed function. begin WriteLn('Waiting until a key is pressed' repeat until KeyPressed; The key is not Read, s

14、o 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. var i : longint; begin WriteL

15、n('You will hear some tones from your speaker' while (i<15000 do begin inc(i,500; Sound(i; Delay(100; end; WriteLn('Quiet now!' NoSound; Stop noise end. 15、Function ReadKey : Char; ReadKey 从键盘缓冲区读取一个键并返回。如果功能键被按下,则返回 0(ASCII 码) , 如果执行该函数后并未有键按下,则程序将一直等到有键按下才继续执行下面的 代码。Linux 下的键盘映射

16、可能会导致错误并由 ReadKey 报告,因此需谨慎使用 ReadKey。 例子: Program Example3; uses Crt; Program to demonstrate the ReadKey function. var ch : char; begin writeln('Press Left/Right, Esc=Quit' repeat ch:=ReadKey; case ch of #0 : begin ch:=ReadKey; Read ScanCode case ch of #75 : WriteLn('Left' #77 : Writ

17、eLn('Right' end; end; #27 : WriteLn('ESC' end; until ch=#27 Esc end. 16、Procedure Sound (hz : word; 使扬声器发出 hz 赫兹的声音。在 Windows 下,系统播放声音的频率参数被忽略。 (意思好像是播放的声音的频率和参数有点差距)在在其他操作系统下,此过 程可能不会执行。 17、Procedure TextBackground (CL: Byte; TextBackground 根据参数 CL 设置背景颜色(执行后输入输出文本的) ,CL 为预定 的颜色常量之一

18、。 例子: Program Example13; uses Crt; Program to demonstrate the TextBackground function. begin TextColor(White; WriteLn('This is written in with the default background color' TextBackground(Green; WriteLn('This is written in with a Green background' TextBackground(Brown; WriteLn('T

19、his is written in with a Brown background' TextBackground(Black; WriteLn('Back with a black background' end. 18、Procedure TextColor (CL: Byte; TextColor 根据 CL 设置前景色(执行后输入输出文本的颜色) ,CL 为预定的颜色 常量之一。 例子: Program Example12; uses Crt; Program to demonstrate the TextColor function. begin WriteL

20、n('This is written in the default color' TextColor(Red; WriteLn('This is written in Red' TextColor(White; WriteLn('This is written in White' TextColor(LightBlue; WriteLn('This is written in Light Blue' end. 19、procedure TextMode(Mode: Integer; TextMode 设置屏幕文本模式(即屏幕的行和

21、列数,较低的字节是用于设置 VGA 文本 模式。这个过程只在 DOS 下执行。 20、Function WhereX : Byte; WhereX 返回当前光标的横坐标(相对于当前窗口) 。 例子: Program Example7; uses Crt; Program to demonstrate the WhereX and WhereY functions. begin Writeln('Cursor postion: X=',WhereX,' Y=',WhereY; end. 21、Function WhereY : Byte; WhereY 返回当前光标的纵坐标(相对于当前窗口) 。 例子: Program Example7; uses Crt; Program to demonstrate the WhereX and WhereY functions. begin Writeln('Cursor postion: X=',Wher

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

最新文档

评论

0/150

提交评论