没分也帮:在窗体中放一Listbox和一按钮,所有程序如下:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
ListBox1: TListBox;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
MyStringList: TStringList;
FileName: String;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
myfile: array [1..10] of String;
i: Integer;
begin
MyStringList := TStringList.Create;
for i := 1 to 10 do
begin
myfile := IntToStr(i);
MyStringList.Add(Myfile);
end;
MyStringList.SaveToFile(FileName + '123.dat');//123.dat是生成的文件
MyStringList.Free;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
FileName := GetCurrentDir();
if FileExists(FileName + '123.dat') then
begin
MyStringList := TStringList.Create;
MyStringList.LoadFromFile(FileName + '123.dat');
ListBox1.Items.Text := MyStringList.Text;
MyStringList.Free;
end;
end;
end.