Development/Delphi
TComboBox/TDBComboBox.AddObject Integer, String, Object
코드의추억
2015. 9. 4. 11:40
1-1. to store the integer values:
with qryGroups do begin First; while not Eof do begin cbGroups.Items.AddObject(FieldByName('Name').AsString, TObject(FieldByName('ID').AsInteger)); Next; end; end;
1-2. to read the integer value from selected item:
strID := LongInt(cbGroups.Items.Objects[cbGroups.ItemIndex]);2-1. to store the string values:
with qryGroups do begin First; while not Eof do begin cbGroups.Items.AddObject(FieldByName('Name').AsString, TObject(NewStr(FieldByName('ID').AsString))); Next; end; end;
2-2. to read a value from selected item:
strID := PAnsiString(cbGroups.Items.Objects[cbGroups.ItemIndex])^;#. don't forget that you must destroy the objects data
for i := 0 to cbGroups.Items.Count-1 do DisposeStr(PString(cbGroups.Items.Objects[i]));1. 콤보박스의 데이저가 로드되기 전에 콤보박스 아이템의 존재 여부를 판단해서 이전데이터 free.
2. form 이 종료 될때 콤보박스 아이템의 존재 여부를 판단해서 이전데이터 free.