我用这种方法解决了//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
Table1->First();
for(int i=0;i<Table1->RecordCount;i++)
{ ListBox1->Items->Add(Table1->FieldByName("Name")->AsString);
Table1->Next();
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ListBox1Click(TObject *Sender)
{
Table1->First();
AnsiString a;
a=Table1->FieldByName("Name")->AsString;
for(int i=ListBox1->Items->Count-1;i>=0;i--)
{
if(ListBox1->Items->Strings[ListBox1->ItemIndex]==a )
Edit1->Text=Table1->FieldByName("Desc")->AsString;
Table1->Next();
a=Table1->FieldByName("Name")->AsString;
}
}
//---------------------------------------------------------------------------
返回页首
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
Table1->First();
for(int i=0;i<Table1->RecordCount;i++)
{ ListBox1->Items->Add(Table1->FieldByName("Name")->AsString);
Table1->Next();
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ListBox1Click(TObject *Sender)
{
Table1->First();
AnsiString a;
a=Table1->FieldByName("Name")->AsString;
for(int i=ListBox1->Items->Count-1;i>=0;i--)
{
if(ListBox1->Items->Strings[ListBox1->ItemIndex]==a )
Edit1->Text=Table1->FieldByName("Desc")->AsString;
Table1->Next();
a=Table1->FieldByName("Name")->AsString;
}
}
//---------------------------------------------------------------------------
返回页首