SOLVED, BUT..: need to use control name in instruction lazarus / 62-General ---------------------------------------------------------------------- xaver13 · 2019-10-23 12:32 in Tabsheet2 I have a Tedit named kolik (and many others) I would like to set color of such controls using cycle - something as follows. I need an advice how to write it. My unsuccessfull attempts follow. I have name of the control (kolik) in variable a but I do not know how to set color of such control. Thank you very much for help. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i      for i := 0 to TabSheet2.ControlCount -1 do     begin       if TabSheet2.Controls[i] is TEdit then begin       //TabSheet2.Controls[i].Color := StringToColor('clBlack');       //TabSheet2.Controls[i].Font.Color := StringToColor('clSilver');     a:=(TabSheet2.Controls[i].Name);       //@a.Color:= StringToColor('clBlack');         kolik.Color := StringToColor('clBlack');       kolik.Font.Color := StringToColor('clSilver');        end;     end; ---------------------------------------------------------------------- af0815 · 2019-10-23 12:39 Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i for i := 0 to TabSheet2.ControlCount -1 do     begin       if TabSheet2.Controls[i] is TEdit then begin        TEdit( TabSheet2.Controls[i]).Color := StringToColor('clBlack');        TEdit( TabSheet2.Controls[i]).Font.Color := StringToColor('clSilver');       end;     end;  Only say the compiler the right type of the Element ---------------------------------------------------------------------- xaver13 · 2019-10-23 12:45 thank you very much it's workig ---------------------------------------------------------------------- lucamar · 2019-10-23 12:49 Or, if you want to do it by name: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i for i := 0 to TabSheet2.ControlCount -1 dobegin  if TabSheet2.Controls[i].Name = 'kolik' then begin    { Why bother with StringToColor(constant_name)? }    TEdit(TabSheet2.Controls[i]).Color := clBlack;    TEdit(TabSheet2.Controls[i]).Font.Color := clSilver;  end;end; Extrapolate for other names, of course. ---------------------------------------------------------------------- xaver13 · 2019-10-23 13:36 Thank you. I changed everything but buttons https://forum.lazarus.freepascal.org/index.php?topic=36774.0 I tried SpeedButtons and ColorButtons too. ---------------------------------------------------------------------- lucamar · 2019-10-23 17:21 You can do it for any descendant of TControl since most of them inherit their Name, Color and Font from the base class: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i for i := 0 to TabSheet2.ControlCount -1 dobegin  if TabSheet2.Controls[i].Name = 'kolik' then begin    TabSheet2.Controls[i].Color := clBlack;    TabSheet2.Controls[i].Font.Color := clSilver;  end;end; In that case you don't need to (and, indeed, shouldn't) hard-cast to the wanted class but use directly the TControl object returned by Controls "array" element getter. That should cope with almost any control whether a descendant of TWinControl, like TEdit, or of TGraphicControl, like TSpeedButton and TColorButton. HTH ---------------------------------------------------------------------- xaver13 · 2019-10-23 18:03 good, thank you! Now I am using Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i      for i := 0 to TabSheet2.ControlCount -1 do      if TabSheet2.Controls[i] is Tedit or TabSheet2.Controls[i] is TDBEdit or TabSheet2.Controls[i] is TLabel then begin        TabSheet2.Controls[i].Color := clBlack;      TabSheet2.Controls[i].Font.Color := clSilver;      end;  But maybe should be nicer something as:  Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i const    blackControls = [TEdit,TDBEdit,TLabel];begin     for i := 0 to TabSheet2.ControlCount -1 do      begin      if TabSheet2.Controls[i] in blackControls do begin        TabSheet2.Controls[i].Color := clBlack;        TabSheet2.Controls[i].Font.Color := clSilver;      end;end;  btw. this is not working yet  (const..Ordinal Expression expected, in..Operator is not overloaded), please, is it possible to use in there and how? I tried some overloading of 'in' but nothing was correct. ---------------------------------------------------------------------- howardpc · 2019-10-23 19:12 You can try some adaptation of this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit Unit1; {$mode objfpc}{$H+} interface uses  Forms, Controls, Graphics, ComCtrls, StdCtrls, Classes; type   TForm1 = class(TForm)    Button1: TButton;    Edit1: TEdit;    Label1: TLabel;    PageControl1: TPageControl;    TabSheet1: TTabSheet;    TabSheet2: TTabSheet;    TestButton: TButton;    procedure TestButtonClick(Sender: TObject);  end;   procedure SetControlColorsInTabsheet(aTabSheet: TTabSheet;          aColor, aFontColor: TColor; aControlClasses: array of const); var  Form1: TForm1; implementation procedure SetControlColorsInTabsheet(aTabSheet: TTabSheet; aColor,             aFontColor: TColor; aControlClasses: array of const);   function DesiredControlClass(aControlClass: TControlClass): Boolean;  var    vr: TVarRec;  begin    for vr in aControlClasses do      if (vr.VType = vtClass) and (vr.VClass = aControlClass) then        Exit(True);    Result := False;  end; var  i: Integer;begin  with aTabSheet do    for i := 0 to ControlCount-1 do      if DesiredControlClass(TControlClass(Controls[i].ClassType)) then        begin          Controls[i].Color := aColor;          Controls[i].Font.Color := aFontColor;        end;end; {$R *.lfm} { TForm1 } procedure TForm1.TestButtonClick(Sender: TObject);begin  SetControlColorsInTabsheet(TabSheet2, clBlue, clSilver, [TEdit, TButton, TLabel]);end; end. ---------------------------------------------------------------------- ASerge · 2019-10-24 20:56 Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i var  C: TControl;begin  for C in TabSheet2.GetEnumeratorControls do    if C.Name = VariableWithKolikName then    begin      C.Color := clBlack;      C.Font.Color := clSilver;    end;end;or Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i var  C: TControl;begin  for C in TabSheet2.GetEnumeratorControls do    case C.Name of      'kolik':        begin          C.Color := clBlack;        C.Font.Color := clSilver;        end;      'OtherName':        begin          //...        end;    end;end; ---------------------------------------------------------------------- xaver13 · 2019-10-26 07:36 Thank you very much ASerge my old version: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   for i := 0 to GroupBox1.ControlCount - 1 do  begin    if GroupBox1.Controls[i] is Tedit or GroupBox1.Controls[i] is      TDBEdit or GroupBox1.Controls[i] is TLabel      or GroupBox1.Controls[i] is TComboBox      then      begin      GroupBox1.Controls[i].Color := myDark;      GroupBox1.Controls[i].Font.Color := clSilver;    end;  end;   new version by you Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   var  C: TControl;..for C in GroupBox1.GetEnumeratorControls do      begin      C.Color := myDark;        C.Font.Color := clSilver;      end;