Solved

Read Only Checkbox

Posted on 2004-04-21
9
302 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses
Course of the Month9 days, 1 hour left to enroll

615 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