From Clomosy Docs

No edit summary
No edit summary
Line 1: Line 1:
To find another component under a component or form, clFindComponent is used. This method allows you to search for a specific named subcomponent. This allows making changes to the properties of the found component.
<div class="alert alert-ligth border border-3 border-primary-subtle rounded-5 p-4 shadow-sm" role="alert">
Form1.clFindComponent(xObjectName : String): TComponent;
</div>


MyForm.clFindComponent(xObjectName : String): TComponent;
To find another component under a component or form, clFindComponent is used. This method allows you to search for a specific named subcomponent. This allows making changes to the properties of the found component.<br>


Within this feature, a string parameter is accepted, and this parameter is the name of the variable.
Within this feature, a string parameter is accepted, and this parameter is the name of the variable.


'''Example:'''<br>
<b>Example</b><br>
In the example, we can determine which of the multiple buttons created using the clSender feature we clicked on and change the button text using the clFindComponent property.
In the example, we can determine which of the multiple buttons created using the clSender feature we clicked on and change the button text using the clFindComponent property.<br>
 
<b>TRObject Syntax</b><br>
:'''TRObject Syntax:'''
<pre>
  Var   
Var   
    MyForm:TclForm;
  MyForm:TclForm;
    mainPnl : TclProPanel;
  mainPnl : TclProPanel;
    testBtn : TClProButton;
  testBtn : TClProButton;
    i,j : Integer;
  i,j : Integer;
    Combo1 : TClComboBox;
  Combo1 : TClComboBox;
 
  void ComboSelected;
procedure ComboSelected;
  var
var
    strKey : String;
  strKey : String;
  {
begin
    strKey = Combo1.GetItemIndex(Combo1.ItemIndex);
  strKey := Combo1.GetItemIndex(Combo1.ItemIndex);
  if (Combo1.ItemIndex <> '0')
  if Combo1.ItemIndex <> '0' then
  {
    TClProButton(MyForm.clFindComponent(strKey)).Caption = strKey+'+';
    TClProButton(MyForm.clFindComponent(strKey)).Enabled = false;
  }
  }
  {
    MyForm=TclForm.Create(self);
   
    Combo1 = MyForm.AddNewComboBox(MyForm,'Combo1');
    Combo1.Align = alMostTop;
    Combo1.Height = 20;
    Combo1.Margins.Top=10;
    Combo1.Margins.Left =MyForm.clWidth/9;
    Combo1.Margins.Right =MyForm.clWidth/9;
   
    Combo1.AddItem('Please select the button to be marked.','0');
    for (j = 1 to 5)
      Combo1.AddItem('testBtn'+IntToStr(j),IntToStr(j));
    MyForm.AddNewEvent(Combo1,tbeOnChange,'ComboSelected');
   
   
    mainPnl=MyForm.AddNewProPanel(MyForm,'mainPnl');
    clComponent.SetupComponent(mainPnl,'{"Align" : "Center","Width" :200,
    "Height":300,"RoundHeight":10,"RoundWidth":10,"BorderColor":"#3a32a8","BorderWidth":2}');
   
    for (i = 0 to 4)
    {
      testBtn = MyForm.AddNewProButton(mainPnl,'testBtn'+IntToStr(i+1),<nowiki>''</nowiki>);
      clComponent.SetupComponent(testBtn,'{"caption":"testBtn'+IntToStr(i+1)+'","Align" : "Top","MarginTop":5,"MarginLeft":5,"MarginRight":5,
      "Height":50}');
      MyForm.SetImage(testBtn,'https://clomosy.com/demos/foodInformationBox.png');
    }
   
    MyForm.Run;
  }
 
:'''Base Syntax'''
  Var 
    MyForm:TclForm;
    mainPnl : TclProPanel;
    testBtn : TClProButton;
    i,j : Integer;
    Combo1 : TClComboBox;
 
  procedure ComboSelected;
  var
    strKey : String;
   begin
   begin
    strKey := Combo1.GetItemIndex(Combo1.ItemIndex);
  TClProButton(MyForm.clFindComponent(strKey)).Caption := strKey+'+';
   if Combo1.ItemIndex <> '0' then
  TClProButton(MyForm.clFindComponent(strKey)).Enabled := false;
  end;
end;
begin
  MyForm :=TclForm.Create(self);
 
  Combo1 := MyForm.AddNewComboBox(MyForm,'Combo1');
  Combo1.Align := alMostTop;
  Combo1.Height := 20;
  Combo1.Margins.Top:=10;
  Combo1.Margins.Left :=MyForm.clWidth/9;
  Combo1.Margins.Right :=MyForm.clWidth/9;
 
  Combo1.AddItem('Please select the button to be marked.','0');
  for j := 1 to 5 do
    Combo1.AddItem('testBtn'+IntToStr(j),IntToStr(j));
   MyForm.AddNewEvent(Combo1,tbeOnChange,'ComboSelected');
 
 
  mainPnl:=MyForm.AddNewProPanel(MyForm,'mainPnl');
  clComponent.SetupComponent(mainPnl,'{"Align" : "Center","Width" :200,
  "Height":300,"RoundHeight":10,"RoundWidth":10,"BorderColor":"#3a32a8","BorderWidth":2}');
 
  for i := 0 to 4 do
   begin
   begin
    TClProButton(MyForm.clFindComponent(strKey)).Caption := strKey+'+';
    testBtn := MyForm.AddNewProButton(mainPnl,'testBtn'+IntToStr(i+1),'');
    TClProButton(MyForm.clFindComponent(strKey)).Enabled := false;
    clComponent.SetupComponent(testBtn,'{"caption":"testBtn'+IntToStr(i+1)+'","Align" : "Top","MarginTop":5,"MarginLeft":5,"MarginRight":5,
    "Height":50}');
    MyForm.SetImage(testBtn,'https://clomosy.com/demos/foodInformationBox.png');  
   end;
   end;
  end;
 
  MyForm.Run;
end;
</pre>
<b>Base Syntax</b><br>
<pre>
Var 
  MyForm:TclForm;
  mainPnl : TclProPanel;
  testBtn : TClProButton;
  i,j : Integer;
  Combo1 : TClComboBox;
procedure ComboSelected;
var
  strKey : String;
begin
  strKey := Combo1.GetItemIndex(Combo1.ItemIndex);
  if Combo1.ItemIndex <> '0' then
   begin
   begin
    MyForm :=TclForm.Create(self);
  TClProButton(MyForm.clFindComponent(strKey)).Caption := strKey+'+';
   
  TClProButton(MyForm.clFindComponent(strKey)).Enabled := false;
    Combo1 := MyForm.AddNewComboBox(MyForm,'Combo1');
    Combo1.Align := alMostTop;
    Combo1.Height := 20;
    Combo1.Margins.Top:=10;
    Combo1.Margins.Left :=MyForm.clWidth/9;
    Combo1.Margins.Right :=MyForm.clWidth/9;
   
    Combo1.AddItem('Please select the button to be marked.','0');
    for j := 1 to 5 do
      Combo1.AddItem('testBtn'+IntToStr(j),IntToStr(j));
    MyForm.AddNewEvent(Combo1,tbeOnChange,'ComboSelected');
   
   
    mainPnl:=MyForm.AddNewProPanel(MyForm,'mainPnl');
    clComponent.SetupComponent(mainPnl,'{"Align" : "Center","Width" :200,
    "Height":300,"RoundHeight":10,"RoundWidth":10,"BorderColor":"#3a32a8","BorderWidth":2}');
   
    for i := 0 to 4 do
    begin
      testBtn := MyForm.AddNewProButton(mainPnl,'testBtn'+IntToStr(i+1),<nowiki>''</nowiki>);
      clComponent.SetupComponent(testBtn,'{"caption":"testBtn'+IntToStr(i+1)+'","Align" : "Top","MarginTop":5,"MarginLeft":5,"MarginRight":5,
      "Height":50}');
      MyForm.SetImage(testBtn,'https://clomosy.com/demos/foodInformationBox.png');
    end;
   
    MyForm.Run;
   end;
   end;
end;
begin
  MyForm :=TclForm.Create(self);
 
  Combo1 := MyForm.AddNewComboBox(MyForm,'Combo1');
  Combo1.Align := alMostTop;
  Combo1.Height := 20;
  Combo1.Margins.Top:=10;
  Combo1.Margins.Left :=MyForm.clWidth/9;
  Combo1.Margins.Right :=MyForm.clWidth/9;
 
  Combo1.AddItem('Please select the button to be marked.','0');
  for j := 1 to 5 do
    Combo1.AddItem('testBtn'+IntToStr(j),IntToStr(j));
  MyForm.AddNewEvent(Combo1,tbeOnChange,'ComboSelected');
 
 
  mainPnl:=MyForm.AddNewProPanel(MyForm,'mainPnl');
  clComponent.SetupComponent(mainPnl,'{"Align" : "Center","Width" :200,
  "Height":300,"RoundHeight":10,"RoundWidth":10,"BorderColor":"#3a32a8","BorderWidth":2}');
 
  for i := 0 to 4 do
  begin
    testBtn := MyForm.AddNewProButton(mainPnl,'testBtn'+IntToStr(i+1),'');
    clComponent.SetupComponent(testBtn,'{"caption":"testBtn'+IntToStr(i+1)+'","Align" : "Top","MarginTop":5,"MarginLeft":5,"MarginRight":5,
    "Height":50}');
    MyForm.SetImage(testBtn,'https://clomosy.com/demos/foodInformationBox.png');
  end;
 
  MyForm.Run;
end;
</pre>
<b>Output:</b><br>
[[File:ClFindComponentExampleV1.0.png|frameless|500px]]<br>


= See Also=
<h2> See Also </h2>
* [[Controls| Controls]]
* [[System_Library#Cl_Utilities_Functions | Cl Utilities Functions]]

Revision as of 10:25, 10 October 2024

To find another component under a component or form, clFindComponent is used. This method allows you to search for a specific named subcomponent. This allows making changes to the properties of the found component.

Within this feature, a string parameter is accepted, and this parameter is the name of the variable.

Example
In the example, we can determine which of the multiple buttons created using the clSender feature we clicked on and change the button text using the clFindComponent property.
TRObject Syntax

 Var  
   MyForm:TclForm;
   mainPnl : TclProPanel;
   testBtn : TClProButton;
   i,j : Integer;
   Combo1 : TClComboBox;
 
 procedure ComboSelected;
 var
   strKey : String;
 begin
   strKey := Combo1.GetItemIndex(Combo1.ItemIndex);
  if Combo1.ItemIndex <> '0' then
  begin
   TClProButton(MyForm.clFindComponent(strKey)).Caption := strKey+'+';
   TClProButton(MyForm.clFindComponent(strKey)).Enabled := false;
  end;
 end;
 begin
   MyForm :=TclForm.Create(self);
   
   Combo1 := MyForm.AddNewComboBox(MyForm,'Combo1');
   Combo1.Align := alMostTop;
   Combo1.Height := 20;
   Combo1.Margins.Top:=10;
   Combo1.Margins.Left :=MyForm.clWidth/9;
   Combo1.Margins.Right :=MyForm.clWidth/9;
   
   Combo1.AddItem('Please select the button to be marked.','0');
   for j := 1 to 5 do
     Combo1.AddItem('testBtn'+IntToStr(j),IntToStr(j));
   MyForm.AddNewEvent(Combo1,tbeOnChange,'ComboSelected');
   
   
   mainPnl:=MyForm.AddNewProPanel(MyForm,'mainPnl');
   clComponent.SetupComponent(mainPnl,'{"Align" : "Center","Width" :200, 
   "Height":300,"RoundHeight":10,"RoundWidth":10,"BorderColor":"#3a32a8","BorderWidth":2}');
   
   for i := 0 to 4 do
   begin
     testBtn := MyForm.AddNewProButton(mainPnl,'testBtn'+IntToStr(i+1),'');
     clComponent.SetupComponent(testBtn,'{"caption":"testBtn'+IntToStr(i+1)+'","Align" : "Top","MarginTop":5,"MarginLeft":5,"MarginRight":5,
     "Height":50}');
     MyForm.SetImage(testBtn,'https://clomosy.com/demos/foodInformationBox.png'); 
   end;
   
   MyForm.Run;
 end;

Base Syntax

 Var  
   MyForm:TclForm;
   mainPnl : TclProPanel;
   testBtn : TClProButton;
   i,j : Integer;
   Combo1 : TClComboBox;
 
 procedure ComboSelected;
 var
   strKey : String;
 begin
   strKey := Combo1.GetItemIndex(Combo1.ItemIndex);
  if Combo1.ItemIndex <> '0' then
  begin
   TClProButton(MyForm.clFindComponent(strKey)).Caption := strKey+'+';
   TClProButton(MyForm.clFindComponent(strKey)).Enabled := false;
  end;
 end;
 begin
   MyForm :=TclForm.Create(self);
   
   Combo1 := MyForm.AddNewComboBox(MyForm,'Combo1');
   Combo1.Align := alMostTop;
   Combo1.Height := 20;
   Combo1.Margins.Top:=10;
   Combo1.Margins.Left :=MyForm.clWidth/9;
   Combo1.Margins.Right :=MyForm.clWidth/9;
   
   Combo1.AddItem('Please select the button to be marked.','0');
   for j := 1 to 5 do
     Combo1.AddItem('testBtn'+IntToStr(j),IntToStr(j));
   MyForm.AddNewEvent(Combo1,tbeOnChange,'ComboSelected');
   
   
   mainPnl:=MyForm.AddNewProPanel(MyForm,'mainPnl');
   clComponent.SetupComponent(mainPnl,'{"Align" : "Center","Width" :200, 
   "Height":300,"RoundHeight":10,"RoundWidth":10,"BorderColor":"#3a32a8","BorderWidth":2}');
   
   for i := 0 to 4 do
   begin
     testBtn := MyForm.AddNewProButton(mainPnl,'testBtn'+IntToStr(i+1),'');
     clComponent.SetupComponent(testBtn,'{"caption":"testBtn'+IntToStr(i+1)+'","Align" : "Top","MarginTop":5,"MarginLeft":5,"MarginRight":5,
     "Height":50}');
     MyForm.SetImage(testBtn,'https://clomosy.com/demos/foodInformationBox.png'); 
   end;
   
   MyForm.Run;
 end;

Output:
ClFindComponentExampleV1.0.png

See Also