Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2002-12

Duplicate condition in HandleNeeded

4 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Martin Smat

Hi,
in procedure TWinControl.HandleNeeded is this part of code: ...
if not HandleAllocated then

  begin
    if Parent = Self
    then begin
      Assert( ... );
    end
    else begin
      if (Parent  nil) then
        Parent.HandleNeeded;
    end;
    if not HandleAllocated then  //********
      CreateHandle;
  end;

...
Is the condition marked with asterisks really needed? IMO it si useless because the same condition is 10 lines above and here it returns always true. Can it be deleted or did I anything overlook?

Reply by email

Mattias Gaertner
to Martin Smat
Show quoted text 12 lines
Hi, in procedure TWinControl.HandleNeeded is this part of code: ... if not HandleAllocated then begin if Parent = Self then begin Assert( ... ); end else begin if (Parent nil) then Parent.HandleNeeded;

^^^^^^^^^^^^^^^^^^^^
This line can create a handle.

end; if not HandleAllocated then //********

This line is needed to end the recursion.

Show quoted text 6 lines
CreateHandle; end; ... Is the condition marked with asterisks really needed? IMO it si useless because the same condition is 10 lines above and here it returns always true. Can it be deleted or did I anything overlook?

yes, no, yes.

Mattias

Reply by email

Mattias Gaertner
to Martin Smat: in procedure TWinControl.HandleNeeded is this part of code: ... if not HandleAllocated…
Show quoted text 17 lines
Let me explain why I asked. I have added Else part with some testing code. It looks like this: if not HandleAllocated then begin ... if not HandleAllocated then CreateHandle else begin // TESTING CODE HERE assignfile(f,'debug.txt'); // f is declared as textfile rewrite(f); writeln(f,'Handle is allocated'); closefile(f); end; end; Then I compiled and ran Lazarus but the file debug.txt was never created. So hence I think the second condition �If not HandleAllocated� is useless (always true).

Most handles are created, because the form starts creating them. When a new form has not yet created its handle and one of its components needs its handle, the above case will happen.

Show quoted text 15 lines
But if the handle can be really created in the recursion then leave this line as it is (I'm not LCL wizard). Don't blame me I'm so punctilious, I know that the cleanups aren't priority nowadays and I don't want raise a quarrel about one line of code but I have another simple question. In constructor TcustomForm.CreateNew is following code: ... BeginFormUpdate; FBorderStyle:= bsSizeable; inherited Create(AOwner); ... // 15 lines here FBorderStyle := bsSizeable; ... Why is there �FborderStyle := bsSizeable� twotimes? Has it any hidden mysterious sense which I can't see?

Lack of time. ;)
I deleted the second one.

Mattias

Reply by email

Martin Smat
to Martin Smat: in procedure TWinControl.HandleNeeded is this part of code: ... if not HandleAllocated…
Mattias Gaertner wrote 50 lines
On Sun, 01 Dec 2002 15:50:08 +0100 Martin Smat wrote: >Hi, >in procedure TWinControl.HandleNeeded is this part of code: >... >if not HandleAllocated then > begin > if Parent = Self > then begin > Assert( ... ); > end > else begin > if (Parent nil) then > Parent.HandleNeeded; > > ^^^^^^^^^^^^^^^^^^^^ This line can create a handle. > end; > if not HandleAllocated then //******** > > This line is needed to end the recursion. > CreateHandle; > end; >... >Is the condition marked with asterisks really needed? IMO it si useless >because the same condition is 10 lines above and here it returns always >true. Can it be deleted or did I anything overlook? > > yes, no, yes. Mattias

Let me explain why I asked. I have added Else part with some testing code. It looks like this:
if not HandleAllocated then
begin
...
if not HandleAllocated then
CreateHandle
else begin // TESTING CODE HERE
assignfile(f,'debug.txt'); // f is declared as textfile rewrite(f);
writeln(f,'Handle is allocated');
closefile(f);
end;
end;
Then I compiled and ran Lazarus but the file debug.txt was never created. So hence I think the second condition �If not HandleAllocated� is useless (always true). But if the handle can be really created in the recursion then leave this line as it is (I'm not LCL wizard). Don't blame me I'm so punctilious, I know that the cleanups aren't priority nowadays and I don't want raise a quarrel about one line of code but I have another simple question.
In constructor TcustomForm.CreateNew is following code: ...
BeginFormUpdate;
FBorderStyle:= bsSizeable;
inherited Create(AOwner);
... // 15 lines here
FBorderStyle := bsSizeable;
...
Why is there �FborderStyle := bsSizeable� twotimes? Has it any hidden mysterious sense which I can't see?

Martin Smat.

Reply by email