Forum > LCL

Creating "TEdit" component dynamically

<< < (5/5)

alpine:

--- Quote from: lucamar on May 06, 2021, 06:54:46 pm ---*snip*
Yes, if the object hasn't been created normally then it's called with an invalid Self. It's not forbidden because there might be legitimate reasons to call it through an instance as a normal method (e.g. to "reset" the object to its default state).
*snip*

--- End quote ---

After reading few articles now I see it clearly! We use it all the time in the constructors (inherited Create;).

Makes me think that the usual heap allocation can be skipped (e.g. for tiny embedded) and have a 'static' instances, something like:


--- 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";}};} ---var  Buf: array [0..MaxBuf-1] of Byte;  Mark: Integer;  O1, O2: TMyObject;begin   Mark := 0;   O1 := TMyObject(@Buf[Mark]); Mark := Mark + TMyObject.InstanceSize;   O1.Create;   O2 := TMyObject(@Buf[Mark]); Mark := Mark + TMyObject.InstanceSize;   O2.Create;   // etc.   MainProc;end. 
Of course that kind of objects should never be Free'd.

BTW, using obj.Create for resetting is considered a very dangerous practice.

lucamar:

--- Quote from: y.ivanov on May 06, 2021, 07:53:44 pm ---BTW, using obj.Create for resetting is considered a very dangerous practice.
--- End quote ---

Thence my previous advice :D

alpine:

--- Quote from: lucamar on May 06, 2021, 08:00:04 pm ---Thence my previous advice :D

--- End quote ---
Absolutely right! Sorry, little dizzy of my (personal) findings.

BTW, Is there a way to know InstanceSize at compile time? Something like SizeOf()? 

lucamar:

--- Quote from: y.ivanov on May 06, 2021, 08:08:14 pm ---BTW, Is there a way to know InstanceSize at compile time? Something like SizeOf()?
--- End quote ---

Not that I know of, sorry.

If I may ask, why do you want it? For most classes InstanceSize is only a "lower estimation".

alpine:

--- Quote from: lucamar on May 06, 2021, 09:13:44 pm ---
Not that I know of, sorry.

If I may ask, why do you want it? For most classes InstanceSize is only a "lower estimation".

--- End quote ---

For specifying the upper bound of the pre-allocated buffer in
https://forum.lazarus.freepascal.org/index.php/topic,54470.msg404786.html#msg404786

Navigation

[0] Message Index

[*] Previous page

Go to full version