My reason for using a form's name inside its own code was to try to aid clarity. I accept that TitleBox.Parent := self; is correct, but what does it mean? Is it equivalent to TitleBox.Parent:= TitleBox rather than TitleBox.Parent:= SS (which is what I had written)? If the former is the case then, once again, I don't follow the logic. Possibly the statement isn't needed at all: I added it after things started to go wrong in case things weren't clear to the compiler.
When you use
Self you refer to the actual object instance, whatever its name (as a variable) instead of to a specific instance SS which might or might not be the current one.
In this specific example
TitleBox.Parent := Self; is equivalent to your
TitleBox.Parent:= SS but, what if you needed somewhere else a duplicate form declared as, say,
TempSS: TSS? When the OnCreate handler were called it would add a TitleBox to
SS again, instead of to the new
TempSS; using
Self as
Parent prevents this and makes TitleBox a "child" of the current object being created, in this case the correct
TempSS instance.
Since most forms are meant as single-instance objects it's easy to forget that when builiding a form in Lazarus what one is really doing is programming a
class, not a specific
object instance. One should always try to remember this (at less until it becomes automatic
)
HTH!