Board index » cppbuilder » a custom readonly TCheckBox

a custom readonly TCheckBox


2005-11-17 11:10:26 PM
cppbuilder62
After searching this group I found a partial solution to my problem. I need a custom
TCheckBox that can be made read only. From a thread titled "custom component and packages"
I figured out how to make and install a custom component. There are a few things that I haven't
figured out yet. I remember reading in the above thread that "Mind that you normally do not
derive from the final component, but from it's Custom version. I made a checkbox from the
TCustomCheckBox and as mentioned in the same thread, I don't see many of the properties.
I thought that perhaps as a learning exercise I could try to make my custom one with the
same properties as TCheckBox. Using Remy Lebeau's suggestion, I looked at TCheckBox
in QStdCtrls.pas then copied all the stuff under published. Most of them worked but I haven't
figured out all of them. I changed the property to __property that seems to be used on the
C++ side but the items with a default give a compile error. In the published section, how should
property Color default clBackground;
be written for C++?
My biggest question is still a mystery to me. How can I override a normal TCheckBox so that
it is read only? What do I need to intercept or tamper in order to get this behavior?
Damon Register
 
 

Re:a custom readonly TCheckBox

Damon Register wrote:
Quote
... I need a custom
TCheckBox that can be made read only.
What is a read only checkbox ? Didn't know that it was writable.
Hans.
 

Re:a custom readonly TCheckBox

On Thu, 17 Nov 2005 18:07:08 +0100, Hans Galema < XXXX@XXXXX.COM >wrote:
Quote
Damon Register wrote:
>... I need a custom
>TCheckBox that can be made read only.

What is a read only checkbox ? Didn't know that it was writable.
Maybe I am not using the right terminology. I want one that can be made to ignore a
user click. In old Borland (5.02) it used BS_CHECKBOX and BS_AUTOCHECKBOX
for the style. In CBuilder the TCheckBox behaves like BS_AUTOCHECKBOX
but I need to set a property that would make it behave like the BS_CHECKBOX.
Damon Register
 

{smallsort}

Re:a custom readonly TCheckBox

"Damon Register" < XXXX@XXXXX.COM >wrote in message
Quote
Maybe I am not using the right terminology. I want one that
can be made to ignore a user click. In old Borland (5.02) it
used BS_CHECKBOX and BS_AUTOCHECKBOX for
the style. In CBuilder the TCheckBox behaves like
BS_AUTOCHECKBOX but I need to set a property that
would make it behave like the BS_CHECKBOX.
You can change the default style for your descendant. Simply override the
virtual CreateParams() method.
Gambit
 

Re:a custom readonly TCheckBox

On Thu, 17 Nov 2005 10:36:52 -0800, "Remy Lebeau \(TeamB\)" < XXXX@XXXXX.COM >wrote:
Quote

"Damon Register" < XXXX@XXXXX.COM >wrote in message
news: XXXX@XXXXX.COM ...

>BS_AUTOCHECKBOX but I need to set a property that
>would make it behave like the BS_CHECKBOX.

You can change the default style for your descendant. Simply override the
virtual CreateParams() method.
This trick doesn't work for both VCL and CLX, does it? I have a bad feeling that it doesn't.
I searching Google, I found some really old (1998) posts on the subject. That one suggested
resetting the state in the OnClick handler and then adding some extra code to avoid the stack
overflow that would result from setting the Checked which in turn causes another OnClick...
Even if I could change the style at create time, I suppose that I would then have to keep
track of the state manually just like I used to with BS_CHECKBOX but it would be really
nice if I can have a read only property so that I can change its behavior at run time
Damon Register
 

Re:a custom readonly TCheckBox

Damon Register wrote:
Quote
Maybe I am not using the right terminology. I want one that can be made to ignore a
user click.
CheckBox1->Enabled = false;
Hans.
 

Re:a custom readonly TCheckBox

On Thu, 17 Nov 2005 20:39:51 +0100, Hans Galema < XXXX@XXXXX.COM >wrote:
Quote
Damon Register wrote:

>Maybe I am not using the right terminology. I want one that can be made to ignore a
>user click.

CheckBox1->Enabled = false;
Thanks for the suggestion but that doesn't solve the problem. I tried that but I get a grey
control and cannot set its state in my program. Here is the problem: I want a checkbox
that sometimes accepts a user click which sets some data item while at other times it
should only show the state of that data item but not allow the user to change it. I suppose
I could use a TButton and just change its appearance or make it owner draw but it would
be cool if I could just add this feature to a regular checkbox
Damon Register
 

Re:a custom readonly TCheckBox

"Damon Register" < XXXX@XXXXX.COM >wrote in message
Quote
Thanks for the suggestion but that doesn't solve the problem.
I tried that but I get a grey control and cannot set its state in
my program.
If you place the CheckBox onto a container, such as a TPanel, and then
disable the container, the Checkbox will retain its enabled look but it be
unclickable.
Quote
I want a checkbox that sometimes accepts a user click which
sets some data item while at other times it should only show the
state of that data item but not allow the user to change it.
Enable and disable the container when needed.
Gambit
 

Re:a custom readonly TCheckBox

Damon Register wrote:
Quote
>CheckBox1->Enabled = false;

Thanks for the suggestion but that doesn't solve the problem. I tried that but I get a grey
control
Yes. That is what the VCL does with disabled components.
Quote
and cannot set its state in my program.
Yes you can. Also when the control is disabled
CheckBox1->Checked = false/true;
does work.
Quote
Here is the problem: I want a checkbox
that sometimes accepts a user click which sets some data item while at other times it
should only show the state of that data item but not allow the user to change it.
That I understood already.
Hans.
 

Re:a custom readonly TCheckBox

On Thu, 17 Nov 2005 13:40:07 -0800, "Remy Lebeau \(TeamB\)" < XXXX@XXXXX.COM >wrote:
Quote
If you place the CheckBox onto a container, such as a TPanel, and then
disable the container, the Checkbox will retain its enabled look but it be
unclickable.
I saw that suggestion in another thread but it doesn't work. I just tested it
now and a TCheckBox on a TPanel gets the same grey disabled look
when the TPanel is disabled.
Damon Register
 

Re:a custom readonly TCheckBox

On Thu, 17 Nov 2005 13:40:07 -0800, "Remy Lebeau \(TeamB\)" < XXXX@XXXXX.COM >wrote:
Quote
If you place the CheckBox onto a container, such as a TPanel, and then
disable the container, the Checkbox will retain its enabled look but it be
unclickable.
Well, this is embarassing. I just discovered that this is an area where VCL and CLX
differ. My project is a CLX but I just tested your suggestion in VCL and I see it works
perfectly. Yes, I know this is a VCL group and there is a CLX group but that group
appears to be dead and I was hopping to find a method that would work for either
VCL or CLX.
In OWL I made a custom TCheckBox and overrode one of the functions (don't remember
which) to get a checkbox that would ignore the click. Is making a custom checkbox a
reasonable approach to this for both VCL and CLX?
Damon Register
 

Re:a custom readonly TCheckBox

Hi Damon,
Your question on 'property Color default clBackground;' maps to __property
TColor Color = { default = clBackground };
The other solution I think you might try is to create an empty OnClick
handler:
void __fastcall TForm1::CheckBox1Click(TObject *Sender)
{
return; // IDE do not delete me, I am not empty
}
Bruce
"Damon Register" < XXXX@XXXXX.COM >wrote in message
Quote
After searching this group I found a partial solution to my problem. I
need a custom
TCheckBox that can be made read only. From a thread titled "custom
component and packages"
I figured out how to make and install a custom component. There are a few
things that I haven't
figured out yet. I remember reading in the above thread that "Mind that
you normally do not
derive from the final component, but from it's Custom version. I made a
checkbox from the
TCustomCheckBox and as mentioned in the same thread, I don't see many of
the properties.
I thought that perhaps as a learning exercise I could try to make my
custom one with the
same properties as TCheckBox. Using Remy Lebeau's suggestion, I looked at
TCheckBox
in QStdCtrls.pas then copied all the stuff under published. Most of them
worked but I haven't
figured out all of them. I changed the property to __property that seems
to be used on the
C++ side but the items with a default give a compile error. In the
published section, how should
property Color default clBackground;
be written for C++?

My biggest question is still a mystery to me. How can I override a normal
TCheckBox so that
it is read only? What do I need to intercept or tamper in order to get
this behavior?

Damon Register