| | |
using only one procedure for more than one components
Please support our Pascal and Delphi advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Nov 2007
Posts: 29
Reputation:
Solved Threads: 0
Now I want to know how I will short my code lines within one procudures just as sharing of events in only one procedures. for now I have written my program code like that but I want to learn how I will use events for 5 components within IF conditions. pls tell me how I will short these code line below. If you write to me or any sample like solution of below code scope I will be very glad from you..
procedure TAnaform.CheckBox2Click(Sender: TObject);
begin
if Checkbox2.Checked then
begin
Anaform.DIKEYAC2.Visible:=True;
Anaform.YATAYKAPA2.Visible:=False;
end;
if not (Checkbox2.Checked) then
begin
Anaform.DIKEYAC2.Visible:=False;
Anaform.YATAYKAPA2.Visible:=True;
end;
end;
procedure TAnaform.CheckBox3Click(Sender: TObject);
begin
if Checkbox3.Checked then
begin
Anaform.DIKEYAC3.Visible:=True;
Anaform.YATAYKAPA3.Visible:=False;
end;
if not (Checkbox3.Checked) then
begin
Anaform.DIKEYAC3.Visible:=False;
Anaform.YATAYKAPA3.Visible:=True;
end;
end;
procedure TAnaform.CheckBox4Click(Sender: TObject);
begin
if Checkbox4.Checked then
begin
Anaform.DIKEYAC4.Visible:=True;
Anaform.YATAYKAPA4.Visible:=False;
end;
if not (Checkbox4.Checked) then
begin
Anaform.DIKEYAC4.Visible:=False;
Anaform.YATAYKAPA4.Visible:=True;
end;
end;
procedure TAnaform.CheckBox5Click(Sender: TObject);
begin
if Checkbox5.Checked then
begin
Anaform.DIKEYAC5.Visible:=True;
Anaform.YATAYKAPA5.Visible:=False;
end;
if not (Checkbox5.Checked) then
begin
Anaform.DIKEYAC5.Visible:=False;
Anaform.YATAYKAPA5.Visible:=True;
end;
end;
procedure TAnaform.CheckBox2Click(Sender: TObject);
begin
if Checkbox2.Checked then
begin
Anaform.DIKEYAC2.Visible:=True;
Anaform.YATAYKAPA2.Visible:=False;
end;
if not (Checkbox2.Checked) then
begin
Anaform.DIKEYAC2.Visible:=False;
Anaform.YATAYKAPA2.Visible:=True;
end;
end;
procedure TAnaform.CheckBox3Click(Sender: TObject);
begin
if Checkbox3.Checked then
begin
Anaform.DIKEYAC3.Visible:=True;
Anaform.YATAYKAPA3.Visible:=False;
end;
if not (Checkbox3.Checked) then
begin
Anaform.DIKEYAC3.Visible:=False;
Anaform.YATAYKAPA3.Visible:=True;
end;
end;
procedure TAnaform.CheckBox4Click(Sender: TObject);
begin
if Checkbox4.Checked then
begin
Anaform.DIKEYAC4.Visible:=True;
Anaform.YATAYKAPA4.Visible:=False;
end;
if not (Checkbox4.Checked) then
begin
Anaform.DIKEYAC4.Visible:=False;
Anaform.YATAYKAPA4.Visible:=True;
end;
end;
procedure TAnaform.CheckBox5Click(Sender: TObject);
begin
if Checkbox5.Checked then
begin
Anaform.DIKEYAC5.Visible:=True;
Anaform.YATAYKAPA5.Visible:=False;
end;
if not (Checkbox5.Checked) then
begin
Anaform.DIKEYAC5.Visible:=False;
Anaform.YATAYKAPA5.Visible:=True;
end;
end;
Same kind of answer as in your other thread.
For each tCheckBox, set the tag property to 1, 2, 3, etc. as appropriate. Then give them all an onClick event method like this:
Again, untested! Of course, I don't know what type of things DIKEYAC and YATAYKAPA are, so I just used "tLabel". You'll need to cast to the correct type of thing...
Also, please use [code] tags...
For each tCheckBox, set the tag property to 1, 2, 3, etc. as appropriate. Then give them all an onClick event method like this:
Delphi Syntax (Toggle Plain Text)
procedure tAnaForm.CheckBoxClick( sender: tObject ); begin if tCheckBox( sender ).checked then begin tLabel( AnaForm.findComponent( 'DIKEYAC' +intToStr( sender.tag ) ) ).visible := true; ... end else begin ... end end;
Also, please use [code] tags...
Last edited by Duoas; Nov 26th, 2007 at 12:30 pm.
The "tag" doesn't do anything. It's just a longint value you can use for whatever you like.
I've used it above to uniquely identify the components you wish to change when you click a checkbox item.
So yataykapa1 gets modified by the checkbox whose tag is 1, and yataykapa2 gets modified by the checkbox whose tag is 2, etc.
Hope this helps.
I've used it above to uniquely identify the components you wish to change when you click a checkbox item.
So yataykapa1 gets modified by the checkbox whose tag is 1, and yataykapa2 gets modified by the checkbox whose tag is 2, etc.
Hope this helps.
•
•
•
•
For each tCheckBox, set the tag property to 1, 2, 3, etc. as appropriate. Then give them all an onClick event method like this:
Delphi Syntax (Toggle Plain Text)
procedure tAnaForm.CheckBoxClick( sender: tObject ); begin if tCheckBox( sender ).checked then begin tLabel( AnaForm.findComponent( 'DIKEYAC' +intToStr( sender.tag ) ) ).visible := true; ... end else begin ... end end;
But just let me to add that some problem that could be gotten by using type-cast without test returned value. If the component could not be found (bad name or disposed), an exception will occur. Just a sugestion to prevent this:
Delphi Syntax (Toggle Plain Text)
procedure tAnaForm.CheckBoxClick( sender: tObject ); var FoundComp :TComponent; begin if tCheckBox( sender ).checked then begin FoundComp := AnaForm.findComponent( 'DIKEYAC' +intToStr( sender.tag ) ); if FoundComp <> nil then tLabel( FoundComp ).visible := true; ... end ... end;
bye
"It always has, at least, two ways to make one same thing. Exactly that they are certain and wrong"(Micheus)
Brazil - Blumenau
Brazil - Blumenau
It depends. In this case I want an exception to occur, because that would mean he mis-programmed his form, and it will let him know if he does.
That is, it is an inviolate part of his design that the checkbox reference a specific component. This is easily done in the forms designer. Failure to do this causes a runtime exception when testing each button.
If you are aiming to find a component based on some other criteria, then by all means you must validate the result, since it is no longer a design assertion but a very possible runtime error.
Hope this helps.
That is, it is an inviolate part of his design that the checkbox reference a specific component. This is easily done in the forms designer. Failure to do this causes a runtime exception when testing each button.
If you are aiming to find a component based on some other criteria, then by all means you must validate the result, since it is no longer a design assertion but a very possible runtime error.
Hope this helps.
![]() |
Similar Threads
- Why won't this code work? (VB.NET)
- passing parameter to Store Procedure in SqlDataAdapter (VB.NET)
- Cant add/remove win components (Windows NT / 2000 / XP)
- Hardware - Cases - Want to separate components (Troubleshooting Dead Machines)
- Dangerous Bug in HijackThis 1.97.7 Restoral Procedure (Viruses, Spyware and other Nasties)
- Use Hibernate and Standby to Conserve Batteries (Windows tips 'n' tweaks)
- need help with newly built computer (Windows NT / 2000 / XP)
- Beware of Bad Capacitors (source of much bizarre behavior) (Motherboards, CPUs and RAM)
Other Threads in the Pascal and Delphi Forum
- Previous Thread: School assignment help
- Next Thread: three timer component problem inside my checkbox event procedure
Views: 1061 | Replies: 6
| Thread Tools | Search this Thread |
Tag cloud for Pascal and Delphi






