procedure TForm1.FormCreate(Sender: TObject);
begin
AssignFile(txtFile,'name.txt');
if not FileExists('name.txt') then Rewrite(txtFile);
end; procedure TForm1.Edit1Change(Sender: TObject);
var
s1, s2:WideString;
i: Integer;
begin
i := Length(WideString(Edit1.Text));
ListBox1.Clear; Reset(txtFile);
try
while not Eof(txtFile) do
begin
ReadLn(txtFile,s1);
s2 := Copy(s1,1,i);
if s2 = Edit1.Text then ListBox1.Items.Add(s1);
end;
finally
CloseFile(txtFile);
end;
if ListBox1.Count > 0 then ListBox1.Visible := True;
end; procedure TForm1.Edit1Exit(Sender: TObject);
var
s1:WideString;
i: Integer;
begin
if Trim(Edit1.Text) = '' then Exit;
for i:= 0 to ListBox1.Items.Count - 1 do
if ListBox1.Items[i] = Edit1.Text then Exit;
Append(txtFile);
try
WriteLn(txtFile,Trim(Edit1.Text));
finally CloseFile(txtFile);
end;
ListBox1.Visible := False;
end; 代码主要就是这些,txtFile:TextFile声明在private里
类似于ie的Cookie,呵呵,就是我的Cookie显示在一个ListBox里,ListBox长度不能动态改变,感觉这样不好没什么技术难度,更不能说完美,所以贴在这里期望起个抛砖引玉的作用
begin
AssignFile(txtFile,'name.txt');
if not FileExists('name.txt') then Rewrite(txtFile);
end; procedure TForm1.Edit1Change(Sender: TObject);
var
s1, s2:WideString;
i: Integer;
begin
i := Length(WideString(Edit1.Text));
ListBox1.Clear; Reset(txtFile);
try
while not Eof(txtFile) do
begin
ReadLn(txtFile,s1);
s2 := Copy(s1,1,i);
if s2 = Edit1.Text then ListBox1.Items.Add(s1);
end;
finally
CloseFile(txtFile);
end;
if ListBox1.Count > 0 then ListBox1.Visible := True;
end; procedure TForm1.Edit1Exit(Sender: TObject);
var
s1:WideString;
i: Integer;
begin
if Trim(Edit1.Text) = '' then Exit;
for i:= 0 to ListBox1.Items.Count - 1 do
if ListBox1.Items[i] = Edit1.Text then Exit;
Append(txtFile);
try
WriteLn(txtFile,Trim(Edit1.Text));
finally CloseFile(txtFile);
end;
ListBox1.Visible := False;
end; 代码主要就是这些,txtFile:TextFile声明在private里
类似于ie的Cookie,呵呵,就是我的Cookie显示在一个ListBox里,ListBox长度不能动态改变,感觉这样不好没什么技术难度,更不能说完美,所以贴在这里期望起个抛砖引玉的作用
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货