Board index » cppbuilder » Why SpeedButton( Assign ); is not working?

Why SpeedButton( Assign ); is not working?


2003-08-14 05:47:41 AM
cppbuilder114
I put 2 SpeedButtons on the form and i tried to copy the
properties of one button to the other, in the Click Event of
button2 i wrote this -
SpeedButton2->Assign( SpeedButton1 );
Why when i run it and press on SpeedButton2 then i get an error
which say "Cannot assign a TSpeedButton to a TSpeedButton"??
Thanks,
Ruby :-|
 
 

Re:Why SpeedButton( Assign ); is not working?

"Ruby" < XXXX@XXXXX.COM >wrote:
Quote
[...]
SpeedButton2->Assign( SpeedButton1 );

[...] i get an error which say "Cannot assign a TSpeedButton
to a TSpeedButton"??
Gambit explained it to me a while ago when I was trying to
assign (I think) one Panel to another but at that time I
didn't understand everything he said so remembering that it
doesn't always work was good enough for me.
I looked at the help for some clues and I see that Assign is
derived from TPersistent which "is the ancestor for all objects
that have assignment and streaming capabilities.".
I understand this to include objects that have methods like
LoadFrom... and SaveTo... like StringLists, Images ect..
~ JD
 

Re:Why SpeedButton( Assign ); is not working?

"Ruby" < XXXX@XXXXX.COM >wrote:
Quote

I did not understand your answer... the TSpeedButton have an
'Assign' method, whats does it used for then?
In all honesty, I can't think of a use for it.
Quote
SpeedButton2->Assign( SpeedButton1 );
i did not get any error or warning for this line at the compile,
why at runtime i get an error on this line? what is wrong with it?
Assign expects the parameter to be of type TPersistent.
Quote
do you mean that TSpeedButton have a method that can't be used?
At least not how you are using it.
Quote
If so, can i just write: SpeedButton2 = SpeedButton1;
will i get the same effect that i want?
That will just assign the address of SpeedButton1 to
SpeedButton2. If you have used 'new' to create SpeedButton2,
you will have just dereferenced SpeedButton2 which will almost
certainly cause an Access Violation when the form is destroyed.
If you're lucky, you'll only have a memory leak.
Quote
to copy ALL SpeedButton1's properties to SpeedButton2:
You'll need to do that manually. If you want a better
explaination as to why, You'll just have to check back to see
if someone that knows more than me posts to this thread.
~ JD
 

{smallsort}

Re:Why SpeedButton( Assign ); is not working?

OK JD, and thanks for your help :-)
"JD" < XXXX@XXXXX.COM >wrote:
Quote

"Ruby" < XXXX@XXXXX.COM >wrote:
>
>I did not understand your answer... the TSpeedButton have an
>'Assign' method, whats does it used for then?

In all honesty, I can't think of a use for it.

>SpeedButton2->Assign( SpeedButton1 );
>i did not get any error or warning for this line at the compile,
>why at runtime i get an error on this line? what is wrong with it?

Assign expects the parameter to be of type TPersistent.

>do you mean that TSpeedButton have a method that can't be used?

At least not how you are using it.

>If so, can i just write: SpeedButton2 = SpeedButton1;
>will i get the same effect that i want?

That will just assign the address of SpeedButton1 to
SpeedButton2. If you have used 'new' to create SpeedButton2,
you will have just dereferenced SpeedButton2 which will almost
certainly cause an Access Violation when the form is destroyed.
If you're lucky, you'll only have a memory leak.

>to copy ALL SpeedButton1's properties to SpeedButton2:

You'll need to do that manually. If you want a better
explaination as to why, You'll just have to check back to see
if someone that knows more than me posts to this thread.

~ JD
 

Re:Why SpeedButton( Assign ); is not working?

"JD" < XXXX@XXXXX.COM >wrote in message
Quote

"Ruby" < XXXX@XXXXX.COM >wrote:
>
>I did not understand your answer... the TSpeedButton have an
>'Assign' method, whats does it used for then?

In all honesty, I can't think of a use for it.

>SpeedButton2->Assign( SpeedButton1 );
>i did not get any error or warning for this line at the compile,
>why at runtime i get an error on this line? what is wrong with it?

Assign expects the parameter to be of type TPersistent.

>do you mean that TSpeedButton have a method that can't be used?

At least not how you are using it.

>If so, can i just write: SpeedButton2 = SpeedButton1;
>will i get the same effect that i want?

That will just assign the address of SpeedButton1 to
SpeedButton2. If you have used 'new' to create SpeedButton2,
you will have just dereferenced SpeedButton2 which will almost
certainly cause an Access Violation when the form is destroyed.
If you're lucky, you'll only have a memory leak.

>to copy ALL SpeedButton1's properties to SpeedButton2:

You'll need to do that manually. If you want a better
explaination as to why, You'll just have to check back to see
if someone that knows more than me posts to this thread.

~ JD

 

Re:Why SpeedButton( Assign ); is not working?

(Sorry for that empty post. I accidently double clicked on the 'Reply
Group' button)
"JD" < XXXX@XXXXX.COM >wrote in message
Quote

"Ruby" < XXXX@XXXXX.COM >wrote:
>If so, can i just write: SpeedButton2 = SpeedButton1;
>will i get the same effect that i want?

That will just assign the address of SpeedButton1 to
SpeedButton2. If you have used 'new' to create SpeedButton2,
you will have just dereferenced SpeedButton2 which will almost
certainly cause an Access Violation when the form is destroyed.
If you're lucky, you'll only have a memory leak.
Sorry to jump in like this, but I think that what you said is not correct.
SpeedButton1 and SpeedButton2 are most likely auto generated members of a
TForm-class. SpeedButton2 is just a pointer. Simply assigning it another
value does not cause AV's or memory leaks. The form owns the speedbuttons.
When the forms destroys, it will destroy them. The pointer SpeedButton2 is
not in play here, but a list of components maintained by the form itself
(TComponent::FComponents).
Ralph
 

Re:Why SpeedButton( Assign ); is not working?

"Ralph Kazemier" < XXXX@XXXXX.COM >wrote:
Quote
[...] I think that what you said is not correct. [...] Simply
assigning it another value does not cause AV's or memory leaks.
If you read my post again, you see that I said:
"... If you have used 'new' to create SpeedButton2, you will have just dereferenced SpeedButton2 ...".
That is absolutely correct and the errors will apply UNLESS he
does something PRIOR to dereferncing SpeedButton2 to prevent
them.
~ JD
 

Re:Why SpeedButton( Assign ); is not working?

"JD" < XXXX@XXXXX.COM >wrote in message
Quote

"Ralph Kazemier" < XXXX@XXXXX.COM >wrote:
>[...] I think that what you said is not correct. [...] Simply
>assigning it another value does not cause AV's or memory leaks.

If you read my post again, you see that I said:

"... If you have used 'new' to create SpeedButton2, you will have just
dereferenced SpeedButton2 ...".
Oops, sorry. I have no idea why I missed that... :$
Quote
That is absolutely correct and the errors will apply UNLESS he
does something PRIOR to dereferncing SpeedButton2 to prevent
them.
Yes.
Ralph
 

Re:Why SpeedButton( Assign ); is not working?

"Ruby" < XXXX@XXXXX.COM >wrote in message
Quote
Why when i run it and press on SpeedButton2 then i get
an error which say "Cannot assign a TSpeedButton to a
TSpeedButton"??
Because like many other VCL components, TSpeedButton does not actually
implement the Assign() method at all. You'll just have to copy the
properties manually one by one. Or else utilize the RTTI system in a loop,
at least. Either way, you have to do the copying yourself.
Gambit
 

Re:Why SpeedButton( Assign ); is not working?

"Ruby" < XXXX@XXXXX.COM >wrote in message
Quote
If so, can i just write: SpeedButton2 = SpeedButton1;

will i get the same effect that i want?
No. You are only assigning one pointer to another, not the actual objects
they point to.
Gambit
 

Re:Why SpeedButton( Assign ); is not working?

"JD" < XXXX@XXXXX.COM >wrote in message
Quote
Assign expects the parameter to be of type TPersistent.
Correction - Assign() expects a parameter that is a TPersistent instance.
That includes every VCL component, both visual and non-visual, as TComponent
is a descendant of TPersistent. However, persistence is an implementation
issue for each individual component to deal with on its own. Simply
deriving from TPersistent does not automatically guarantee persistence. It
only guarantees that an object can be stored persistently *if* the component
wants to allow itself to be persisted.
Gambit
 

Re:Why SpeedButton( Assign ); is not working?

"JD" < XXXX@XXXXX.COM >wrote in message
Quote
where have you been ?? !!! ??
I've been away from my computer for the last couple of days. I got new
office furniture on Tuesday so was spending all day reorganizing my room,
and then Wednesday I was gone all day with Jury Duty.
Gambit
 

Re:Why SpeedButton( Assign ); is not working?

"Remy Lebeau \(TeamB\)" < XXXX@XXXXX.COM >wrote:
Quote
[...] I got new office furniture on Tuesday
Lucky you.
Quote
Wednesday I was gone all day with Jury Duty.
Guilty or Not Guilty of what?
OH! Have you heard the one about selecting jurors? Goes something like: What's the point, choosing from a bunch of folks not smart enough to get out of it. <very big grin>LOL
~ JD
 

Re:Why SpeedButton( Assign ); is not working?

"JD" < XXXX@XXXXX.COM >wrote in message
Quote
Guilty or Not Guilty of what?
Have no clue, they call any of us up to the courtroom for anything. I just
sat in the waiting room all day reading a StarWars book :-)
Quote
OH! Have you heard the one about selecting jurors? Goes something
like: What's the point, choosing from a bunch of folks not smart enough
to get out of it. <very big grin>LOL
Hey, I already got out of it twice before. Does that make me stupid all of
a sudden? :-p
Gambit
 

Re:Why SpeedButton( Assign ); is not working?

"JD" < XXXX@XXXXX.COM >wrote in message
Quote
Next time, if you actually get into the jury box, before they
start to question you, you can get sent home early if you
point at the defendant and ask "Is that the guilty S.O.B.".
Followup posted to the .non-technical group.
Gambit