unit Unit
interface
uses
Windows
Dialogs
type
TForm
Button
Button
procedure Button
procedure Button
end;
var
Form
implementation
{$R *
type
TIntArray = array of Integer;
{把 Integer 數組寫入文件的函數}
function IntArrToFile(ns: TIntArray; FileName: string): Boolean;
var
IntFile: file of Integer;
n: Integer;
begin
try
AssignFile(IntFile
if FileExists(FileName) then Reset(IntFile) else Rewrite(IntFile);
Seek(IntFile
for n in ns do Write(IntFile
Result := True;
finally
CloseFile(IntFile);
end;
end;
{讀取的函數}
function FileToIntArr(FileName: string; var ns: TIntArray): Integer;
var
IntFile: file of Integer;
begin
if not FileExists(FileName) then Exit(
AssignFile(IntFile
Reset(IntFile);
while not Eof(IntFile) do
begin
SetLength(ns
Read(IntFile
end;
CloseFile(IntFile);
Result := Length(ns);
end;
{寫入測試}
procedure TForm
var
IntArr: TIntArray;
begin
SetLength(IntArr
IntArr[
IntArr[
IntArr[
IntArrToFile(IntArr
end;
{讀取測試}
procedure TForm
var
IntArr: TIntArray;
n: Integer;
begin
FileToIntArr(
for n in IntArr do ShowMessage(IntToStr(n));
end;
From:http://tw.wingwit.com/Article/program/Delphi/201311/8432.html