Sign in Join

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

Mailing lists / lazarus / 2018-01

Redundant assigned(X) and (X is Txxx) in Laz. sources

5 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

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

Juha Manninen
to Vojtěch Čihák
Vojtěch Čihák wrote 6 lines
I wrote a small routine to search Lazarus sources and it found about 60 places similar to this (taborderdlg.pas, line 398): if Assigned(LookupRoot) and (LookupRoot is TWinControl) then begin Should I make a patch for all occurences?

Yes, I think the patch would be applied.
IIRC "is" was not allowed with Nil references in old FPC versions but it was a long time ago.

BTW, a regular expression search in the Find in Files dialog would have found those cases, too.

Juha

Reply by email

Mattias Gaertner
to Juha Manninen
Show quoted text 12 lines
On Fri, Jan 12, 2018 at 8:38 PM, Vojtěch Čihák via Lazarus wrote: > I wrote a small routine to search Lazarus sources and it found about 60 > places similar to this (taborderdlg.pas, line 398): > > if Assigned(LookupRoot) and (LookupRoot is TWinControl) then begin > > Should I make a patch for all occurences? Yes, I think the patch would be applied. IIRC "is" was not allowed with Nil references in old FPC versions but it was a long time ago.

No, "is" was always checking for nil.
Maybe some people are confused by "as", which does not check for nil.

Mattias

Reply by email

Dennis
to Mattias Gaertner
Mattias Gaertner wrote 18 lines
On Fri, 12 Jan 2018 21:44:47 +0200 Juha Manninen via Lazarus wrote: > On Fri, Jan 12, 2018 at 8:38 PM, Vojtěch Čihák via Lazarus > wrote: >> I wrote a small routine to search Lazarus sources and it found about 60 >> places similar to this (taborderdlg.pas, line 398): >> >> if Assigned(LookupRoot) and (LookupRoot is TWinControl) then begin >> >> Should I make a patch for all occurences? > Yes, I think the patch would be applied. > IIRC "is" was not allowed with Nil references in old FPC versions but > it was a long time ago. No, "is" was always checking for nil. Maybe some people are confused by "as", which does not check for nil. Mattias

I am now confused, so
in FPC, it is safe to just use: if LookupRoot is TWinControl instead of
if assigned(LookupRoot) and (LookupRoot is TWinControl) then ....

is it safe to
    with LookupRoot as TWinControl do begin
        ....
    end;
or should I always
    if assigned(LookupRoot) then
      with LookupRoot as TWinControl do begin
          ....
      end;

Dennis

Reply by email

Mattias Gaertner
to Dennis
Show quoted text 5 lines
[...] I am now confused, so in FPC, it is safe to just use: if LookupRoot is TWinControl instead of if assigned(LookupRoot) and (LookupRoot is TWinControl) then ....

Yes.

is it safe to with LookupRoot as TWinControl do begin .... end;

No.

Show quoted text 5 lines
or should I always if assigned(LookupRoot) then with LookupRoot as TWinControl do begin .... end;

Yes.

Mattias

Reply by email