Board index » cppbuilder » Property editor woes

Property editor woes


2005-09-29 12:16:47 AM
cppbuilder4
I've been having a problem getting an AnsiString property editor to work
with a data-aware component I wrote. The component works as it's
supposed to, and I was able to install it (along with a number of other
components) successfully in the IDE. However, the AnsiString property
editor I wrote for the DataField doesn't give me the drop-down list of
fields in the dataset.
I've researched the issue ad infinitum and have read virtually every
newsgroup post that has appeared in the last five years, and I'm at a
total loss as to why it doesn't work.
Here is the relevant code:
First, the data-aware component for which the property editor was designed:
in DataAwareControl.h (header file):
#ifndef DataAwareControlH
#define DataAwareControlH
#include <SysUtils.hpp>
#include <Controls.hpp>
#include <Classes.hpp>
#include <Forms.hpp>
#include <StdCtrls.hpp>
#include <DB.hpp>
#include <DBTables.hpp>
#include <dbctrls.hpp>
#include "TAncestorControl.h"
class PACKAGE TDataAwareControl : public TAncestorControl
{
private:
.
.
TFieldDataLink *FDataLink;
AnsiString __fastcall GetDataField(void);
void __fastcall SetDataField(AnsiString df);
.
.
protected:
.
.
public:
.
.
published:
.
.
__property AnsiString DataField = {read=GetDataField,
write=SetDataField};
.
.
BEGIN_MESSAGE_MAP
.
.
END_MESSAGE_MAP(TDTSpinEdit);
};
in DataAwareControl.cpp (source file)
#include <vcl.h>
#pragma hdrstop
#include "DataAwareControl.h"
#pragma package(smart_init)
.
.
.
AnsiString __fastcall TDataAwareControl::GetDataField(void)
{
return FDataLink->FieldName;
}
void __fastcall TDataAwareControl::SetDataField(AnsiString df)
{
FDataLink->FieldName = df;
}
All this successfully compiles and links, along with six other custom
controls, into a runtime package.
To install it in the IDE and provide the desired property editor, I
created a design package containing the following file:
dclmyreg.cpp (registration file):
#pragma hdrstop
#include <designeditors.hpp>
#include "DataAwareControl.h"
.
.
(headers for other components being registered)
.
.
#pragma package(smart_init)
PTypeInfo AnsiStringTypeInfo(void)
{
PTypeInfo typeInfo = new TTypeInfo;
typeInfo->Name = "AnsiString";
typeInfo->Kind = tkLString;
return typeInfo;
};
class PACKAGE TSubDFPropertyEditor : public TStringProperty
{
public:
TPropertyAttributes __fastcall GetAttributes(void);
void __fastcall GetValues(TGetStrProc AddField);
AnsiString __fastcall GetValue(void);
void __fastcall SetValue(const AnsiString Value);
};
TPropertyAttributes __fastcall TSubDFPropertyEditor::GetAttributes(void)
{
return TPropertyAttributes() << paValueList;
}
void __fastcall TSubDFPropertyEditor::GetValues(TGetStrProc AddField)
{
TDataAwareControl *dtCtrl;
TDataSet *ds;
TField *df;
dtCtrl = dynamic_cast<TDataAwareControl*>(GetComponent(0));
if (dtCtrl) {
ds = dtCtrl->DataSource->DataSet;
if (ds) {
for (int i = 0; i < ds->FieldCount; i++) {
df = ds->Fields->Fields[i];
if ((df->DataType == ftDateTime) ||
(df->DataType == ftDate) ||
(df->DataType == ftTime) ||
(df->DataType == ftTimeStamp)) {
AddField(df->FieldName);
}
}
}
}
}
AnsiString __fastcall TSubDFPropertyEditor::GetValue(void)
{
return GetStrValue();
}
void __fastcall TSubDFPropertyEditor::SetValue(const AnsiString Value)
{
SetStrValue(Value);
Modified();
}
namespace Dclmyreg
{
void __fastcall PACKAGE Register()
{
TComponentClass classes[7];
.
.
classes[2] = __classid(TDataAwareControl);
.
.
RegisterComponents("My Controls", classes, 6);
RegisterPropertyEditor(AnsiStringTypeInfo(),
__classid(TDataAwareControl),
"DataField", __classid(TSubDFPropertyEditor));
}
}
I made sure to include the runtime package in the "Requires" list.
The design package compiles and installs correctly, and I can drop any
of the registered components on a form, and they all work. The only
problem is that clicking the DataField property in the Object Inspector
does not produce the expected drop-down list. (Although, if I type it
in, it connects with the correct field.)
Am I missing something?
Phil
 
 

Re:Property editor woes

"Phil Manger" < XXXX@XXXXX.COM >wrote in message
Quote
PTypeInfo AnsiStringTypeInfo(void)
{
PTypeInfo typeInfo = new TTypeInfo;
typeInfo->Name = "AnsiString";
typeInfo->Kind = tkLString;
return typeInfo;
};
Use this instead:
PPropInfo pPropInfo = ::GetPropInfo(__typeinfo(TDataAwareControl),
"DataField");
RegisterPropertyEditor(*(pPropInfo->PropType),
__classid(TDataAwareControl), "DataField", __classid(TSubDFPropertyEditor));
Gambit
 

Re:Property editor woes

Remy Lebeau (TeamB) wrote:
Quote
"Phil Manger" < XXXX@XXXXX.COM >wrote in message
news:433ac17b$ XXXX@XXXXX.COM ...


>PTypeInfo AnsiStringTypeInfo(void)
>{
>PTypeInfo typeInfo = new TTypeInfo;
>typeInfo->Name = "AnsiString";
>typeInfo->Kind = tkLString;
>return typeInfo;
>};


Use this instead:

PPropInfo pPropInfo = ::GetPropInfo(__typeinfo(TDataAwareControl),
"DataField");
RegisterPropertyEditor(*(pPropInfo->PropType),
__classid(TDataAwareControl), "DataField", __classid(TSubDFPropertyEditor));


Gambit


Yea! That worked! Thanks for your help, and thanks for getting back to
me so soon.
Phil
 

{smallsort}