[Lazarus] TFrame improvements

Juha Manninen juha.manninen62 at gmail.com
Tue Nov 30 11:18:02 CET 2021

On Mon, Nov 29, 2021 at 11:14 PM Ondrej Pokorny via lazarus <
lazarus at lists.lazarus-ide.org> wrote:

> That is nonsense. I reverted your change. The code user code is just plain
> wrong and your change in TFrame doesn't change anything about it.
> Try e.g. :
> procedure TForm1.Button1Click(Sender: TObject);
> var
>   grid: TNewGrid;
> begin
>   grid := TNewGrid.Create(Self);
>   grid.MyProperty := 1; // exception
> end;
> Btw. Delphi behaves the same.
Of course your example code throws an exception because the grid has no
Parent. Assign a Parent after creation and it works.
Your example shows that you don't understand the issue at all! The problem
was not the grid's parent but the Frame's parent. The grid's parent is
requested, it is there, then its parent's parent is requested. The Frame
has no Parent by definition at design time -> exception.

My fix is 100% correct. Calling it nonsense and reverting it was not nice.
Please restore it. You can fix the commit message at the same go. It must
go to 2.2, too. One less bug in the release.

There is one alternative solution. If you are right and the component
behaves wrong, then an exception must be thrown when it is placed on a Form
as well.
Now the behavior is inconsistent and buggy.
I personally don't see why component authors should be punished with such
an exception. If the component does not work, it will be evident by other

> 2) Is it a bug in first? (and therefore is a fix needed): No.
> No (at least if it is at runtime) it is not a bug, because it is by
design that a frame needs a form as parent.

Why you play dummy now? You know the problem happens at design time, not
The exception happened only because the code required a Frame to have a
Parent which BY DEFINITION it does not have at design time under the
default designer.
The correct fix is to NOT require a Frame to have a Parent, which I did in
my commit.

> 3) Before the patch, ignoring the design time issues => did it work at
runtime? (And is it indented to?)

Yes, at runtime it works on both a Form and a Frame.
At design time it works on a Form but crashes on a Frame which is clearly a
bug. Agree?

I wrote about a hypothetical situation where a Frame stands alone at
runtime. It obviously does not happen with the current TFrame. I meant that
my fix is logically correct also if somebody derives a *SuperFrame* for
whatever reason for extra capabilities. The frame's params would still be
right then.

Yes, the error message is confusing.
 "*NewGrid1.MyProperty: Control '' has no parent window*" while it actually
came recursively from the Frame.Parent.
Maybe it confused Ondrej's head. It confused mine initially, and Flávio
Etrusco's (see his comment).
Now that I understand the issue, my fix clearly was the right one.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20211130/bf087052/attachment-0001.html>

More information about the lazarus mailing list