lcl/widgetset/wslclclasses.pp has a series of useless "Result := nil;" lines in:
function FindClassNode(const AComponent: TComponentClass): PClassNode;
var
idx: integer;
begin
Result := nil;
if WSClassesList.Search(AComponent, idx) then
Exit(WSClassesList[idx]);
Result := FindNodeParent(AComponent.ClassParent);
end;
No matter what, the nil value will be overwritten later.
function FindParentWSClassNode(const ANode: PClassNode): PClassNode;
begin
Result := ANode^.Parent;
while Result <> nil do begin
if Result^.WSClass <> nil then Exit;
Result := Result^.Parent;
end;
Result := nil;
end;
There are two ways of leaving the "while Result <> nil do" loop:
- exiting with an assigned result at "if Result^.WSClass <> nil then Exit;" in which case the line "Result := nil;" won't be run;
- exiting when Result is nil, situation when the line "Result := nil;" is useless.
function FindCommonAncestor(const AClass1, AClass2: TClass): TClass;
begin
Result := AClass1;
if AClass2.InheritsFrom(Result) then Exit;
Result := AClass2;
while Result <> nil do begin
if AClass1.InheritsFrom(Result) then Exit;
Result := Result.ClassParent;
end;
Result := nil;
end;
Similar to function FindParentWSClassNode(const ANode: PClassNode): PClassNode;
There are two ways of leaving the "while Result <> nil do" loop:
- exiting with an assigned result at "if AClass1.InheritsFrom(Result) then Exit;" in which case the line "Result := nil;" won't be run;
- exiting when Result is nil, situation when the line "Result := nil;" is useless.
Edit: Removed the patch because it become obsolete.