全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:1021
推到 Plurk!
推到 Facebook!

對於記錄類型的迷惑,請教

答題得分者是:P.D.
qiziyh
一般會員


發表:2
回覆:7
積分:1
註冊:2008-09-29

發送簡訊給我
#1 引用回覆 回覆 發表時間:2009-09-06 15:48:22 IP:222.219.xxx.xxx 訂閱

[code delphi]
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TPeople = record
Name : String;
Age : Integer;
Adress : String;
PhoneNumber : String;
end;

type
。。
。。
。。

private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
FileName : String;
RWFileName : file of Tpeople;
People : TPeople;

implementation

[/code]
請問上面的代碼中,我聲明了記錄類型Tpeople,在後面我把RWFileName聲明為自己定義的記錄類型文件,這個語法哪裡錯誤了嗎?為什麼在編譯的時候老是提示[DCC Error] Unit1.pas(16): E2155 Type 'TPeople' needs finalization - not allowed in file type呢?在網上查了很多資料,似乎都是這種寫法啊,為什麼我寫出來就編譯不過去呢?請原諒如此的無知問題,實在是找不到哪裡語法有錯誤,請教了
P.D.
版主


發表:603
回覆:4038
積分:3874
註冊:2006-10-31

發送簡訊給我
#2 引用回覆 回覆 發表時間:2009-09-07 00:03:12 IP:61.67.xxx.xxx 未訂閱
這是 Delphi Help 全文(引述..), 紅色的部份注意
或者使用 array[1..20] of Char 亦可

A file is an ordered set of elements of the same type. Standard I/O routines use the predefined TextFile or Text type, which represents a file containing characters organized into lines. For more information about file input and output, see Standard routines and I/O.
To declare a file type, use the syntax
type fileTypeName = file of type
where fileTypeName is any valid identifier and type is a fixed-size type. Pointer types隝hether implicit or explicit铘re not allowed, so a file cannot contain dynamic arrays, long strings, classes, objects, pointers, variants, other files, or structured types that contain any of these.
For example,
type
PhoneEntry = record
FirstName, LastName: string[20];
PhoneNumber: string[15];
Listed: Boolean;
end;
PhoneList = file of PhoneEntry;
declares a file type for recording names and telephone numbers.
You can also use the file of ... construction directly in a variable declaration. For example,
var List1: file of PhoneEntry;
The word file by itself indicates an untyped file:
var DataFile: file;
For more information, see Untyped files.
Files are not allowed in arrays or records.
qiziyh
一般會員


發表:2
回覆:7
積分:1
註冊:2008-09-29

發送簡訊給我
#3 引用回覆 回覆 發表時間:2009-09-07 11:27:27 IP:65.49.xxx.xxx 訂閱
感谢PD版主,终于明白了,呵呵,困惑了好几天啊,谢谢,谢谢
系統時間:2024-04-30 3:08:36
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!