Fórum Converter String em Label #294576
05/09/2005
0
for i := 1 to 200 do
´ME´+IntToStr(i).Caption:= ´Algo´;
Exemplo
ME1.Caption:= ´Algo´;
ME2.Caption:= ´Algo´;
ME3.Caption:= ´Algo´;
ME4.Caption:= ´Algo´;
ME5.Caption:= ´Algo´;
...
Eu tenho 200 Label e precisso que coloque todos iguais então como vou fazer isso??
Rudá
Curtir tópico
+ 0Posts
05/09/2005
Steve_narancic
var lb: TLabel; i: integer; begin for i:= 0 to 200 do begin lb := TLabel.Create(); lb.Name := ´ME´+IntToStr(i); lb.Parent:= CRM_Principal; lb.Top:= i; lb.Left:= i; lb.Caption := ´ME´+IntToStr(i); lb.Visible:= true; end;
Gostei + 0
05/09/2005
Michael
Se vc tem absoluta certeza que todos os labels existem, pode usar o seguinte código:
for I := 1 to 200 do TLabel(FindComponent(´ME´ + IntToStr(I))).Caption := ´Algo´;
Se vc não tem esta certeza, então use este outro:
var oControl : TComponent; (...) for I := 1 to 200 do begin oControl := FindComponent(´ME´ + IntToStr(I)); if Assigned(oControl) then TLabel(oControl).Caption := ´Algo´; end;
[]´s
Gostei + 0
05/09/2005
Steve_narancic
for i:= 0 to ComponentCount do begin if Components[i] is TLabel then (Components[i] as TLabel).Caption := ´Algo´; end;
Gostei + 0
05/09/2005
Massuda
var Componente: TComponente; .... Componente := FindComponent(´NomeDoComponente´); if Componente <> nil then begin // encontrou o componente end; ...
Gostei + 0
06/09/2005
Rudá
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)