請教各位 如何將 Array 的資料存檔 |
|
ckc8088
一般會員 發表:3 回覆:7 積分:2 註冊:2002-07-11 發送簡訊給我 |
|
hagar
版主 發表:143 回覆:4056 積分:4445 註冊:2002-04-14 發送簡訊給我 |
參考:
I need to save a array of record variable. Which is the
best way to do it?
It's possible read the file with data-aware component?
A:
It's not very Delphi-like (but then, neither are Pascal
records really), but you can read and write records to
and from a file using the standard Pascal file manipulation
procedures like so:
type TMyRec = record ; Field1 : integer ; Field2 : string ; end ; TMyRecArray = array [0..9] of TMyRec ; var MyArray : TMyRecArray ; MyRec : TMyRec ; RecFile : file of TMyRec ; begin {...some code that intializes MyArray goes here...} AssignFile( RecFile, 'MYREC.FIL' ) ; ReWrite( RecFile ) ; for i := 0 to 9 do begin Write( RecFile, MyRec[i] ) ; end ; CloseFile( RecFile ) ; end;You can also use Read() to get a record from such a file, and Seek() to move to a particular record in the file (starting with 0). For more details on these have a look at I/O Routines in the Delphi on-line help. If you want to do this with the Data Aware components, you'll have to construct a database where the database records reflect the structure of your Pascal records, then provide translation routines to get the data from one to the other. I'm not aware of any way to do this directly, but it could certainly be encapsulated in a component. |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |