?
Solved

Changing all the component in my form that tag = 5

Posted on 2006-03-30
24
Medium Priority
?
229 Views
Last Modified: 2010-04-05
Hello guys

I would like to create a " for " where I could get all the components on my form that has in their tag the value 5 and changed their propert enabled to false.

Thanks
0
Comment
Question by:hidrau
  • 10
  • 6
  • 6
  • +1
24 Comments
 
LVL 11

Expert Comment

by:calinutz
ID: 16332661
Disable all Edits on a form that have TAG=5:


var
   i : integer;
begin
   for i:= 0  to ComponentCount - 1 do
     begin
     if (Components[i] is TEdit) and (Components[i].Tag=5) then
        TEdit(Components[i]).Enabled := false;
     end;
end;
0
 
LVL 1

Author Comment

by:hidrau
ID: 16332694
Isn't there any general way to this ? I must inform the component class like Tedit, Tbitbtn, etc

Thanks
0
 
LVL 11

Expert Comment

by:calinutz
ID: 16332697
Just add If clauses for any other kind of components that you have on your form that you want to disable in the FOR loop
something like for buttons for example:

     if (Components[i] is TButton) and (Components[i].Tag=5) then
        TButton(Components[i]).Enabled := false;


regards
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 11

Expert Comment

by:calinutz
ID: 16332761
for i:= 0  to ComponentCount - 1 do
     begin
     if (Components[i] is TEdit) and (Components[i].Tag=5) then
        TEdit(Components[i]).Enabled := false;

     if (Components[i] is TButton) and (Components[i].Tag=5) then
        TButton(Components[i]). Enabled := false;

     if (Components[i] is TLabel) and (Components[i].Tag=5) then
        TLabel(Components[i]). Enabled := false;

     if (Components[i] is TMemo) and (Components[i].Tag=5) then
        TMemo(Components[i]). Enabled := false;

// and so on for all kinds of components that you are using on that form

     end;



Regards
0
 
LVL 4

Expert Comment

by:David_Ward
ID: 16332763
You could try something like this, I think it "should" work ...

in the .Create event for your form add this code;

  for i1:=0 to ComponentCount-1 do
    begin
      if Components[i1].tag=5 then
        Components[i1].enabled:=false;
    end;

Remeber to declare -

var
  i1:                  integer;

 - in there too.

If that does not work, you may have to get a little more specific, as follows;

  for i1:=0 to ComponentCount-1 do
    begin
       // replace TButton with your specific component types ...

       if Components[i1] is Tbutton then
         begin
            if (Components[i1] as TButton).Tag=5 then
              (Components[i1] as TButton).Enabled:=false;
         end
         else
           if Components[i1] is TEditBox then
             begin
                if (Components[i1] as TEditBox).Tag=5 then
                  (Components[i1] as TEditBox).Enabled:=false;
             end;

       // and so on ...
    end;



Cheers,

David.
0
 
LVL 4

Expert Comment

by:David_Ward
ID: 16332781
nuts, I should remember to "refresh" before I post :)

0
 
LVL 11

Expert Comment

by:calinutz
ID: 16332793
David_Ward....
This does not work :         Components[i1].enabled:=false;
and the                            (Components[i1] as TEdit)    is the same as TEdit(Components[i])

:)
0
 
LVL 11

Expert Comment

by:calinutz
ID: 16332806
No problem
:-)
0
 
LVL 4

Expert Comment

by:David_Ward
ID: 16332833
yep, I said the first bit might be too general

and as for: "(Components[i1] as TEdit)    is the same as TEdit(Components[i])" I know :) but we all have our own little ways now, dont we.
0
 
LVL 4

Expert Comment

by:David_Ward
ID: 16332889
:)

What about this ... It might be worth a try ... (I have not tested it, just kicking it around ...)

var
  ThisObject: TObject;
  i1:              Integer;

begin
  for i1:=0 to pred(COmponentCount) do
     begin
        ThisObject:=Components[i1];

         if ThisObject.Tag=5 then
           ThisObject.ENabled:=true;
     end;
end;
0
 
LVL 4

Expert Comment

by:David_Ward
ID: 16332911

var
  ThisObject: TObject;
  i1:              Integer;

begin
  for i1:=0 to pred(COmponentCount) do
     begin
        ThisObject:=Components[i1];

         if ThisObject.Tag=5 then
           ThisObject.ENabled:=False;  // not true; sorry :)
     end;
end;
0
 
LVL 11

Expert Comment

by:calinutz
ID: 16333000
Still does not work this way... You must specify the type of the component

Should be like:

procedure TForm1.Button3Click(Sender: TObject);
var
  thisObj:TObject;
 i1:              Integer;

begin
  for i1:=0 to pred(COmponentCount) do
     begin
        ThisObj:=Components[i1];
         If ThisObj is TEdit then
         if TEdit(ThisObj).Tag=5 then
           TEdit(ThisObj).ENabled:=False;  // not true; sorry :)
     end;
end;

Regards
:-)
0
 
LVL 1

Author Comment

by:hidrau
ID: 16333011
No David_Ward , it didn't work
0
 
LVL 11

Expert Comment

by:calinutz
ID: 16333045
You cannot refference a property of a component that you don't know what it is...
Do you test these code lines?
0
 
LVL 1

Author Comment

by:hidrau
ID: 16333060
so calinutz
Isn't there any way to do something more generic?

0
 
LVL 4

Expert Comment

by:David_Ward
ID: 16333118
David laughs at calinutz ...

I said I had not tested it, do you not read the posts :)

0
 
LVL 11

Accepted Solution

by:
calinutz earned 2000 total points
ID: 16333120
It should not be that difficult to question all kinds of components in a for statement...


var
   i : integer;
begin
   for i:= 0  to ComponentCount - 1 do
   If Components[i].Tag=5 then
   begin
    if (Components[i] is TEdit) then TEdit(Components[i]).Enabled := false;
    if (Components[i] is TButton) then TButton(Components[i]). Enabled := false;
    if (Components[i] is TMemo) then TMemo(Components[i]). Enabled := false;
    if (Components[i] is TLabel) then TLabel(Components[i]). Enabled := false;
    if (Components[i] is TComboBox) then TComboBox(Components[i]). Enabled := false;
    if (Components[i] is TCheckBox) then TCheckBox(Components[i]). Enabled := false;
    if (Components[i] is TRadioButton) then TRadioButton(Components[i]). Enabled := false;
   end;
end;
0
 
LVL 1

Author Comment

by:hidrau
ID: 16333145
Thanks calinutz
alex
0
 
LVL 11

Expert Comment

by:calinutz
ID: 16333150
" David laughs at calinutz ..."

:))

I only read question and code :-)
0
 
LVL 11

Expert Comment

by:calinutz
ID: 16333172
Alex, I have no knowledge of a more generic way to do it.
And I really thing that there isn't any :(

regards
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 16334234
usual the property enabled is introduced and published with tcontrol


so it should be simplified to

var
   i : integer;
begin
   for i:= 0  to ComponentCount - 1 do
     If (Components[i].Tag=5) and (Components[i] is TControl) then
       TControl(Components[i]).enabled := false;
end;

meikl ;-)

0
 
LVL 1

Author Comment

by:hidrau
ID: 16334394
Hello kretzschmar

Thanks for your help too.
Could you open this post for me so that I could spli the point once again?

Thanks
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 16334772
>Could you open this post for me so that I could spli the point once again?

this is not needed, hidrau, i have really enough points :-))

additional i was far too late . . .

its enough for me, if you find it usefull

meikl ;-)
0
 
LVL 1

Author Comment

by:hidrau
ID: 16334801
ok thanks even though
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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…
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…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses
Course of the Month14 days, 9 hours left to enroll

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