Jump to content

Alberto Paganini

Members
  • Content Count

    45
  • Joined

  • Last visited

Community Reputation

3 Neutral

About Alberto Paganini

  • Birthday May 25

Technical Information

  • Delphi-Version
    Delphi XE2

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. Hello, I am trying to update DSharp to the latest release. Before doing that I updated Spring4D successfully. When I tried to update DSharp and build DSharp.Core.DelphiXE2.bpl I had the error message "[DCC Error] DSharp.Collections.Iterators.pas(54): E2170 Cannot override a non-virtual method" Here below is the excerpt of the unit with line 54 TCustomIterator<T> = class(TIterator<T>) private fProc: TIteratorProc<T>; public constructor Create(const proc: TIteratorProc<T>); function Clone: TIterator<T>; override; function MoveNext: Boolean; override; // line 54 end; Any idea of what I am missing out on? Many thanks Alberto
  2. Alberto Paganini

    Delphi SQL Formatter

    Hello, Isn't the download still available ? Is there an alternative link ? Many thanks Alberto
  3. Alberto Paganini

    Unit dependency viwer

    Hello, Isn't there a 32 bit version of the software ?
  4. Alberto Paganini

    Transform string into TDateTime

    One important part of the application I am working on is to retrieve data from a service provider as often as possible. The function JsonStringToDateTime is called tens of thousands of times from several processes in a few minutes in order to parse the data provided therefore, the faster the function the more times the application can retrieve data. This is one of the most "popular" functions but there are others similar and called as much as this one and I will look into these too. I understand this is just a quick fix, the next step would be to refactor the logic of the application in order to retrieve data and parse it in a better way (maybe parse only the necessary data) but that would require more time and I would like to see some results in the short run. However, for the records here the three versions with the usual quick test. program SoapTest; {$APPTYPE CONSOLE} {$R *.res} uses madExcept, madLinkDisAsm, madListHardware, madListProcesses, madListModules, System.SysUtils, Soap.XSBuiltIns; const gOutOfScopelDate: TDateTime = 2 + 365; {*****************************************************************************************} function JsonStringToDateTime(S: widestring): TDateTime; {*****************************************************************************************} begin result := gOutOfScopelDate; with TXSDateTime.Create() do begin try XSToNative(S); result := AsDateTime; finally Free; end; end; end; {*****************************************************************************************} function JsonStringToDateTime2(S: widestring): TDateTime; {*****************************************************************************************} begin try Result := EncodeDate(StrToInt(Copy(S, 1, 4)), StrToInt(Copy(S, 6, 2)), StrToInt(Copy(S, 9, 2))); Result := Result + EncodeTime(StrToInt(Copy(S, 12, 2)), StrToInt(Copy(S, 15, 2)), StrToInt(Copy(S, 18, 2)), 0); except result := gOutOfScopelDate; end; end; {*****************************************************************************************} function JsonStringToDateTime3(Src: widestring): TDateTime; {*****************************************************************************************} function CharToDigit(aChar: Char): Integer; inline; begin Result := Ord(aChar) - Ord('0'); end; var S: string; pSrc, pDest: PChar; begin SetLength(S, 8); pSrc := Pointer(Src); pDest := Pointer(S); try //date pDest^ := pSrc^; (pDest + 1)^ := (pSrc + 1)^; (pDest + 2)^ := (pSrc + 2)^; (pDest + 3)^ := (pSrc + 3)^; (pDest + 4)^ := (pSrc + 5)^; (pDest + 5)^ := (pSrc + 6)^; (pDest + 6)^ := (pSrc + 8)^; (pDest + 7)^ := (pSrc + 9)^; {(*} Result := EncodeDate( // year CharToDigit(S[1]) * 1000 + CharToDigit(S[2]) * 100 + CharToDigit(S[3]) * 10 +CharToDigit(S[4]), CharToDigit(S[5]) * 10 +CharToDigit(S[6]), //month CharToDigit(S[7]) * 10 +CharToDigit(S[8])); //date {*)} //time pDest^ := (pSrc + 11)^; (pDest + 1)^ := (pSrc + 12)^; (pDest + 2)^ := (pSrc + 14)^; (pDest + 3)^ := (pSrc + 15)^; (pDest + 4)^ := (pSrc + 17)^; (pDest + 5)^ := (pSrc + 18)^; {(*} Result:=Result+EncodeTime( CharToDigit(S[1]) * 10 +CharToDigit(S[2]), //hh CharToDigit(S[3]) * 10 +CharToDigit(S[4]), //mm CharToDigit(S[5]) * 10 +CharToDigit(S[6]), //ss 0//ms ); {*)} except result := gOutOfScopelDate; end; end; const aTimes = 5000; var TimeResult: TDateTime; a: TDateTime; b: TDateTime; I: Integer; hh, mm, ss, ms: Word; begin a := Now; for i := 0 to aTimes do begin TimeResult := JsonStringToDateTime('2021-02-11T02:25:00.000Z'); end; b := Now - a; DecodeTime(b, Hh, mm, ss, ms); Writeln('JsonStringToDateTime sec:' + IntToStr(ss) + ' msec:' + IntToStr(ms)); a := Now; for i := 0 to aTimes do begin TimeResult := JsonStringToDateTime2('2023-03-13T02:25:00.000Z'); end; b := Now - a; DecodeTime(b, Hh, mm, ss, ms); Writeln('JsonStringToDateTime2 sec:' + IntToStr(ss) + ' msec:' + IntToStr(ms)); a := Now; for i := 0 to aTimes do begin TimeResult := JsonStringToDateTime3('2023-03-13T02:25:00.000Z'); end; b := Now - a; DecodeTime(b, Hh, mm, ss, ms); Writeln('JsonStringToDateTime3 sec:' + IntToStr(ss) + ' msec:' + IntToStr(ms)); Readln; end. In all honesty, I didn't think that replacing Copy would make a big difference, obviously, I was wrong. I was under the impression that StrToInt could be replaced but I didn't know how to do. The improvement that the changes suggested by @Fr0sT.Brutal make is very big! Thank you. I hope I have understood all the suggestions. Many thanks Alberto
  5. Alberto Paganini

    Transform string into TDateTime

    I was not able to think of anything better in order to transform parts of a string into numbers and then put everything into a TDateTime. Is there an alternative to that, considering that performance is important here?
  6. Alberto Paganini

    Transform string into TDateTime

    @emailx45 That is technically correct, there is no "null date" in Delphi. The software I am working on should receive dates >01/01/1901 only. If something goes wrong the procedure assigns 01/01/1901 to Result. Somewhere else the application checks Result and if it is is 01/01/1901 treats this accordingly. I should have renamed it something like gOutOfScopeDate
  7. Alberto Paganini

    Transform string into TDateTime

    Yes, sorry I forgot to remove it. Any particular reason for that? I am not trying to be funny here. I just want to understand why this is better. Yes, not a problem in my case.
  8. Alberto Paganini

    Transform string into TDateTime

    I would like to replace JsonStringToDateTime with JsonStringToDateTime2 in my code because it is significantly faster. Here below a small example program MyTest; {$APPTYPE CONSOLE} {$R *.res} uses madExcept, madLinkDisAsm, madListHardware, madListProcesses, madListModules, System.SysUtils, Soap.XSBuiltIns; const gNullDate: TDateTime = 2 + 365; {*****************************************************************************************} function JsonStringToDateTime(S: widestring): TDateTime; {*****************************************************************************************} begin result := gNullDate; with TXSDateTime.Create() do begin try XSToNative(S); result := AsDateTime; finally Free; end; end; end; {*****************************************************************************************} function JsonStringToDateTime2(S: widestring): TDateTime; {*****************************************************************************************} var Dummy: string; begin try Result := EncodeDate(StrToInt(Copy(S, 1, 4)), StrToInt(Copy(S, 6, 2)), StrToInt(Copy(S, 9, 2))); Result := EncodeTime(StrToInt(Copy(S, 12, 2)), StrToInt(Copy(S, 15, 2)), StrToInt(Copy(S, 18, 2)), 0); except result := gNullDate; end; end; var TimeResult: TDateTime; a: TDateTime; b: TDateTime; I: Integer; hh, mm, ss, ms: Word; begin a := Now; for i := 0 to 5000 do begin TimeResult := JsonStringToDateTime('2021-02-11T02:25:00.000Z'); end; b := Now - a; DecodeTime(b, Hh, mm, ss, ms); Writeln('JsonStringToDateTime sec:' + IntToStr(ss) + ' msec:+' + IntToStr(ms)); a := Now; for i := 0 to 5000 do begin TimeResult := JsonStringToDateTime2('2021-02-11T02:25:00.000Z'); end; b := Now - a; DecodeTime(b, Hh, mm, ss, ms); Writeln('JsonStringToDateTime2 sec:' + IntToStr(ss) + ' msec:+' + IntToStr(ms)); Readln; end. Can you see any drawbacks in JsonStringToDateTime2 ? Many thanks Alberto
  9. Alberto Paganini

    tlsv1 alert protocol version

    Ok, I have found out the final issues. It turned out that Windows 7 does not enable TLS 1.2 by default. You have to do it manually by following this process https://support.site24x7.com/portal/en/kb/articles/how-to-check-if-tls-1-2-is-enabled At this stage, the function above started working. Next, I had to add one extra line in a third party code every time TIdSSLIOHandlerSocketOpenSSL is created. The extra line is sslIOHandler.SSLOptions.SSLVersions := [sslvTLSv1_2]; After that, the application started working as before. @Remy LebeauThank you for your help Alberto
  10. Alberto Paganini

    tlsv1 alert protocol version

    It seems I am making progress with this. I have amended the class in a way the application loads the .DLLs residing in the application folder. This is achieved with IdSSLOpenSSLHeaders.IdOpenSSLSetLibPath(). (Thanks to Remi for this post https://stackoverflow.com/questions/13269169/how-to-use-a-dll-outside-of-the-system-path) IdSSLOpenSSL.OpenSSLVersion; confirms now "OpenSSL 1.0.2q 20 Nov 2018" is loaded and this collides with the .DLLs version in the application folder. As far as I can see from the https://www.openssl.org/news/openssl-1.0.2-notes.html the OpenSSL 1.0.2 supports TLS 1.2 for a long time (Jan 2015). Despite that my application still throws "tlsv1 alert protocol version" Is there anything else I should be aware of ? The amended source code is here above if anybody may be interested. Many thanks Alberto function TConnectionClass.GetToken: Boolean; var LJSONObject: TJSONObject; LJSONValue: TJSONValue; {$IFDEF VER230} LJSONPair: TJSONPair; {$ENDIF} LJSONToken: TJSONValue; IdHTTP: TIdHTTP; IdSSL: TIdSSLIOHandlerSocketOpenSSL; IdLogFile: TIdLogFile; sList: TStringList; Path:string; OpenSSLVersion:string; begin begin Result := False; FToken := ''; Path:=ExtractFilePath(ParamStr(0)); IdSSLOpenSSLHeaders.IdOpenSSLSetLibPath(Path); OpenSSLVersion:= IdSSLOpenSSL.OpenSSLVersion; IdHTTP := TIdHTTP.Create(nil); try IdHTTP.HTTPOptions := IdHTTP.HTTPOptions + [hoForceEncodeParams]; IdHTTP.HandleRedirects := True; IdSSL := TIdSSLIOHandlerSocketOpenSSL.Create(IdHTTP); IdSSL.SSLOptions.SSLVersions := [sslvTLSv1, sslvTLSv1_1, sslvTLSv1_2]; IdHTTP.IOHandler := IdSSL; IdLogFile := TIdLogFile.Create(IdHTTP); IdLogFile.Filename := 'c:\' + ChangeFileExt(ExtractFileName(ParamStr(0)), '.log'); IdLogFile.Active := True; IdHTTP.Intercept := IdLogFile; IdHTTP.Request.Accept := 'application/json'; IdHTTP.Request.CustomHeaders.Values['X-Application'] := cBetfair_AppKey; IdHTTP.Request.ContentType := 'application/x-www-form-urlencoded'; sList := TStringList.Create; try sList.Add('username=' + FUserID); sList.Add('password=' + FPassword); LJSONValue := TJSONObject.ParseJSONValue(IdHTTP.Post(URL_LOGIN, sList)); try if LJSONValue is TJSONObject then begin LJSONObject := TJSONObject(LJSONValue); {$IFDEF VER230} LJSONPair := LJSONObject.Get('token'); if LJSONPair <> nil then LJSONToken := LJSONPair.JsonValue else LJSONToken := nil; {$ELSE} LJSONToken := LJSONObject.Values['token']; {$ENDIF} if LJSONToken <> nil then FToken := LJSONToken.Value; end; finally LJSONValue.Free; end; finally sList.Free; end; finally IdHTTP.Free; end; Result := (FToken <> ''); end;
  11. Alberto Paganini

    tlsv1 alert protocol version

    @Remy Lebeau Yes, this is the issue. I have just found out from the provider that "From 1st December only TLS 1.2 and above will be supported". I renamed libeay32.dll and ssleay32.dll in the system32 folder, downloaded the two .DLLs from Github, placed them in the application folder but the error is still the same. The version I have reported is the one found in the properties of the .DLL files. However, the OpenSSLVersion function reports OpenSSL 1.0.0d 8 Feb 2011, and that explains why the .exe is not working any longer. Does it mean my application uses other SSL .DLLs on my hard disk? (yes, I have a few installed by other third-party software. Each of them resides in the relevant application folder) How can I tell my application that the correct .DLL resides in the same folder of the application itself? I don't want to delete the other .DLLs in order not to stop the other applications to work. Many thanks. Alberto
  12. Alberto Paganini

    tlsv1 alert protocol version

    Hello, I have a problem with a Win32 application using Indy. All of a sudden it throws me the following error message: "Error connecting with SSL. error 1409442E:SSL routine:ssl3_read_bytes:tlsv1 alert protocol version" In the beginning, I supposed it had something to do with an obsolete version I manage in my source. The following is the only place in my source where I set the SSL version and it supports the version 1.2 function TConnectionClass.GetToken: Boolean; var LJSONObject: TJSONObject; LJSONValue: TJSONValue; {$IFDEF VER230} LJSONPair: TJSONPair; {$ENDIF} LJSONToken: TJSONValue; IdHTTP: TIdHTTP; IdSSL: TIdSSLIOHandlerSocketOpenSSL; IdLogFile: TIdLogFile; sList: TStringList; begin Result := False; FToken := ''; IdHTTP := TIdHTTP.Create(nil); try IdHTTP.HTTPOptions := IdHTTP.HTTPOptions + [hoForceEncodeParams]; IdHTTP.HandleRedirects := True; IdSSL := TIdSSLIOHandlerSocketOpenSSL.Create(IdHTTP); IdSSL.SSLOptions.SSLVersions := [sslvTLSv1, sslvTLSv1_1, sslvTLSv1_2]; IdHTTP.IOHandler := IdSSL; IdLogFile := TIdLogFile.Create(IdHTTP); IdLogFile.Filename := 'c:\' + ChangeFileExt(ExtractFileName(ParamStr(0)), '.log'); IdLogFile.Active := True; IdHTTP.Intercept := IdLogFile; IdHTTP.Request.Accept := 'application/json'; IdHTTP.Request.CustomHeaders.Values['X-Application'] := cBetfair_AppKey; IdHTTP.Request.ContentType := 'application/x-www-form-urlencoded'; sList := TStringList.Create; try sList.Add('username=' + FUserID); sList.Add('password=' + FPassword); LJSONValue := TJSONObject.ParseJSONValue(IdHTTP.Post(URL_LOGIN, sList)); try if LJSONValue is TJSONObject then begin LJSONObject := TJSONObject(LJSONValue); {$IFDEF VER230} LJSONPair := LJSONObject.Get('token'); if LJSONPair <> nil then LJSONToken := LJSONPair.JsonValue else LJSONToken := nil; {$ELSE} LJSONToken := LJSONObject.Values['token']; {$ENDIF} if LJSONToken <> nil then FToken := LJSONToken.Value; end; finally LJSONValue.Free; end; finally sList.Free; end; finally IdHTTP.Free; end; Result := (FToken <> ''); end; I also tried to amend the options into IdSSL.SSLOptions.SSLVersions := [sslvTLSv1_2]; but the error is still the same Then I updated the SSL .dll files in my system32 folder by downloading the latest version of libeay32.dll and ssleay32.dll from here https://indy.fulgan.com/SSL/ and replace the old files with the new ones. I have double-checked and now the .dll have Version file 1.0.2.21 and Version 1.0.2u Despite these attempts, the application still throws me the same exception. Is there anything else I should change? Many thanks Alberto
  13. Alberto Paganini

    Delete FastMM4 MemoryManager_EventLog.txt

    Thank you David, this did the trick !
  14. Alberto Paganini

    Delete FastMM4 MemoryManager_EventLog.txt

    I did and created this test: program Project3; {$APPTYPE CONSOLE} {$R *.res} uses FastMM4, system.Classes, System.SysUtils; var t:tstringlist; begin t:=TStringList.Create; end. I ran it a number of times and the new reports are appended to the old ones. Obviously there must be something wrong in my FastMM4 settings. I will look into that.
  15. I use FastMM4 to check memory leaks and I noticed the report file " MyApplicatoin+MemoryManager_EventLog.txt" is not deleted automatically once I have amended the source and I run my application again. This way if there are still memory leaks they are added to the existing report and this confuses me. Is there an option in FastMM4 to achieve that I am not aware of or do I have to rely on DeleteFile(...) when I run the application ? Many thanks Alberto
×