TComboBox下拉取值
?
新建一個類,存儲我們需要的數(shù)據:
TItemEx=class(TObject)
public
????? caption:string;
????? StringValue:string;
end;
//使用adoquery中的值填充combobox
function FillInComBoBoxWithAdoQuery(objAdoQuery:TAdoQuery;objComBoBox:TComboBox;sql:string;captionFieldName:string;
????valueFieldName:string;noAsFirst:boolean):boolean;
//當noAsFirst為true是,combobox的第一項是'無'
var
? objItemEx:TItemEx;
begin
? objComBoBox.Clear;
? objComBoBox.ItemIndex:=-1;
? if noAsFirst
? then begin
???? objItemEx:=TItemEx.Create;
???? objItemEx.caption:='無';
???? objItemEx.StringValue:='';
???? objComBoBox.Items.AddObject(objItemEx.caption,objItemEx);
???? objComBoBox.ItemIndex:=0;
? end;
? objAdoQuery.Close;
? objAdoQuery.SQL.Clear;
? objAdoQuery.SQL.Add(sql);
? objAdoQuery.Open;
? objAdoQuery.First;
? while not objAdoQuery.Eof do
? begin
??? objItemEx:=TItemEx.Create;
??? objItemEx.caption:=objAdoQuery.FieldByName(captionFieldName).AsString;
??? objItemEx.StringValue:=objAdoQuery.FieldByName(valueFieldName).AsString;
??? objComBoBox.Items.AddObject(objItemEx.caption,objItemEx);
??? objAdoQuery.Next;
? end;
? objAdoQuery.close;
? result:=true;
end;
//取得comboobx中被選定向的制
function GetComBoBoxSelectedStringValue(objComBoBox:TComboBox):string;
var
? objItemEx:TItemEx;
begin
? if (objComBoBox.ItemIndex>-1 )
? then begin
?????? objItemEx:=(objComBoBox.Items.Objects[objComBoBox.ItemIndex] as? TItemEx);
?????? result:=objItemEx.StringValue;
? end
? else begin
?????? result:='';
? end;
end;
轉載于:https://www.cnblogs.com/gaowen1210/archive/2011/05/24/2055079.html
總結
以上是生活随笔為你收集整理的TComboBox下拉取值的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: iOS用户设计指南-特别说明
- 下一篇: Flex4与WebService通信