Here comes an error, which cannot exist. And it hides away for many days and then to re-occurs again.
And to my mind, the favorite ghosting day is Saturday.
In case you do not believe me such a story, - I attach a screenshot.
But let us start by what I wanna do, a really simple thing:
There is a date I have as string in the format MM/DD/YYYY.
It shall be converted into a Delphi-Type date.
In about one out of six or ten the date is thought by Lazarus to be zero.
If I repeat the task long enough, - the conversion works again.
The error message looks "impressive" in the sense of "what..."?
It is translated to English (gueltig = valid) and you find it below in the line "if not gueltig then show Message"
There is an invalid date: 27.01.2023
This is the source, where the thing stands in.
And probably there is anything, I can change, but whatever I tried there, - the ghost was not banned.
function TZeit.KorrigiereAmiDatum(s: string): TDate; // 12/31/2017 => 31.12.2017 in TDate
Var gueltig: Boolean;
dat: TDateTime;
j: integer;
s1, s2: string;
begin
result:=0;
// s:=AnsiReplaceStr(s,'/','.');
j:=Pos('/',s);
s1:=copy(s,0,j - 1 ); // kopiert das Monat = Ziffern vor dem 1. Strich, z.B. '6'
s1:=trim(s1);
If Length(s1) = 1 then s1:='0' + s1; // macht aus 6 ein 06
s:=copy(s,j+1,Length(s)); // hat jetzt nur mehr Tag und Jahr, wie '31/2017'
j:=Pos('/',s); // sucht den Endschrägstrich vom Ami-Tag
s2:=copy(s, 0 ,j - 1 );
s2:=trim(s2);
If Length(s2) = 1 then s2:='0' + s2; // macht aus 6 ein 06
s:=s2 + '.' + s1 + '.' + RightStr(s,4);
gueltig:=TryStrToDate(s, dat); // Direktaufruf ging nicht, 10.12.2022 das ist völlig unverständlich, das String sieht richtig aus
if not gueltig then // startete Lazarus neu, danach ging es einfach wieder
showMessage('Zeit.KorrigiereUSDatum: Es wurde ein ungültiges Datum übergeben: ' + s)
else result:=trunc(dat);
end;
:'(
Any ideas?