Jump to content

Leaderboard


Popular Content

Showing content with the highest reputation on 02/06/23 in all areas

  1. mytbo

    Enable protocol TLS 1.3 on Windows 7

    The all-purpose solution is Curl. The curl.exe program is part of current Windows versions. Links: GitHub, Download, Manual, libcurl C API and libcurl C examples. An encapsulation for libcurl DLL can be found in the mORMot unit mormot.lib.curl. The mORMot library does not need to be installed. Download the current commit and the static binaries from the last tag directory. Set the appropriate library and search paths in Delphi. This pattern helps to create them: // Simply replace the colons with the save path ..\src;..\src\app;..\src\core;..\src\crypt;..\src\db;..\src\lib;..\src\misc;..\src\net;..\src\orm;..\src\rest;..\src\script;..\src\soa;..\src\tools\ecc;..\src\ui; For many use cases you can find a template in the libcurl C examples. The following Delphi example shows the implementation for a download: uses mormot.core.base, mormot.core.text, mormot.core.os, mormot.lib.curl; var hnd: TCurl; url: RawUtf8; res: TCurlResult; buffer: RawByteString; responseSize: Int64; begin if not CurlIsAvailable then Exit; //=> hnd := curl.easy_init; if hnd <> Nil then begin url := 'https://icons8.com/icons/set/home.html'; curl.easy_setopt(hnd, coURL, Pointer(url)); curl.easy_setopt(hnd, coSSLVerifyPeer, 0); curl.easy_setopt(hnd, coSSLVerifyHost, 0); curl.easy_setopt(hnd, coWriteFunction, @CurlWriteRawByteString); curl.easy_setopt(hnd, coWriteData, @buffer); res := curl.easy_perform(hnd); if res = crOk then begin FileFromString(buffer, MakePath([Executable.ProgramFilePath, 'home.html'])); curl.easy_getinfo(hnd, ciSizeDownloadT, responseSize); ShowMessage(Format('Download completed: %s', [KB(responseSize)])); end else ShowMessage(Format('Curl told us %d (%s)', [Ord(res), curl.easy_strerror(res)])); curl.easy_cleanup(hnd); end; end; An example to study is also the class TCurlHttp from the unit mormot.net.client. With best regards Thomas
  2. KodeZwerg

    More precise countdown

    unit Unit1; interface uses Winapi.MMSystem, Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls; type TForm1 = class(TForm) btnTimerOn: TButton; btnTimerOff: TButton; Memo1: TMemo; procedure FormCreate(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure btnTimerOffClick(Sender: TObject); procedure btnTimerOnClick(Sender: TObject); strict private FMMRESULT: MMRESULT; private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TimerCallBack(TimerID, Msg: Uint; dwUser, dw1, dw2: DWORD); pascal; begin Form1.Memo1.Lines.Add('Hello from Multimedia Timer!'); end; procedure TForm1.FormCreate(Sender: TObject); begin FMMRESULT := DWORD(-1); end; procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction); begin btnTimerOffClick(Sender); Action := caFree; end; procedure TForm1.btnTimerOnClick(Sender: TObject); var LDelay: UINT; begin if (FMMRESULT <> DWORD(-1)) then btnTimerOffClick(Sender); LDelay := 1000; // Timer in millisecond (1000 = 1 second) FMMRESULT := TimeSetEvent(LDelay, 0, @TimerCallBack, 0, TIME_PERIODIC); end; procedure TForm1.btnTimerOffClick(Sender: TObject); begin if (FMMRESULT <> DWORD(-1)) then begin TimeKillEvent(FMMRESULT); FMMRESULT := DWORD(-1); end; end; end. In my experience, nothing beats a multimedia timer. I hope it helps.
×