[Lazarus] TFrame improvements
Martin Frb
lazarus at mfriebe.de
Tue Nov 30 09:31:16 CET 2021
On 30/11/2021 00:27, Juha Manninen via lazarus wrote:
> On Mon, Nov 29, 2021 at 11:14 PM Ondrej Pokorny via lazarus
> <lazarus at lists.lazarus-ide.org> wrote:
>
> On 29.11.2021 17:18, Juha Manninen via lazarus wrote:
>> The commit message is not perfect but the committed code is, now
>> that I fully understand the issue.
>
> 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.
>
> No, the code is valid although not recommended. Accessing Canvas
> outside Paint works with some widgetsets and then an exception is wrong.
>
There are 2 (or 3) question.
1) Is the fix correct: Yes (if 2 or 3), otherwise "not applicable"
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.
3) Before the patch, ignoring the design time issues => did it work at
runtime? (And is it indented to?)
When (without the patch) the stream is read at runtime, and the frame is
embedded in a Form, does the example code then work?
Basically, will at runtime the parent be set, before any properties are
loaded?
(Or, Is that documented that it should?)
=> *If* this works at runtime (and if this is by intention), then there
is a bug in the designer, in that the designer fails to set the parent
(parent = designer) in time.
I have not tested the example from the bug. But I did a quick debug of a
TFrame being loaded, at runtime:
- The TFrame is loading twice from lfm (the frames own lfm, and the
changeds stored in the form)
-- the first loading, there is no parent set => so it would/could fail.
-- the 2nd loading, there is a parent
The exact "expected" (not tested) behaviour for the app from the bug
would be:
- If the offending property has a default, and is not changed from the
default => all good, property is not set during TReader
- If the default is changed in the Frame's lfm => crash, because the
property is set, when there is no parent.
- if the default is only changed for the frame's instance on the form
(stored in the form's lfm) => ok
So IMHO it is save to say, that this is not supported at runtime either.
Should it be? IMHO not, see below.
-----------------------
This leaves improving the designer, to add a better error message, and
handle it more gracefully.
-----------------------
Otherwise Ondrej is right that code accessing the handle (and that
includes canvas) must do checks.
And TFrame is not the only place were it this is needed.
b := TPanel.Create(Form1);
a := TGraphicControl.Create(b);
//a.Parent := b;
//b.Parent := Form1;
a.Canvas.Line(1,1,2,2);
You must set both parents, or it crashes.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20211130/17c809f9/attachment.html>
More information about the lazarus
mailing list