Forum > LCL

Creating "TEdit" component dynamically

<< < (2/5) > >>

pascal111:
By the way, is there a problem if I said:


--- 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";}};} --- e1.create(self); // rather than     e1:=tedit.Create(self);  

alpine:

--- Quote from: pascal111 on May 05, 2021, 02:24:33 pm ---By the way, is there a problem if I said:


--- 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";}};} ---e1.create(self); // rather than     e1:=tedit.Create(self); 
--- End quote ---
It is not the same. The constructor is part of the class(TEdit), not the instance (e1). e1 is just a pointer internally.

lucamar:

--- Quote from: pascal111 on May 05, 2021, 02:24:33 pm ---By the way, is there a problem if I said:

--- 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";}};} ---e1.create(self); // rather than     e1:=tedit.Create(self);
--- End quote ---

When you do that what you're doing is basically just calling a method of the instance, rather than invoking the constructor of the class. Two very different concepts.

pascal111:
I see now. I think the different between the two concepts can be used in advanced uses of components.

lucamar:
Beyond the instance creation "magic", the constructor is sometimes used to initialize some fields, set some default properties, etc. If you're going to call it as a method to "reset" it to the default state it's usually better to include all those initializations to their own method (SetDefaults() or whatever) and call that instead.

That way it's less confusing and there is no doubt about whether you're constructing the object or just "resetting" it.

IMHO, of course :-\

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version