Bug in fuction ParseDate in EditBtn.pas lazarus / 31-LCL ---------------------------------------------------------------------- kolevs · 2020-08-13 07:57 Hi, While looking at the code in EditBtn.pas, I noticed some strange statement(may be bug): Function ParseDate(S : String; Order : TDateOrder; Def: TDateTime) : TDateTime; Var   P,N1,N2,N3 : Integer;   B : Boolean; begin   Result:=Def;   P:=Pos(DefaultFormatSettings.DateSeparator,S);   If (P=0) then     Exit;   N1:=StrToIntDef(Copy(S,1,P-1),-1);   If (N1=-1) then Exit;   Delete(S,1,P);   P:=Pos(DefaultFormatSettings.DateSeparator,S);   If (P=0) then     Exit;   N2:=StrToIntDef(Copy(S,1,P-1),-1);   If (N1=0) then Exit;   Delete(S,1,P);   N3:=StrToIntDef(S,-1);   If (N3=-1) then     exit;   Case Order of     doYMD : B:=TryEncodeDate(N1,N2,N3,Result);     doMDY : B:=TryEncodeDate(N3,N1,N2,Result);     doDMY : B:=TryEncodeDate(N3,N2,N1,Result);     else B:=false;   end;   If not B then // Not sure if TryEncodeDate touches Result.     Result:=Def; end; This:   N2:=StrToIntDef(Copy(S,1,P-1),-1);   If (N1=0) then Exit; shouldn't it be:   If(N2=-1) then Exit; Regards ---------------------------------------------------------------------- wp · 2020-08-13 08:23 Yes, looks wrong. But I think it is not relevant because the edit mask of TDateEdit is designed such that only numeric characters can be entered, and thus the center part of the date string will always be a valid number, i.e. StrToIntdef will never return the default value. Even without the edit mask (when the code snipped is copied to another file) the parsing result is still correct because the invalid center part makes the final TryStrToDate fail. Nevertheless, for the sake of code clarity, I fixed it in r63728. ---------------------------------------------------------------------- kolevs · 2020-08-14 08:26 Thanks, you are very fast  Sorry for the inconvenience, but I found another not very logical part in same file. function ParseDateNoPredefinedOrder internal procedure Split     for i :=  1 to Length(Fmt) do       if not (Fmt in Digits) then Sep := Sep + [Fmt]; Isn't that supposed Fmt to be 'dd.mm.yy' or something like this, but not Digits. May be SDate should be used? Regards