Solved

Read Only Checkbox

Posted on 2004-04-21
9
292 Views
Last Modified: 2010-05-18
Hi all.

Hopefully this is an easy question..

I am writing an application that displays the status of true false attributes of an account using check boxes on a form.

I do not want the users to be able to uncheck - re-check the check boxes, but do not want the checkboxes to appear disabled as they tend to blend in with the form and look crappy.. (Technical term).

Is there a way to make the check boxes read only, or is there another check box component I can use for this??
0
Comment
Question by:BedouinDN
  • 4
  • 2
  • 2
  • +1
9 Comments
 
LVL 11

Accepted Solution

by:
shaneholmes earned 125 total points
ID: 10883516
Will need to derive a new component and handle the Mouse events yoruself:

type
  TReadOnlyCheckBox = class(TCheckBox)
  private
    fReadOnly: Boolean;
  protected
    procedure WmLButtonDown(var Msg: TWMLButtonDown);
        message Wm_LButtonDown;
    procedure WmLButtonUp(var Msg: TWMLButtonUp);
        message Wm_LButtonUp;
    procedure WmLButtonDblClk(var Msg: TWMLButtonDblClk);
        message Wm_LButtonDblClk;
  published
    property ReadOnly: Boolean read fReadOnly write fReadOnly;
  end;

...

procedure TReadOnlyCheckBox.WmLButtonDown(var Msg: TWMLButtonDown);
begin
  if not ReadOnly then
    inherited
  else
    Msg.Result := 0;
end;

procedure TReadOnlyCheckBox.WmLButtonUp(var Msg: TWMLButtonUp);
begin
  if not ReadOnly then
    inherited
  else
    Msg.Result := 0;
end;

procedure TReadOnlyCheckBox.WmLButtonDblClk(var Msg:
TWMLButtonDblClk);
begin
  if not ReadOnly then
    inherited
  else
    Msg.Result := 0;
end;



Shane
0
 

Expert Comment

by:steveaish
ID: 10883524
Not the tidiest way but have a private variable called Check1Checked type boolean

type
  TForm1 = class(TForm)
    CheckBox1: TCheckBox;
    procedure FormCreate(Sender: TObject);
  private
    Check1Checked : Boolean;

when you make your checkbox checked or unchecked also set this variable (Check1Checked := Checkbox1.Checked)

in the OnClick event of the Checkbox

procedure TForm1.CheckBox1Click(Sender: TObject);
begin
  if Checkbox1.Checked <> Check1Checked then
  begin
    Checkbox1.Checked := Check1Checked;
  end;
end;

0
 
LVL 17

Expert Comment

by:mokule
ID: 10883616

My solution to every problem is TPanel :)

Place CheckBoxes on a TPanel and set

Panel1.Enabled := False;

That's all
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 4

Author Comment

by:BedouinDN
ID: 10883696
Have accepted Shanes answer as I will be using this a lot and so will create a new derived Checkbox, Mokule - Your answer works beautifully and I will use yours for now until I get the time to create. Please look for "Points for Mokule" in the list for the same amount of points..

Steveaish, I have tried to do this but ended up in an endless loop until stack overflow - Seems setting the checked value calls the OnCLick method.. :-(

Thanks again guys..

Colin.
0
 
LVL 17

Expert Comment

by:mokule
ID: 10883698
Why You don't like TPanel :(
0
 
LVL 4

Author Comment

by:BedouinDN
ID: 10883703
Beat ya..
:-)
0
 
LVL 17

Expert Comment

by:mokule
ID: 10883711
Ooops. And yet You like it also. Thanks :))
I was too fast.
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10883807
I like Mokule solution as well, i may use that in the future for speediency.... <SMILE>

Shane
0
 
LVL 17

Expert Comment

by:mokule
ID: 10883904
Wow :)
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Delphi TcxGrid group footer summary 3 316
Help on project with Soap 10 57
Create Database on Android via Delphi dbExpress 3 110
FMX and jaudiotracker playing memory stream 29 85
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question