Delphi中將檔案流的資料寫入動態陣列

2021-03-31 21:33:16 字數 552 閱讀 6723

var

myfile:tfilestream;

mybuf:array of pchar;

begin

myfile:=tfilestream.create('d:/a.txt',fmopenreadwrite);

setlength(mybuf,myfile.size);

myfile.readbuffer(mybuf[0],myfile.size);

//delete(string(mybuf),1,myfile.size-4);

showmessage(pchar(mybuf));

此**也是在摸索中搞出來的,不是非常的理解,大概理解是這樣的,因為delphi中的靜態陣列是在執行前就分配好了,所以它的變數位址就是此陣列的第一維位址,即沒有描述部份,故它的sizeof為1個位元組,而動態陣列是在執行期間動態分配乙個記憶體塊,所以它的變數位址部分需要乙個描素部分,故它的sizeof為四個位元組,用於存放描素表,所以在 readbuffet時,需要採用此陣列的第一維位址為起始位址,才不會導致溢位,也不知這樣理解是否正確,暫且這樣理解吧,以後有機會再深入了解

Delphi中將檔案流的資料寫入動態陣列

var myfile tfilestream mybuf array of pchar begin myfile tfilestream.create d a.txt fmopenreadwrite setlength mybuf,myfile.size myfile.readbuffer mybu...

簡單的檔案流寫讀

region 檔案流寫入 private void writefileinfo stream myfile.open filemode.openorcreate byte bytearr stream.write bytearr,0,bytearr.length 1 stream.flush str...

delphi寫的時鐘

很久以前寫的程式了,要整理機器,只好放到這了 unit unit1 inte ce uses windows,messages,sysutils,variants,classes,graphics,controls,forms,dialogs,extctrls,stdctrls type tform...