我有一个办法 PMyRecord=^TMyRecord TMyRecord=record text:String; id:Integer; sid:Integer; end;写 var aa:PMyRecord; AllocMem(aa); Items.AddObject(@aa); 读 aa:=PMyRecord(Items.Objects[n]);//或者 TMyRecord(Items.Objects[n]);在程序结束的时候,记得将每个 PMyRecord(也就是 Items.Objects) 释放 for n:=0 to Items.Count do FreeAndNil(Items.Objects[n]);样式差不多就是这样,其他的自己研究一下吧。
2个动态数组:idarr,sidarr:array of integer; 加入combobox.items的同时,也加到这2个数组获取,按idarr[combobox.itemindex]取即可
大家是不是把问题搞复杂化var vList:TStringList; With Adoquery do begin first; while not Eof do begin vList:=TStringList.Create; vList.Add(FieldByName('id').AsString); vList.Add(FieldByName('sid').AsString); ComboBox.Items.AddObject(FieldByName('text').AsString,vList); next; end; end; 用id,sid的时候,这样取出: vList:=TStringList(ComboBox.Items.Objects[ItemIndex]); showmessage(vList.Strings[0]); //这个是id showmessage(vList.Strings[1]); //这个是sid
Type
TValue = class
property ID: Integer read FID write FID;
property SID: Integer read FSID write FSID; constructor Create(ID, SID: String);
end;
PMyRecord=^TMyRecord
TMyRecord=record
text:String;
id:Integer;
sid:Integer;
end;写
var aa:PMyRecord;
AllocMem(aa);
Items.AddObject(@aa);
读
aa:=PMyRecord(Items.Objects[n]);//或者 TMyRecord(Items.Objects[n]);在程序结束的时候,记得将每个 PMyRecord(也就是 Items.Objects)
释放
for n:=0 to Items.Count do
FreeAndNil(Items.Objects[n]);样式差不多就是这样,其他的自己研究一下吧。
加入combobox.items的同时,也加到这2个数组获取,按idarr[combobox.itemindex]取即可
vList:TStringList; With Adoquery do
begin
first;
while not Eof do
begin
vList:=TStringList.Create;
vList.Add(FieldByName('id').AsString);
vList.Add(FieldByName('sid').AsString);
ComboBox.Items.AddObject(FieldByName('text').AsString,vList);
next;
end;
end; 用id,sid的时候,这样取出:
vList:=TStringList(ComboBox.Items.Objects[ItemIndex]);
showmessage(vList.Strings[0]); //这个是id
showmessage(vList.Strings[1]); //这个是sid