Forum > LCL
[SOLVED] Component name
Pe3s:
Hello, how can I pass a component name as a variable or constructor?
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure(componentName :)
AlexTP:
Youtube has videos for 'Pascal tutorial' search; you need them.
RayoGlauco:
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.
GetMem:
Most likely OP wants to pass a component to another class. Use the constructor, like this:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---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:
--- Quote from: RayoGlauco on January 14, 2022, 01:33:54 pm ---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.
--- End quote ---
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.
Navigation
[0] Message Index
[#] Next page