[lazarus] Duplicate condition in HandleNeeded

Martin Smat martin.smat at tiscali.cz
Tue Dec 3 12:22:15 EST 2002


Mattias Gaertner wrote:

>On Sun, 01 Dec 2002 15:50:08 +0100
>Martin Smat <martin.smat at tiscali.cz> 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.






More information about the Lazarus mailing list