2010-06-17 8 views
0

에서 tdbmemo에 항목을 표시합니다. category1과 category2 값을 가진 콤보 상자가 있습니다 ... category1에는 연필, 음식, 잡지, 신문과 같은 항목이 있습니다. category1을 선택하면 항목을 검색하고 싶습니다. 내가 항목을 표시하는 clcat.items.add 사용 ...하는 방법을 잘 모릅니다하지만 항목이콤보 박스

procedure TfrmSysConfig.FillInCheckListClCat; 
var 
    sTable : string; 
    sqlCat : TIBOQuery; 
    iIndex :integer; 
    lstCat : TStringList; 
begin 
    if tblMain.FieldByName('POS_ReceiptCatBreakDown').AsString <> '' then begin 
    sqlCat := TIBOQuery.Create(nil); 
    sqlCat.IB_Connection := dmMain.db; 
    lstCat := TStringList.Create; 
    try 
     sqlCat.SQL.Text := 'SELECT code FROM ' + cboCategory.Value; 
     sqlCat.Open; 
     while not sqlCat.Eof do begin 
     clCat.Items.Add(sqlCat.FieldByName('Code').AsString); 
     sqlCat.Next; 
     end; 
    finally 
     lstCat.Free; 
     sqlCat.Free; 
    end; 
    end; 
end; 

답변

0
를 표시하지 않습니다 ... 내가 checklistbox에 표시 할 tdbmemo에서 같은 항목을 tdbmemo.then

sqlCat.SQL.Text : = 'SELECT code FROM'+ cboCategory.Value; - 이것이 작동하지 않을 것이라고 생각합니다 ... select 절은 "select * from table where condition"과 같습니다.

얼마 전에 IBObjects에서 근무했으며 그 구성 요소에 유용한 속성이 있습니다.

목록 (category1 및 category2 등)에 대해 IB_ComboBox를 사용하고 IB_Memo에 연결합니다 (이 이름이 100 %는 확실하지 않지만 알아낼 것입니다). 그리고 IBTable을 사용하면 그 위에 필터. 또한 그들은 사이트에서 매우 유용한 문서를 가지고 있습니다.

안부,

+0

잘 찾아 냈습니다. 누락 된 "From Table where x ="부분을 바로 읽으십시오. –

0

을 heres는 내가 그것을 어떻게 ... 첫 번째 드롭 형태의 콤보, dbmemo와 (당신이 이미 가지고) 목록 상자를 체크에 세 가지 구성 요소.

다음 단위 'VAR'에 문자열 목록 변수를 추가 섹션 내가 'TStringList를 항목 분명 콤보 상자를 초기화하고'카테고리 1 '을 추가하고이 formcreate 이벤트에

strs : tstringlist; 

다음 을 strs 명명하고

,691,363 : 구분 2 '항목은 .....를 heres는 다음

procedure TForm2.FormCreate(Sender: TObject); 
begin 
    strs := TStringList.create; 
    strs.Add('food'); 
    strs.Add('magazine'); 
    strs.Add('pencil'); 
    strs.Add('newspaper'); 
    Combobox1.Items.clear; 
    ComboBox1.Items.add('category1'); 
    ComboBox1.Items.add('category2'); 

end; 

우리가 콤보 상자 변경에 대한 이벤트 핸들러를 작성하고 checklistbox 및 dbmemo를 업데이트하는 코드를 작성하는 방법 (210)

procedure TForm2.ComboBox1Change(Sender: TObject); 
begin 
    if ComboBox1.ItemIndex = 0 then 
    DBMemo1.lines.AddStrings(strs); 
    CheckListBox1.Items.addstrings(strs); 
end; 

을 heres 전체 코드 : 무언가가 당신에게 불분명하거나, 병이 시도는 더 세부 사항을 설명하기 위해 뭔가를 이해 해달라고하면

unit project1; 

interface 

uses 
    Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 
    Dialogs, StdCtrls, DBCtrls, CheckLst; 

type 
    TForm2 = class(TForm) 
    ComboBox1: TComboBox; 
    DBMemo1: TDBMemo; 
    CheckListBox1: TCheckListBox; 
    procedure FormCreate(Sender: TObject); 
    procedure ComboBox1Change(Sender: TObject); 
    private 
    { Private declarations } 
    public 
    { Public declarations } 
    end; 

var 
    Form2: TForm2; 
    strs : tstringlist; 

implementation 

{$R *.dfm} 

procedure TForm2.ComboBox1Change(Sender: TObject); 
begin 
    if ComboBox1.ItemIndex = 0 then 
    DBMemo1.lines.AddStrings(strs); 
    CheckListBox1.Items.addstrings(strs); 
end; 

procedure TForm2.FormCreate(Sender: TObject); 
begin 
    strs := TStringList.create; 
    strs.Add('food'); 
    strs.add('magazine'); 
    strs.Add('pencil'); 
    strs.add('newspaper'); 
    combobox1.Items.clear; 
    ComboBox1.items.add('category1'); 
    ComboBox1.items.add('category2'); 

end; 


end. 

난이 도움을 바랍니다, 문의하시기 바랍니다.