From Clomosy Docs

No edit summary
No edit summary
 
(8 intermediate revisions by one other user not shown)
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): TCLComponent;
</div>


MyForm.clFindComponent(xObjectName : String)
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>


:'''Base Syntax'''
<pre>
Var 
  MyForm:TclForm;
  mainPnl : TclProPanel;
  testBtn : TClProButton;
  i,j : Integer;
  Combo1 : TClComboBox;


   Var 
void ComboSelected;
  MyForm:TclForm;
var
  mainPnl : TclProPanel;
   strKey : String;
  testBtn : TClProButton;
{
  i : Integer;
  strKey = Combo1.GetItemIndex(Combo1.ItemIndex);
  objectName:string;
  if (Combo1.ItemIndex <> '0')
  {
  TClProButton(MyForm.clFindComponent(strKey)).Caption = strKey+'+';
  TClProButton(MyForm.clFindComponent(strKey)).Enabled = false;
  }
}
{
  MyForm =TclForm.Create(self);
    
    
  procedure GetName;
  Combo1 = MyForm.AddNewComboBox(MyForm,'Combo1');
  var
  Combo1.Align = alMostTop;
    clickedBtn:TClProButton;
  Combo1.Height = 20;
  begin
  Combo1.Margins.Top=10;
    clickedBtn := TClProButton(Myform.Clsender);
  Combo1.Margins.Left =MyForm.clWidth/9;
    TClProButton(MyForm.clFindComponent(clickedBtn.Caption)).Caption := clickedBtn.Caption+'+';
  Combo1.Margins.Right =MyForm.clWidth/9;
    clickedBtn.Enabled := false;
  end;
    
    
   begin
   Combo1.AddItem('Please select the button to be marked.','0');
  MyForm:=TclForm.Create(self);
  for (j = 1 to 5)
  mainPnl:=MyForm.AddNewProPanel(MyForm,'mainPnl');
    Combo1.AddItem('testBtn'+IntToStr(j),IntToStr(j));
  clComponent.SetupComponent(mainPnl,'{"Align" : "Center","Width" :200,
  MyForm.AddNewEvent(Combo1,tbeOnChange,'ComboSelected');
  "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');
   
    MyForm.AddNewEvent(testBtn,tbeOnClick,'GetName');
  end;
 
  MyForm.Run;
  end;
:'''TRObject Syntax:'''
  Var 
  MyForm:TclForm;
  mainPnl : TclProPanel;
  testBtn : TClProButton;
  i : Integer;
  objectName:string;
    
    
  void GetName;
  mainPnl=MyForm.AddNewProPanel(MyForm,'mainPnl');
  var
  mainPnl.Align = AlCenter;
    clickedBtn:TClProButton;
  mainPnl.Width = 200;
  {
  mainPnl.Height = 300;
    clickedBtn = TClProButton(Myform.Clsender);
  mainPnl.clProSettings.IsRound = True;
    TClProButton(MyForm.clFindComponent(clickedBtn.Caption)).Caption = clickedBtn.Caption+'+';
  mainPnl.clProSettings.RoundHeight = 10;
    clickedBtn.Enabled = false;
  mainPnl.clProSettings.RoundWidth = 10;
  }
  mainPnl.clProSettings.BorderColor = clAlphaColor.clHexToColor('#3a32a8');
  mainPnl.clProSettings.BorderWidth = 2;
  mainPnl.SetclProSettings(mainPnl.clProSettings);
    
    
  for (i = 0 to 4)
   {
   {
  MyForm=TclForm.Create(self);
    testBtn = MyForm.AddNewProButton(mainPnl,'testBtn'+IntToStr(i+1),'');
  mainPnl=MyForm.AddNewProPanel(MyForm,'mainPnl');
    testBtn.Align = AlTop;
  clComponent.SetupComponent(mainPnl,'{"Align" : "Center","Width" :200,
    testBtn.caption = 'testBtn'+IntToStr(i+1);
   "Height":300,"RoundHeight":10,"RoundWidth":10,"BorderColor":"#3a32a8","BorderWidth":2}');
    testBtn.Margins.Right = 5;
    testBtn.Margins.Left = 5;
    testBtn.Margins.Top = 5;
    testBtn.Height = 50;
    MyForm.SetImage(testBtn,'https://clomosy.com/demos/foodInformationBox.png');
   }
    
    
  for (i = 0 to 4)
  MyForm.Run;
  {
}
  testBtn = MyForm.AddNewProButton(mainPnl,'testBtn'+IntToStr(i+1),<nowiki>''</nowiki>);
</pre>
  clComponent.SetupComponent(testBtn,'{"caption":"testBtn'+IntToStr(i+1)+'","Align" : "Top","MarginTop":5,"MarginLeft":5,"MarginRight":5,
 
  "Height":50}');
<b>Output:</b><br>
  MyForm.SetImage(testBtn,'https://clomosy.com/demos/foodInformationBox.png');
[[File:ClFindComponentExampleV1.0.png|frameless|400px]]<br>
   
    MyForm.AddNewEvent(testBtn,tbeOnClick,'GetName');
  }
 
  MyForm.Run;
  }


= See Also=
<h2> See Also </h2>
* [[Controls| Controls]]
* [[System_Library#Cl_Utilities_Functions | Cl Utilities Functions]]
{{#seo:|description=Learn how clFindComponent locates subcomponents by name in Clomosy, enabling property modifications like changing button text.}}

Latest revision as of 07:46, 24 December 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.

Var  
  MyForm:TclForm;
  mainPnl : TclProPanel;
  testBtn : TClProButton;
  i,j : Integer;
  Combo1 : TClComboBox;

void ComboSelected;
var
  strKey : String;
{
  strKey = Combo1.GetItemIndex(Combo1.ItemIndex);
  if (Combo1.ItemIndex <> '0')
  {
  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');
  mainPnl.Align = AlCenter;
  mainPnl.Width = 200;
  mainPnl.Height = 300;
  mainPnl.clProSettings.IsRound = True;
  mainPnl.clProSettings.RoundHeight = 10;
  mainPnl.clProSettings.RoundWidth = 10;
  mainPnl.clProSettings.BorderColor = clAlphaColor.clHexToColor('#3a32a8');
  mainPnl.clProSettings.BorderWidth = 2;
  mainPnl.SetclProSettings(mainPnl.clProSettings);
  
  for (i = 0 to 4)
  {
    testBtn = MyForm.AddNewProButton(mainPnl,'testBtn'+IntToStr(i+1),'');
    testBtn.Align = AlTop;
    testBtn.caption = 'testBtn'+IntToStr(i+1);
    testBtn.Margins.Right = 5;
    testBtn.Margins.Left = 5;
    testBtn.Margins.Top = 5;
    testBtn.Height = 50;
    MyForm.SetImage(testBtn,'https://clomosy.com/demos/foodInformationBox.png'); 
  }
  
  MyForm.Run;
}

Output:
ClFindComponentExampleV1.0.png

See Also