文件oka.txt,基本内容为:
AAAAA 111111111
BBBBB 222222222
CCCCC 333333333
DDDDD 444444444
EEEEE 555555555组件Tlistbox,Tedit 分别两个,下面的问题出来了!procedure TForm1.FormCreate(Sender: TObject);
var
a:string;
i,j:integer;begin
templist:=Tstringlist.Create;
templist.LoadFromFile('d:\oka.txt');with templist do
for i:=0 to count -1 do
begin
a:=templist.Strings[i];
j:=pos(' ',z);
b:=copy(a,j+1,MAXINT);
a:=copy(a,0,j-1);
listbox1.Items.add(a);
end;
end;procedure TForm1.ListBox1Click(Sender: TObject);
var
k,i,j:integer;
begin
for k:=0 to listbox1.Count -1 do
if listbox1.Selected[k] then
edit1.Text:=listbox1.Items.Strings[k];问题:listbox1.items里已经加载了变量a的值,选择a,edit1里显示它的值。
如何在选取listbox1的a值后,在edit2里显示a相关的值?
AAAAA 111111111
BBBBB 222222222
CCCCC 333333333
DDDDD 444444444
EEEEE 555555555组件Tlistbox,Tedit 分别两个,下面的问题出来了!procedure TForm1.FormCreate(Sender: TObject);
var
a:string;
i,j:integer;begin
templist:=Tstringlist.Create;
templist.LoadFromFile('d:\oka.txt');with templist do
for i:=0 to count -1 do
begin
a:=templist.Strings[i];
j:=pos(' ',z);
b:=copy(a,j+1,MAXINT);
a:=copy(a,0,j-1);
listbox1.Items.add(a);
end;
end;procedure TForm1.ListBox1Click(Sender: TObject);
var
k,i,j:integer;
begin
for k:=0 to listbox1.Count -1 do
if listbox1.Selected[k] then
edit1.Text:=listbox1.Items.Strings[k];问题:listbox1.items里已经加载了变量a的值,选择a,edit1里显示它的值。
如何在选取listbox1的a值后,在edit2里显示a相关的值?
什么意思?
是把listbox1的a值给edit2吗?
AAAAAA
BBBBBB
CCCCCC对应的值
1111111111
2222222222
3333333333
with templist do
for i:=0 to count -1 do
begin
a:=templist.Strings[i];
j:=pos(' ',z);
b:=copy(a,j+1,MAXINT);
a:=copy(a,0,j-1);
listbox1.Items.add(a);
templist.Strings[i] := b;
end;
end;
然后在ListBox的单击事件中写
edit2.text ;= templist.String[ListBox1.ItemIndex];