hidrau
asked on
Changing all the component in my form that tag = 5
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
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
ASKER
Isn't there any general way to this ? I must inform the component class like Tedit, Tbitbtn, etc
Thanks
Thanks
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]).Ena bled := false;
regards
something like for buttons for example:
if (Components[i] is TButton) and (Components[i].Tag=5) then
TButton(Components[i]).Ena
regards
for i:= 0 to ComponentCount - 1 do
begin
if (Components[i] is TEdit) and (Components[i].Tag=5) then
TEdit(Components[i]).Enabl ed := 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
begin
if (Components[i] is TEdit) and (Components[i].Tag=5) then
TEdit(Components[i]).Enabl
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
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:=fa lse;
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.
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:=fa
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.
nuts, I should remember to "refresh" before I post :)
David_Ward....
This does not work : Components[i1].enabled:=fa lse;
and the (Components[i1] as TEdit) is the same as TEdit(Components[i])
:)
This does not work : Components[i1].enabled:=fa
and the (Components[i1] as TEdit) is the same as TEdit(Components[i])
:)
No problem
:-)
:-)
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.
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.
:)
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;
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;
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;
end;
end;
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:=Fa lse; // not true; sorry :)
end;
end;
Regards
:-)
Should be like:
procedure TForm1.Button3Click(Sender
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:=Fa
end;
end;
Regards
:-)
ASKER
No David_Ward , it didn't work
You cannot refference a property of a component that you don't know what it is...
Do you test these code lines?
Do you test these code lines?
ASKER
so calinutz
Isn't there any way to do something more generic?
Isn't there any way to do something more generic?
David laughs at calinutz ...
I said I had not tested it, do you not read the posts :)
I said I had not tested it, do you not read the posts :)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks calinutz
alex
alex
" David laughs at calinutz ..."
:))
I only read question and code :-)
:))
I only read question and code :-)
Alex, I have no knowledge of a more generic way to do it.
And I really thing that there isn't any :(
regards
And I really thing that there isn't any :(
regards
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]).en abled := false;
end;
meikl ;-)
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]).en
end;
meikl ;-)
ASKER
Hello kretzschmar
Thanks for your help too.
Could you open this post for me so that I could spli the point once again?
Thanks
Thanks for your help too.
Could you open this post for me so that I could spli the point once again?
Thanks
>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 ;-)
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 ;-)
ASKER
ok thanks even though
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]).Enabl
end;
end;