?? itemex.pas
字號(hào):
unit ItemEx;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ADODB, DB, StdCtrls;
type
TItemEx=class(TObject)
public
caption:string;
StringValue:string;
end;
implementation
//使用adoquery中的值填充combobox
function FillInComBoBoxWithAdoQuery(objAdoQuery:TAdoQuery;objComBoBox:TComboBox;sql:string;captionFieldName:string;
valueFieldName:string;noAsFirst:boolean):boolean;
//當(dāng)noAsFirst為true是,combobox的第一項(xiàng)是'無(wú)'
var
objItemEx:TItemEx;
begin
objComBoBox.Clear;
objComBoBox.ItemIndex:=-1;
if noAsFirst
then begin
objItemEx:=TItemEx.Create;
objItemEx.caption:='無(wú)';
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;
end.
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -