Thank you very much.
--
Best regards,
Diviner.
The easiest way is to dissable it.
ie MyCheckBox.Enabled := false;
You can still use the Checked property, but the box is greyed.
The problem I,ve always had with TCheckBox is that the OnClick event is
actually an OnChangeCheckState event.
Set the Checked property ie MyCheckBox.Checked := Boolean and OnClick still
comes. Resetting the state in OnClick causes and endless loop. I've always
found dissable sufficient and never bothered to find an alternative way of
doing it.
This has always been like this. I'm now using D4 but it was the same in D2.
What would be useful is an
OnBeforeStateChange(Sender : TObject ; State : Boolean, var CanDo :
Boolean);
Does anybody else know a way of doing what Deviner wants without deriving
from TCheckBox and overriding some method or other.
And is TCheckBox different in later Delphi's.
If that doesn't work then you can manage the state yourself and use code in the OnChange event like
inherited;
if not UserCanChange then
begin
TCheckBox(Sender).Checked := not TCheckBox(Sender);
end;
That is, let the change be made but immediately change it back. The user shouldn't see this.
Raymond KEnnington
I have a better way of doing this.
I have implemented a readonly property for the checkbox that works as
expected.
Only thing is i'm at work now, so you'll have to wait till this evening b4 i
can post it.
(That is if i can get my connection up today, else i'll have to make a
floppy and post it tomorrow)..
Greetz,
Arthuro..
Thank you very much. May I have a copy of your effort? :)
--
Best regards,
Diviner.
As i have promised here it is, my solution for the readonly checkbox.
What i do is overriding the toggle event method which is launched at the
precise moment that you click the checkbox to change it. I do an adittional
check against the new readonly property, and if its set i ignore the toggle
command, so the change never happens.
It's a crude hack but utterly simple, and verry clean..
The increase in size for the checkbox component is next to nothing...
Type
TReadOnlyCheckBox = Class(TCheckBox)
Private
{ Private declarations }
FReadOnly: Boolean;
Protected
{ Protected declarations }
Procedure Toggle; Override;
Public
{ Public declarations }
Constructor Create(AOwner: TComponent); override;
Published
{ Published declarations }
Property ReadOnly: Boolean Read FReadOnly Write FReadOnly;
End;
Implementation
Procedure TReadOnlyCheckBox.Toggle;
Begin
If Not FReadOnly Then
Inherited Toggle;
End;
Constructor TReadOnlyCheckBox.Create(AOwner: TComponent);
Begin
FReadOnly:= True;
Inherited Create(AOwner);
End;
But he will, if he has a fast computer.
I think my solution is better, although it works along the same lines.
I make it so that the change never happens in the first place.
The checkbox is never redrawn, and the status never changes.. See my other
post for the details details..