O
optn3
Unregistered / Unconfirmed
GUEST, unregistred user!
memo1.text数据量大时,比如几千行时,执行代码很慢,怎样才能加快。
代码意为:对memo1中出现相同符合ComboBox1.Text的数抽出来。
private
{ Private declarations }
sl1: tstringlist;
sl2: tstringlist;
procedure TForm1.getmemotext(var list: tstringlist); //memo1按条件统计出现次多的保留
var i: Integer;
s: string;
ss:TStringList;
begin
ss:=TStringlist.Create;
ss.Text := memo1.Text;
list.Clear;
for i := 0 to ss.Count - 1 do
begin
s := list.Values[ss];
if s = '' then
begin
s := '1';
list.Add(ss+'='+ s);
end else
list.Values[ss] := IntToStr(StrToInt(s)+1);
end;
ss.Free;
end;
procedure TForm1.Button1Click(Sender: TObject);
var i,j,g: Integer;
sk:TStringList;
begin
sk:=TStringlist.Create;
sk.Text := memo1.Text;
getmemotext(sl1);
j := 0;
for i := 0 to sk.Count - 1 do
if sl1.Values[sk[j]] <> '' then
//////////////从combobox3中选择参数作为条件 在memo1中进行过滤
begin
if form1.ComboBox3.Text = '>=' then
if StrToInt(sl1.Values[sk[j]]) < StrToInt(ComboBox1.Text) then
sk.Delete(j)
else
j := j + 1;
if form1.ComboBox3.Text = '>' then
if StrToInt(sl1.Values[sk[j]]) <= StrToInt(ComboBox1.Text) then
sk.Delete(j)
else
j := j + 1;
if form1.ComboBox3.Text = '<' then
if StrToInt(sl1.Values[sk[j]]) >= StrToInt(ComboBox1.Text) then
sk.Delete(j)
else
j := j + 1;
if form1.ComboBox3.Text = '<=' then
if StrToInt(sl1.Values[sk[j]]) > StrToInt(ComboBox1.Text) then
sk.Delete(j)
else
j := j + 1;
if form1.ComboBox3.Text = '=' then
if StrToInt(sl1.Values[sk[j]]) <> StrToInt(ComboBox1.Text) then
sk.Delete(j)
else
j := j + 1;
end;
{ if StrToInt(sl1.Values[Memo1.Lines[j]]) < StrToInt(ComboBox1.Text) then
Memo1.Lines.Delete(j)
else
j := j + 1; }
memo1.Text := sk.Text;
sk.Free;
getmemotext(sl1);
end;
代码意为:对memo1中出现相同符合ComboBox1.Text的数抽出来。
private
{ Private declarations }
sl1: tstringlist;
sl2: tstringlist;
procedure TForm1.getmemotext(var list: tstringlist); //memo1按条件统计出现次多的保留
var i: Integer;
s: string;
ss:TStringList;
begin
ss:=TStringlist.Create;
ss.Text := memo1.Text;
list.Clear;
for i := 0 to ss.Count - 1 do
begin
s := list.Values[ss];
if s = '' then
begin
s := '1';
list.Add(ss+'='+ s);
end else
list.Values[ss] := IntToStr(StrToInt(s)+1);
end;
ss.Free;
end;
procedure TForm1.Button1Click(Sender: TObject);
var i,j,g: Integer;
sk:TStringList;
begin
sk:=TStringlist.Create;
sk.Text := memo1.Text;
getmemotext(sl1);
j := 0;
for i := 0 to sk.Count - 1 do
if sl1.Values[sk[j]] <> '' then
//////////////从combobox3中选择参数作为条件 在memo1中进行过滤
begin
if form1.ComboBox3.Text = '>=' then
if StrToInt(sl1.Values[sk[j]]) < StrToInt(ComboBox1.Text) then
sk.Delete(j)
else
j := j + 1;
if form1.ComboBox3.Text = '>' then
if StrToInt(sl1.Values[sk[j]]) <= StrToInt(ComboBox1.Text) then
sk.Delete(j)
else
j := j + 1;
if form1.ComboBox3.Text = '<' then
if StrToInt(sl1.Values[sk[j]]) >= StrToInt(ComboBox1.Text) then
sk.Delete(j)
else
j := j + 1;
if form1.ComboBox3.Text = '<=' then
if StrToInt(sl1.Values[sk[j]]) > StrToInt(ComboBox1.Text) then
sk.Delete(j)
else
j := j + 1;
if form1.ComboBox3.Text = '=' then
if StrToInt(sl1.Values[sk[j]]) <> StrToInt(ComboBox1.Text) then
sk.Delete(j)
else
j := j + 1;
end;
{ if StrToInt(sl1.Values[Memo1.Lines[j]]) < StrToInt(ComboBox1.Text) then
Memo1.Lines.Delete(j)
else
j := j + 1; }
memo1.Text := sk.Text;
sk.Free;
getmemotext(sl1);
end;