BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Adding TLabel in component

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (VCL Components Development)
View previous topic :: View next topic  
Author Message
MD
Guest





PostPosted: Fri Feb 27, 2004 7:49 am    Post subject: Adding TLabel in component Reply with quote



Hi,

The question is :
How can I use a TLabel as property inside another component and access to
TLabel's properties??

I create a new component with a TLabel as published property.
If I try to use directly the TLabel as private member, the compilator
generate an error.
It's necessary to use the TLabel as pointer and create it inside the
constructor .
In the property's editor the TLabel exist as pointer and there is no way to
attempt the TLabel's properties trough the new component.

So, How can I Add a The Label inside the new component and show the TLabel's
properties in the property's editor?

For Example
Folder.h
class PACKAGE TFolder : public TComponent
{
private:
TLabel* LBTest;

virtual void __fastcall SetLabel(TLabel* pLabel);
virtual TLabel* __fastcall GetLabel();

__published:
__property TLabel* LAB = {read=GetLabel, write=SetLabel};
}

Folder.cpp
__fastcall TFolder ::TFolder (TComponent* Owner)
: TComponent()
{
LBTest = new TLabel(this);
}

__fastcall TFolder::~TFolder ()
{
delete LBTest;
}

void __fastcall TFolder::SetLabel(TLabel* pLabel)
{
LBTest->Assign(pLabel);
}

TLabel* __fastcall TFolder::GetLabel()
{
return LBTest;
}

Thank for you help.

MD


Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Fri Feb 27, 2004 8:09 am    Post subject: Re: Adding TLabel in component Reply with quote




"MD" <mduse (AT) skynet (DOT) be> wrote


Quote:
How can I use a TLabel as property inside another
component and access to TLabel's properties??

I create a new component with a TLabel as published
property.

That will only work for BCB6. Are you using BCB6? If so, you did not call
the TLabel's SetSubComponent() method after instantiating it.

Quote:
If I try to use directly the TLabel as private member, the
compilator generate an error.

You need to be more specific. What kind of error?

Quote:
It's necessary to use the TLabel as pointer and create it
inside the constructor .

Of course. All VCL objects must be used via pointers. They must always be
instantiated dynamically on the heap.

Quote:
In the property's editor the TLabel exist as pointer and there
is no way to attempt the TLabel's properties trough the new
component.

If you are not using BCB6, then you must write your own custom property
editor to expose access to the TLabel's properties at design time.

Quote:
LBTest->Assign(pLabel);

TLabel, like most other VCL components in general, does not implement
Assign() at all. You will get an exception if you try to use Assign(). You
will have to copy all of the property values yourself manually one property
at a time, or alternatively use RTTI to loop through the properties, but you
are still assigning them one at a time either way.


Gambit



Back to top
MD
Guest





PostPosted: Fri Feb 27, 2004 8:15 am    Post subject: Re: Adding TLabel in component Reply with quote



Hi,

I use BCB5.
So, I need to implement a custom property editor to access to the TLabel's
properties at design time.

Is there some links with example of custom property editor wrote in BCB to
help me
to do this work.

Thanks for your answer.

MD

"Remy Lebeau (TeamB)" <gambit47.no.spam (AT) no (DOT) spam.yahoo.com> a écrit dans le
message de news:403ef933$1 (AT) newsgroups (DOT) borland.com...
Quote:

"MD" <mduse (AT) skynet (DOT) be> wrote in message
news:403ef681$1 (AT) newsgroups (DOT) borland.com...

How can I use a TLabel as property inside another
component and access to TLabel's properties??

I create a new component with a TLabel as published
property.

That will only work for BCB6. Are you using BCB6? If so, you did not
call
the TLabel's SetSubComponent() method after instantiating it.

If I try to use directly the TLabel as private member, the
compilator generate an error.

You need to be more specific. What kind of error?

It's necessary to use the TLabel as pointer and create it
inside the constructor .

Of course. All VCL objects must be used via pointers. They must always
be
instantiated dynamically on the heap.

In the property's editor the TLabel exist as pointer and there
is no way to attempt the TLabel's properties trough the new
component.

If you are not using BCB6, then you must write your own custom property
editor to expose access to the TLabel's properties at design time.

LBTest->Assign(pLabel);

TLabel, like most other VCL components in general, does not implement
Assign() at all. You will get an exception if you try to use Assign().
You
will have to copy all of the property values yourself manually one
property
at a time, or alternatively use RTTI to loop through the properties, but
you
are still assigning them one at a time either way.


Gambit






Back to top
Martin Moeller
Guest





PostPosted: Fri Feb 27, 2004 3:58 pm    Post subject: Re: Adding TLabel in component Reply with quote

"MD" <mduse (AT) skynet (DOT) be> wrote:

Quote:
Is there some links with example of custom property editor wrote in BCB to
help me
to do this work.

I use BCB6, but in my post 'Can't load an AnsiString as member' dated
24.02.2004 you find complete working code suitable also for BCB5.

Rgds, Martin




Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Fri Feb 27, 2004 7:31 pm    Post subject: Re: Adding TLabel in component Reply with quote

"MD" <mduse (AT) skynet (DOT) be> wrote


Quote:
So, I need to implement a custom property editor to access
to the TLabel's properties at design time.

Yes. Otherwise, do not publish the TLabel directly to begin with.

Quote:
Is there some links with example of custom property editor
wrote in BCB to help me to do this work.

Not for this particular task, no.

Basically, you need to create a new class derived from TPropertyEditor, and
override its GetAttributes() method to include the paSubProperties
attribute, and then override the GetProperties() method to return
appropriate TPropertyEditor instances for every property of the TLabel that
you want to expose access to.

Fortunately, the VCL already has such a propety editor class available -
TClassProperty. So, you can simply call RegisterPropertyEditor() specifying
TClassProperty as the editor for your label property, ie:

#include "MyComponent.h"

namespace Mycomponent
{
void PACKAGE __fastcall Register()
{
TComponentClass classes[1] = {__classid(TMyComponent)};
RegisterComponents("My Tab", classes, 0);

PPropInfo pPropInfo = ::GetPropInfo(__typeinfo(TMyComponent),
"Label");
RegisterPropertyEditor(*(pPropInfo->PropType),
__classid(TMyComponent), "Label", __classid(TClassProperty));
}
}


Gambit



Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (VCL Components Development) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.