Board index » cppbuilder » BCB5:Some observations when inserting components into a custom component

BCB5:Some observations when inserting components into a custom component


2006-01-21 09:57:13 AM
cppbuilder72
Hello,
how can inserting a component into a custom component be prevented at
design time. When inserting e.g. a button into the custom component,
something gets into trouble, according to the error messages.
The next question is, what has to be done to make inserting components
into custom components possible, and whether this is possible at all.
The custom component I'm trying with is derived from a class itself
derived from TFrame. It contains an OK button named Button1.
There is one more problem, when trying to insert another OK button
somewhere into the form the custom component is in, there are annoying
messages, that Button1 is already used in the form.
Regards,
Sascha Michel
 
 

Re:BCB5:Some observations when inserting components into a custom component

"Sascha Michel" < XXXX@XXXXX.COM >wrote in message
Quote
how can inserting a component into a custom component
be prevented at design time.
Do you mean visually dropping a component from the Palette onto your custom
component in the Form Designer? If so, then simply remove the
csAcceptsControls flag from the ControlStyle property in your custom
component's constructor.
Quote
When inserting e.g. a button into the custom component, something
gets into trouble, according to the error messages.
Please be more specific. What EXACTLY is happening.
Quote
what has to be done to make inserting components into custom
components possible, and whether this is possible at all.
That behavior is already implemented by default. You do not need to do
anything extra to get it.
Quote
when trying to insert another OK button somewhere into the form
the custom component is in, there are annoying messages, that Button1
is already used in the form.
The only way that can happen is if you are not setting up the original
Button to begin with. Please explain, in detail, exactly what your setup
is, and what your code looks like for it.
Gambit
 

Re:BCB5:Some observations when inserting components into a custom component

Hello,
sorry, I should have made clear that my goal was to prevent visually
dropping components to a custom component and informing the developer
somehow that something has not been accepted. What is the best way to do
this?
Remy Lebeau (TeamB) wrote:
Quote
"Sascha Michel" < XXXX@XXXXX.COM >wrote in message
news: XXXX@XXXXX.COM ...

>how can inserting a component into a custom component
>be prevented at design time.

Do you mean visually dropping a component from the Palette onto your custom
component in the Form Designer? If so, then simply remove the
csAcceptsControls flag from the ControlStyle property in your custom
component's constructor.
This would just make the visually dropped component fall through. It
does not make sense for the custom components I'm planning. I'd rather
like to give some sensible error message. The crazy things I've tried to
describe were the results of a half-way solution. I was a little bit
confused, because at design time the visually dropped components were
displayed as if my custom component had caught them, but in fact they
had fallen through, or had been caught by some component within the
frame my custom component is derived from.
I was trying to prevent visually dropping another component by basically
two variants, one by throwing in the Notification method, another by
throwing in ValidateInsert. In the end I had the following and it seems
to work. All components within my custom component let something
visually dropped fall through, the custom component accepts it, but only
to deny it by ValidateInsert.
// Visually created frame
class TMyFrame : public TFrame
{
__published:
TPanel *Panel;
TMemo *Memo1;
TButton *Button1;
private:
public:
__fastcall TMyFrame(TComponent* Owner);
};
// Custom component using the visually created frame
class PACKAGE TKMyFrame : public TMyFrame
{
private:
protected:
DYNAMIC void __fastcall ValidateInsert(TComponent* AComponent);
public:
__fastcall TKMyFrame(TComponent* Owner);
__published:
};
__fastcall TKMyFrame::TKMyFrame(TComponent* Owner)
: TMyFrame(Owner)
{
TControlStyle remove;
remove << csAcceptsControls;
TControl *Temp;
for ( int I = this->ComponentCount -1; I>= 0; I--)
{
Temp = dynamic_cast< TControl *>( this->Components[I] );
if ( Temp != NULL )
Temp->ControlStyle -= remove;
}
}
void __fastcall TKMyFrame::ValidateInsert(TComponent* AComponent)
{
if ( ComponentState.Contains( csLoading ))
return;
throw Exception( "No to " + AComponent->Name );
}
Quote

>When inserting e.g. a button into the custom component, something
>gets into trouble, according to the error messages.

Please be more specific. What EXACTLY is happening.
I could not have been more specific without giving the full source code.
I was confused about those visually dropped components falling through,
but being displayed, as if my custom component had accepted them. I
think this is a feature to enable the IDE to keep all dropped components
visible at design time, although they should be below the component that
had not accepted them.
Quote

>when trying to insert another OK button somewhere into the form
>the custom component is in, there are annoying messages, that Button1
>is already used in the form.

The only way that can happen is if you are not setting up the original
Button to begin with. Please explain, in detail, exactly what your setup
is, and what your code looks like for it.
The problem with the double name was due to the IDE getting confused by
my endless tries to drop components into a new project with my custom
component. This happens at times. The source code got out of sync. This
is the main reason I want more control about what is dropped, and where.
Is there any way to set breakpoints in the de{*word*81} to be used at design
time? This would make it a lot easier to understand what happens at
design time.
Thank you,
Sascha Michel
 

{smallsort}

Re:BCB5:Some observations when inserting components into a custom component

"Sascha Michel" < XXXX@XXXXX.COM >wrote in message
Quote
sorry, I should have made clear that my goal was to prevent
visually dropping components to a custom component
My previous reply already explained how to do that.
Quote
and informing the developer somehow that something has
not been accepted.
Why? No other component does that. The VCL is not set up for that specific
case, especially at design-time.
Gambit