[SOLVED] Component name lazarus / 31-LCL ---------------------------------------------------------------------- Pe3s · 2022-01-14 12:05 Hello, how can I pass a component name as a variable or constructor? 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 procedure(componentName :) ---------------------------------------------------------------------- AlexTP · 2022-01-14 12:18 Youtube has videos for 'Pascal tutorial' search; you need them. ---------------------------------------------------------------------- RayoGlauco · 2022-01-14 12:33 Pe3s, are you talking about passing a string (a component name) as a constructor (a procedure)? This is nosense. Yo need to explain this better. ---------------------------------------------------------------------- balazsszekely · 2022-01-14 12:40 Most likely OP wants to pass a component to another class. Use the constructor, like 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 type  TMyClass = class  private    FForm: TForm;  public    constructor Create(AForm: TForm);  end; //.. constructor TMyClass.Create(AForm: TForm);begin    FForm := AForm;  //use FForm, you don't have to free it on destructorend; ---------------------------------------------------------------------- Thaddy · 2022-01-14 12:45 Quote from: RayoGlauco on January 14, 2022, 01:33:54 pmPe3s, are you talking about passing a string (a component name) as a constructor (a procedure)? This is nosense. Yo need to explain this better. Well, the constructor can be done to some extend, but OP should mind that FPC is not a scripting language. It is unusual to use such constructs. The technique to use is to use {$if declared(variableName)} in combination with RTTI to get a class reference from which you can create an instance. Highly NOT recommended, but that would work, I guess. ---------------------------------------------------------------------- howardpc · 2022-01-14 13:45 Quote from: Thaddy on January 14, 2022, 01:45:03 pmWell, the constructor can be done to some extend, but OP should mind that FPC is not a scripting language. It is unusual to use such constructs. The technique to use is to use {$if declared(variableName)} in combination with RTTI to get a class reference from which you can create an instance. Highly NOT recommended, but that would work, I guess. "the technique to use ... highly NOT recommended" seems like a self- contradiction. RTTI is currently only available via FPC for published properties of classes and a few other limited cases. What is so unusual about passing data as parameter(s) in a constructor? You make it sound as if such a technique were unsound or hackish. It is a perfectly acceptable way to pass data that you don't want exposed globally. ---------------------------------------------------------------------- Pe3s · 2022-01-14 16:38 Thank you. greetings ---------------------------------------------------------------------- PascalDragon · 2022-01-14 19:44 Quote from: howardpc on January 14, 2022, 02:45:54 pmQuote from: Thaddy on January 14, 2022, 01:45:03 pmWell, the constructor can be done to some extend, but OP should mind that FPC is not a scripting language. It is unusual to use such constructs. The technique to use is to use {$if declared(variableName)} in combination with RTTI to get a class reference from which you can create an instance. Highly NOT recommended, but that would work, I guess. "the technique to use ... highly NOT recommended" seems like a self- contradiction. RTTI is currently only available via FPC for published properties of classes and a few other limited cases. What is so unusual about passing data as parameter(s) in a constructor? You make it sound as if such a technique were unsound or hackish. It is a perfectly acceptable way to pass data that you don't want exposed globally. I think the “highly NOT recommended” is related to Thaddy's idea of using {$if declared(variableName)}. The idea of using RTTI would of course be alright if the extended RTTI would already be integrated. ---------------------------------------------------------------------- Akira1364 · 2022-01-14 21:50 Can you give an example of what you're actually trying to do?