利用TStringList的LoadFromFile方法可以很容易的实现你的要求.
实际上,你也不一定非要保存到字符串数组中,相比之下TStringList更好用.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
const
MAXLINE=2000;
var
Form1: TForm1;
MyArray:Array[0..MAXLINE]of String;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
var
theStringList:TStringList;
i:Integer;
begin
theStringList:=TStringList.Create();
theStringList.LoadFromFile('C:/Autoexec.bat');
for i:=0 to theStringList.Count-1 do
MyArray:=theStringList.Strings;
theStringList.Free;
end;
end.