線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:1043
推到 Plurk!
推到 Facebook!

關於Read你一些問題!!!

答題得分者是:pceyes
with
一般會員


發表:6
回覆:5
積分:2
註冊:2008-06-25

發送簡訊給我
#1 引用回覆 回覆 發表時間:2008-06-28 20:07:14 IP:218.19.xxx.xxx 訂閱
今天看課本的時候看到一函數名 Read 其解釋為(從文件中讀取數據)...
名位可以解釋一下這個Read是怎么用的嗎!!感謝...小弟剛學Delphi不久,見笑了.
------
!!^_^..我愛Delphi*^_^*!!
pceyes
尊榮會員


發表:70
回覆:657
積分:1140
註冊:2003-03-13

發送簡訊給我
#2 引用回覆 回覆 發表時間:2008-06-29 01:11:05 IP:220.141.xxx.xxx 訂閱
Read reads data from a file.
Unit
System
Category
text file routines
Delphi syntax:
Typed files:
procedure Read(F , V1 [, V2,...,Vn ] );
Text files:
procedure Read( [ var F: Text; ] V1 [, V2,...,Vn ] );
Description
The Read procedure can be used in Delphi code in the following ways.
For typed files, it reads a file component into a variable.
For text files, it reads one or more values into one or more variables.
With a type string variable:
Read reads all characters up to, but not including, the next end-of-line marker or until Eof(F) becomes true; it does not skip to the next line after reading. If the resulting string is longer than the maximum length of the string variable, it is truncated.
After the first Read, each subsequent Read sees the end-of-line marker and returns a zero-length string.
Use multiple Readln calls to read successive string values.
When the extended syntax is enabled, Read can read null-terminated strings into zero-based character arrays.
With a type character variable:
Read reads one character from the file and assigns it to the variable. If CRLF mode is enabled and Eof(F) was true before Read was executed, the value Chr(26) (a Ctrl-Z character) is assigned to the variable. (To enable CRLF mode, use SetLineBreakStyle.)
With type integer or type real variables:
Read skips any blanks, tabs, or end-of-line markers preceding the numeric string.
If the numeric string does not conform to the expected format, an I/O error occurs; otherwise, the value is assigned to the variable.
The next Read starts with the blank, tab, or end-of-line marker that terminated the numeric string.
example :
var
F1, F2: TextFile;
Ch: Char;
begin
if OpenDialog1.Execute then begin
AssignFile(F1, OpenDialog1.Filename);
Reset(F1);
if SaveDialog1.Execute then begin
AssignFile(F2, SaveDialog1.Filename);
Rewrite(F2);
while not Eof(F1) do
begin
Read(F1, Ch);
Write(F2, Ch);
end;
CloseFile(F2);
end;
CloseFile(F1);
end;
end;
------
努力會更接近成功
with
一般會員


發表:6
回覆:5
積分:2
註冊:2008-06-25

發送簡訊給我
#3 引用回覆 回覆 發表時間:2008-06-29 13:52:33 IP:58.62.xxx.xxx 訂閱
雖然不是很明白,不過還是感謝你,我會把此段源碼搞清楚了.
------
!!^_^..我愛Delphi*^_^*!!
系統時間:2024-05-07 2:40:01
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!