;of text: ''''); Readln(s); Writeln(''''You typed: '''',s); Writeln(''''Hit <Enter> to exit''''); Readln; end; ----------------------------------------------------------------------------- SeekEof 测试档案是否结束. ----------------------------------------------------------------------------- Unit System 函数原型 function SeekEof [ (var F: Text) ]: Boolean; 范例 var f : System.TextFile; i, j, Y : Integer; begin AssignFile(f,''''TEST.TXT''''); Rewrite(f); { Create a file with 8 numbers and some whitespace at the ends of the lines } Writeln(f,''''1 2 3 4 ''''); Writeln(f,''''5 6 7 8 ''''); Reset(f); { Read the numbers back. SeekEoln returns TRUE if there are no more numbers on the current line; SeekEof returns TRUE if there is no more text (other than whitespace) in the file. } Y := 5; while not SeekEof(f) do begin if SeekEoln(f) then Readln; { Go to next line } Read(f,j); Canvas.TextOut(5, Y, IntToStr(j)); Y := Y + Canvas.TextHeight(IntToStr(j)) + 5; end; end; ----------------------------------------------------------------------------- SeekEoln 测试档案中行是否结束. ----------------------------------------------------------------------------- Unit System 函数原型 function SeekEoln [ (var F: Text) ]: Boolean; Example var
f : System.TextFile; i, j, Y : Integer; begin AssignFile(f,''''TEST.TXT''''); Rewrite(f); { Create a file with 8 numbers and some whitespace at the ends of the lines } Writeln(f,''''1 2 3 4 ''''); Writeln(f,''''5 6 7 8 ''''); Reset(f); { Read the numbers back. SeekEoln returns TRUE if there are no more numbers on the current line; SeekEof returns TRUE if there is no more text (other than whitespace) in the file. }
Y := 5; while not SeekEof(f) do begin if SeekEoln(f) then Readln; { Go to next line } Read(f,j); Canvas.TextOut(5, Y, IntToStr(j)); Y := Y + Canvas.TextHeight(IntToStr(j)) + 5; end; end; ## SeekEoln, SeekEof Example ----------------------------------------------------------------------------- SetTextBuf 指定 I/O buffer 给 text file. ----------------------------------------------------------------------------- Unit System 函数原型 procedure SetTextBuf(var F: Text; var Buf [ ; Size: Integer] ); 范例 uses Dialogs; var F, FTwo: System.TextFile; Ch: Char; Buf: array[1..4095] of Char; { 4K buffer } begin if OpenDialog1.Execute then begin AssignFile(F, ParamStr(1)); { Bigger buffer for faster reads } SetTextBuf(F, Buf); Reset(F); { Dump text file into another file } AssignFile(FTwo, ''''WOOF.DOG''''); Rewrite(FTwo); while not Eof(f) do begin Read(F, Ch); Write(FTwoCh); end; System.CloseFile(F); System.CloseFile(FTwo); end; end; ----------------------------------------------------------------------------- Write 写入档案. ----------------------------------------------------------------------------- Unit System
var Stream: TBlobStream; S: string; begin with Table1 do begin
Edit;
Stream := CreateBlobStream(FieldByName(''''Notes''''), bmReadWrite); try Stream.Seek(0, 2); {Seek 0 bytes from the stream''''s end point} S := '''' This line will be added to the end.''''; Stream.Write(PChar(S), Length(S)); finally Stream.Free; end; Post; end; end; ----------------------------------------------------------------------------- Writeln 写入档案. ----------------------------------------------------------------------------- Unit System 函数原型 procedure Writeln([ var F: Text; ] P1 [, P2, ...,Pn ] ); 范例 var s : string; begin Write(''''Enter a line of text: ''''); Readln(s); Writeln(''''You typed: '''',s); Writeln(''''Hit <Enter> to exit''''); Readln; end; ======================================= Transfer routines 转换函式 ======================================= Chr 将 Byte 转为字元. ----------------------------------------------------------------------------- Unit System 函数原型 function Chr(X: Byte): Char; 范例 begin Canvas.TextOut(10, 10, Chr(65)); { The letter ''''A''''} end; Example procedure TForm1.ComboBox1KeyPress(Sender: TObject; var Key: Char);
var Found: boolean; i,SelSt: Integer; TmpStr: string; begin { first, process the keystroke to obtain the current string } { This code requires all items in list to be uppercase} if Key in [''''a''''..''''z''''] then Dec(Key,32); {Force Uppercase only!} with (Sender as TComboBox) do begin SelSt := SelStart; if (Key = Chr(vk_Back)) and (SelLength <> 0) then TmpStr := Copy(Text,1,SelStart)+Copy(Text,SelLength+SelStart+1,255)