+4
Under review

[W504] False positive with classes with multiple constructors where one calls the other

Uwe Schuster 10 years ago updated by dummzeuch 9 years ago 6
A constructor that calls another constructor in the same class leads to false positive W504.

type
TFoo = class(TObject)
public
constructor Create;
end;

TBar = class(TFoo)
public
constructor Create;
constructor CreateEx;
end;

//<- http://fixinsight.userecho.com/topic/701447-w504-false-positive-with-objects-inherited-from-tobject/
constructor TFoo.Create;
begin

end;

constructor TBar.Create;
begin
inherited Create;
end;

constructor TBar.CreateEx;//<- False positive W504
begin
Create;
end;

Not fixed:

constructor TLutHandlerArgus2Single.Create(_SensorInfo: TSensorInfo;

_DoConvert: TLutHandlerArgus2SingleDoConvert;
_DoConvertInv: TLutHandlerArgus2SingleDoConvertInv;
_GetMinDigits: TLutHandlerArgus2SingleGetMinDigits;
_GetMaxDigits: TLutHandlerArgus2SingleGetMinDigits);
begin
inherited Create('', 0); // << call to inherited Create

FDoConvert := _DoConvert;
FDoConvertInv := _DoConvertInv;
FGetMinDigits := _GetMinDigits;
FGetMaxDigits := _GetMaxDigits;
FSensorInfo := _SensorInfo;
end;

constructor TLutHandlerArgus2Single.Create(_Filename: string; _DoConvert: TLutHandlerArgus2SingleDoConvert;
_DoConvertInv: TLutHandlerArgus2SingleDoConvertInv;
_GetMinDigits: TLutHandlerArgus2SingleGetMinDigits;
_GetMaxDigits: TLutHandlerArgus2SingleGetMinDigits);
var
fm: TdzFile;
SensorInfo: TSensorInfo;
begin
fm := TdzFile.Create(_Filename);
try
fm.OpenReadonly;
if fm.Read(SensorInfo, SizeOf(SensorInfo)) <> SizeOf(SensorInfo) then
raise Exception.CreateFmt(_('Error while reading SensorInfo from file "%s"'), [_Filename]);
Create(SensorInfo, _DoConvert, _DoConvertInv, _GetMinDigits, _GetMaxDigits); // << call to overloaded create
finally
FreeAndNil(fm);
end;
end;


Still not fixed:


constructor Tdm_DbasePrivateSession.Create(_Owner: TComponent; const _DatabaseDir: string);

begin

inherited Create(_Owner);

FDatabaseDir := _DatabaseDir;

TFileSystem.ForceDir(FDatabaseDir);

end;


constructor Tdm_DbasePrivateSession.Create(const _DatabaseDir: string);
begin
Create(nil, _DatabaseDir);
end;


constructor Tdm_DbasePrivateSession.CreateForTable(_Owner: TComponent; const _Tablename: string);
begin
Create(_Owner, ExtractFilePath(_Tablename));
end;


constructor Tdm_DbasePrivateSession.CreateForTable(const _Tablename: string); // <--- false positive W525 here
begin
CreateForTable(nil, _Tablename);
end;