Board index » cppbuilder » Changes in caption reflected during design time

Changes in caption reflected during design time

Now I have a published property Caption of type AnsiString.  In my paint()
method, I use TextOut() to draw Caption on my control.  During design time,
however, I would like any changes in the Caption property reflected on the
control or simply update the control's caption whenever the user edits the
Caption property in the Object Inspector, not after the user has finished
editing and pressed Enter.  If you place a TButton on a form and change the
Caption property, you will see what I mean.  Please help.
 

Re:Changes in caption reflected during design time


You would need to register your own property editor for your Caption
property.  In the editor, override the inherited GetAttributes() method to
return the paAutoUpdate attribute.  That should update the property on every
key press.

Gambit

Quote
"OYT" <ooiyit...@hotmail.com> wrote in message

news:3e1c38f9@newsgroups.borland.com...
Quote
> Now I have a published property Caption of type AnsiString.
> In my paint() method, I use TextOut() to draw Caption on
> my control.  During design time, however, I would like any
> changes in the Caption property reflected on the control or
> simply update the control's caption whenever the user edits the
> Caption property in the Object Inspector, not after the user
> has finished editing and pressed Enter.  If you place a TButton
> on a form and change the Caption property, you will see what
> I mean.  Please help.

Re:Changes in caption reflected during design time


Quote
Remy wrote:
> You would need to register your own property editor for your Caption
> property.  In the editor, override the inherited GetAttributes() method to
> return the paAutoUpdate attribute.  That should update the property on
> every key press.

If the component is a TControl derivative, it should already have a property
named Caption, with the TCaptionProperty property editor registered for
that property.  Changing the Caption should result in a CM_TEXTCHANGED
at the control, which could be handled by the component....

If the component is not a TControl derivative, the TCaptionProperty property
editor can be registered for it, and the setter function for the Caption property
could cause the caption to be painted.

Unless, of course, I am completely wrong-- which is quite possible!

Re:Changes in caption reflected during design time


In my attempt to write a property editor for my control's Caption property,
I have produced the following codes.

In the header file

//--------------------------------------------------------------------------
-
#ifndef YTButtonPropEditorH
#define YTButtonPropEditorH
//--------------------------------------------------------------------------
-
#include <DesignEditors.hpp>
//--------------------------------------------------------------------------
-
class PACKAGE YTButtonPropEditor : public TPropertyEditor
{
    protected:
        TPropertyAttributes __fastcall GetAttributes()
        {
            return TPropertyEditor::GetAttributes() << paAutoUpdate;
        }

    public:
        __fastcall YTButtonPropEditor(const _di_IDesigner ADesigner, int
APropCount) : TPropertyEditor(ADesigner, APropCount)
        {}

Quote
};

//--------------------------------------------------------------------------
-
#endif

In the cpp file

//--------------------------------------------------------------------------
-
#include "YTButton.h"
#include "YTButtonPropEditor.h"
#pragma package(smart_init)
//--------------------------------------------------------------------------
-
namespace Ytbuttonpropeditor
{
    void __fastcall PACKAGE Register()
    {
        TTypeInfo TI;
        TI.Kind = tkString;
        TI.Name = "AnsiString";
        RegisterPropertyEditor(&TI,
                               __classid(YTButton),
                               "Caption",
                               __classid(YTButtonPropEditor));
    }

Quote
}

//--------------------------------------------------------------------------
-

When I compile, it produces the following linker errors, here are just a
few.

[Linker Error] Unresolved external '__tpdsc__
Designeditors::TPropertyEditor' referenced from C:\PROGRAM
FILES\BORLAND\CBUILDER6\PROJECTS\THIRD PARTY COMPONENTS\VCL
COMPONENT\YTPACKAGE\YTPROPERTYEDITOR.OBJ
[Linker Error] Unresolved external 'Designeditors::TPropertyEditor::'
referenced from C:\PROGRAM FILES\BORLAND\CBUILDER6\PROJECTS\THIRD PARTY
COMPONENTS\VCL COMPONENT\YTPACKAGE\YTPROPERTYEDITOR.OBJ
[Linker Error] Unresolved external '__fastcall
Designeditors::TPropertyEditor::~TPropertyEditor()' referenced from
C:\PROGRAM FILES\BORLAND\CBUILDER6\PROJECTS\THIRD PARTY COMPONENTS\VCL
COMPONENT\YTPACKAGE\YTPROPERTYEDITOR.OBJ
[Linker Error] Unresolved external '__fastcall
Designeditors::TPropertyEditor::Initialize()' referenced from C:\PROGRAM
FILES\BORLAND\CBUILDER6\PROJECTS\THIRD PARTY COMPONENTS\VCL
COMPONENT\YTPACKAGE\YTPROPERTYEDITOR.OBJ

What is wrong?  Please help, and thank you Remy for your advice on my
previous post.

Re:Changes in caption reflected during design time


Quote
"OYT" <ooiyit...@hotmail.com> wrote in message

news:3e1d5b56$1@newsgroups.borland.com...

Quote
>         TTypeInfo TI;
>         TI.Kind = tkString;
>         TI.Name = "AnsiString";
>         RegisterPropertyEditor(&TI,
>                                __classid(YTButton),
>                                "Caption",
>                                __classid(YTButtonPropEditor));

A simplier approach would be to use GetPropInfo() instead of constructing
the TypeInfo manually:

    PPropInfo pPropInfo = ::GetPropInfo(__typeinfo(YTButton), "Caption");
    RegisterPropertyEditor(&TI, __classid(YTButton), "Caption",
__classid(YTButtonPropEditor));

This work for all data types, not just AnsiString.

Quote
> When I compile, it produces the following linker errors, here are just a
> few.

Refer to the "Updating Pascal component design packages" topic of the
"What's New in C++Buildr" help file.  You need to add DesignIDE.bpi to your
package's Requires list, and then manually edit the project makefile to add
the -LUDesignIde flag to the PFLAGS section.

Gambit

Other Threads