본문 바로가기

Development/Delphi

TComboBox/TDBComboBox.AddObject Integer, String, Object

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.




'Development > Delphi' 카테고리의 다른 글

FieldByName 속도 향상  (0) 2015.09.18
TCheckbox.checked 설정시 onClick 이벤트 발생시키지 않기  (0) 2015.09.14
로컬 IP 가져오기  (0) 2015.08.25
Form 생성 및 해제  (0) 2015.08.25
TDataSet 관련 (TQuery, TFDQuery)  (0) 2015.08.24