无法弄清楚如何对用户定义的对象使用实时绑定

时间:2019-01-30 09:15:04

标签: c++ c++builder livebindings

我试图弄清楚livebindings如何与用户定义的对象一起工作。因此,我举了一个简单的例子来说明它的工作原理,但事实并非如此。我搜索了所有信息,以了解问题所在,但到目前为止没有结果。

该示例基于Jim Tierney(embarcadero传播者)示例。我一次又一次地将自己的代码与他的代码进行比较。不幸的是,我看不出有什么区别,但是肯定它们在那里...

我的代码如下:

Unit1.h

class TPerson : public TObject
{
    private:
        UnicodeString nom;
        UnicodeString prenom;
    public:
        __fastcall TPerson();
        __fastcall ~TPerson();
        __property UnicodeString Nom = {read=nom, write=nom};
        __property UnicodeString Prenom = {read=prenom};
};
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published:    // Composants gérés par l'EDI
    TLabeledEdit *LabeledEdit1;
    TLabeledEdit *LabeledEdit2;
    TAdapterBindSource *AdapterBindSource1;
    TDataGeneratorAdapter *DataGeneratorAdapter1;
    TBindingsList *BindingsList1;
    TLinkControlToField *LinkControlToField1;
    TLinkControlToField *LinkControlToField2;
    void __fastcall PrototypeBindSource1CreateAdapter(TObject *Sender, TBindSourceAdapter *&ABindSourceAdapter);
    void __fastcall AdapterBindSource1CreateAdapter(TObject *Sender, TBindSourceAdapter *&ABindSourceAdapter);

private:    // Déclarations utilisateur
    TPerson* personne;
public:     // Déclarations utilisateur
    __fastcall TForm1(TComponent* Owner);
};

Unit1.cpp

__fastcall TPerson::TPerson() : TObject()
{
    this->nom = "Jon";
    this->prenom = "Stockton";
}
//---------------------------------------------------------------------------
__fastcall TPerson::~TPerson()
{
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
    : TForm(Owner)
{
    this->personne = new TPerson();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::AdapterBindSource1CreateAdapter(TObject *Sender, TBindSourceAdapter *&ABindSourceAdapter)
{
    ABindSourceAdapter = new TObjectBindSourceAdapter(this, this->personne, __classid(TPerson), true);
}

Unit1.dfm Form Design

Visual LiveBinding Visual LiveBinding Editor

但是,当我执行此操作时,我的主要窗体将暴露TPerson对象的两个属性,但没有反映TPerson对象的值,而是可以看到TPrototypeBindSource组件的值。 Main form result

因此,我希望标签编辑框包含TPerson对象的值。我还期望通过实时绑定定义,如果我在运行时更改TPserson属性,则会更新编辑文本值。 Main form expected

0 个答案:

没有答案