during design time fine, but during runtime propeties without effect
I add two properties to the control.
DataSource and a String for the column name. The combobox should be filled
with all records of the dataset which is linke to the datasource.
Problem:
During the design time everything works fine -> the Item consist of the
records
But during the runtime the set properties has no effect -> the list is
empty.
That's my first component and I think this is a very stupid mistake, but I
can't find the problem.
//--------------------------------------------------------------------------
-
#include <vcl.h>
#pragma hdrstop
#include "DBComboBoxList.h"
#pragma package(smart_init)
//--------------------------------------------------------------------------
-
// Mit ValidCtrCheck wird sichergestellt, da? die erzeugten Komponenten
// keine rein virtuellen Funktionen besitzen.
//
static inline void ValidCtrCheck(TDBComboBoxList *)
{
new TDBComboBoxList(NULL);
//--------------------------------------------------------------------------
-
__fastcall TDBComboBoxList::TDBComboBoxList(TComponent* Owner)
: TCustomComboBox(Owner)
{
FDataLink = new TFieldDataLink();
FDataLink->Control = this;
//--------------------------------------------------------------------------
-
namespace Dbcomboboxlist
{
void __fastcall PACKAGE Register()
{
TComponentClass classes[1] = {__classid(TDBComboBoxList)};
RegisterComponents("Cratemaker", classes, 0);
}
//--------------------------------------------------------------------------
-
__fastcall TDBComboBoxList::~TDBComboBoxList()
{
FDataLink->Control = NULL;
FDataLink->OnUpdateData = NULL;
delete FDataLink;
AnsiString __fastcall TDBComboBoxList::GetDataField(){
return FDataLink->FieldName;
TDataSource* __fastcall TDBComboBoxList::GetDataSource(){
return FDataLink->DataSource;
void __fastcall TDBComboBoxList::SetDataField(AnsiString FieldName){
FDataLink->FieldName = FieldName;
Caption = "";
InitItems();
void __fastcall TDBComboBoxList::SetDataSource(TDataSource *datasource){
if ( datasource != NULL ){
datasource->FreeNotification(this);
if (Items != NULL)
{
Items->Clear();
}
}
FDataLink->DataSource = datasource;
/**
The method load the items by reading from datasource
*/
void __fastcall TDBComboBoxList::InitItems()
{
if (FDataLink->FieldName != NULL &&
FDataLink->DataSource != NULL &&
Items != NULL)
{
Items->Clear();
TDataSet* dataSet = FDataLink->DataSource->DataSet;
if (dataSet != NULL)
{
// iterate over all records from dataset
while (!dataSet->Eof)
{
Items->Add(dataSet->FieldByName(FDataLink->FieldName)->AsString);
dataSet->Next();
}
}
else Items->Add("DEBUG: DatSet empty");
}