如果我編譯下面的代碼它給第1行的警告「未初始化變量」:分配給LTIME「價值從來沒有使用過」變爲
值從未使用*
但如果我刪除了這一行,我坐上2號線不同的警告:
變量LTIME可能尚未初始化
編譯器是否丟失了一些東西,或者我?
procedure TFormWebServices.RemoveOldReports;
var
TSR : TSearchRec;
I : Integer;
lCutOff,
lTime : Int64;
TSToDelete: TStringList;
S,Msg : String;
E : Exception;
begin
lCutOff := DelphiToJavaDateTime(Now - cDefReportLifeMins/1440);
I := FindFirst(FReportDir + '*.pdf',0,TSR);
TSToDelete := TStringList.Create;
while I = 0 do
begin
if (TSR.Attr and faDirectory) = 0 then
begin
lTime := lCutOff; // Line 1
try
lTime := StrToInt64(Copy(TSR.Name,1,pos('.',TSR.Name)-1));
except
on E:Exception do lTime := lCutOff;
end;
if lTime < lCutOff then // Line 2
TSToDelete.Add(TSR.Name);
end;
I := FindNext(TSR);
end;
這不是一個Why is the Compiler warning that variable may not be initialized?傻瓜,因爲我在異常分配lTime
爲好。
的可能的複製(HTTP://計算器。 com/questions/11554857/why-the-compiler-warning-that-variable-may-not-initialized) –
它看起來確實是重複的。 –
但是,真的,這裏不需要使用異常處理。 RTL爲此提供了一套'TryStrTo [x]'方法 - 比讓異常處理程序處理它更有效。 [TryStrToInt64文檔](http://docwiki.embarcadero.com/Libraries/en/System.SysUtils.TryStrToInt64) –