Jump to content

KodeZwerg

Members
  • Content Count

    289
  • Joined

  • Last visited

  • Days Won

    3

Everything posted by KodeZwerg

  1. Simple check (FileExists()) before download from your list, delete or rename however you like (depending on filesize, I would first download and on success rename to the original filename)
  2. KodeZwerg

    Update an application automatically

    @aehimself I am impressed by your updater and other useful things you collected, maybe you like to upgrade the unit OSVersion.pas type TTrueVersion = packed record Major, Minor, Build: DWORD; end; procedure RtlGetNtVersionNumbers(out MajorVersion, MinorVersion, BuildNumber: DWORD); stdcall; external 'Ntdll.dll'; function GetTrueVersion: TTrueVersion; var vMaj, vMin, vBuild: DWORD; begin RtlGetNtVersionNumbers(vMaj, vMin, vBuild); Result.Major := vMaj; Result.Minor := vMin; Result.Build := Lo(vBuild); end; procedure TForm1.FormCreate(Sender: TObject); var ver: TTrueVersion; begin ver := GetTrueVersion; Label1.Caption := Format('Running Windows %d.%d Build: %d', [ver.Major, ver.Minor, ver.Build]); end; That's the most accurate way to determine a Windows version that I do know.
  3. KodeZwerg

    More precise countdown

    I just used it like I would use a standard TTimer. Here is a sample usage, in attachment a full project you can load in. procedure TForm11.FormCreate(Sender: TObject); begin Timer1 := TkzTimer.Create(Self); try Timer1.OnTimer := DoTimer1; Timer1.LinkIntervalDueTime := False; Timer1.DueTime := 5000; Timer1.Interval := 1; finally Timer1.Enabled := True; end; Timer2 := TkzTimer.Create(Self); try Timer2.OnTimer := DoTimer2; Timer2.Interval := 750; finally Timer2.Enabled := True; end; end; I've tested with Delphi Alexandria, 32 and 64 bit. When you load project and build it, answer the question about "remove does not have corresponding component" with "No" As you can see and liked to have, DueTime is added, by default it act like the basic TTimer act with a lag of 1000ms or whatever Interval you set. In demo i used 1ms with a waiting time of 5s and 750ms, works for me flawless and nothing bad happen on closing the demo. I added a LinkIntervalDueTime boolean that control if values should be in balance (like a basic TTimer would be) or complete seperated from each other. Anyway, 1ms is in my demo too fast to process for Vcl, lags are on Vcl side, not my Component. I hope you like it and find it useful for your needs. kzTimer.zip
  4. KodeZwerg

    Memory Leak when loading/unloading Delphi DLL

    At what point you confirm that you having a memory leak? Beside that you do not check for anything (what you should do) your infinite loop loads faster than it release, but ref counting works correct here.
  5. KodeZwerg

    More precise countdown

    @programmerdelphi2k updated to the method you mentioned, thanks @aehimself updated to a more stable version that can run multiple times unit kz.Windows.Timer; interface uses Winapi.Windows, Winapi.Messages, Vcl.Forms, System.Classes; type TkzTimer = class(TComponent) strict private FEnabled: Boolean; FInterval: DWORD; FOnTimer: TNotifyEvent; FHandle: THandle; private FHWND: HWND; private procedure EnableTimer; procedure DisableTimer; procedure SetEnabled(const AValue: Boolean); procedure SetInterval(const AValue: DWORD); protected procedure WndProc(var Message: TMessage); procedure DoTimer; virtual; public constructor Create(AOwner: TComponent); override; destructor Destroy; override; published property Enabled: Boolean read FEnabled write SetEnabled default False; property Interval: DWORD read FInterval write SetInterval default 1000; property OnTimer: TNotifyEvent read FOnTimer write FOnTimer; end; implementation procedure TimerCallback(lpParameter: TkzTimer; TimerOrWaitFired: Boolean); StdCall; begin Winapi.Windows.PostMessage(lpParameter.FHWND, (WM_APP + 666), 0, 0); end; procedure TkzTimer.DoTimer; begin if Assigned(FOnTimer) then FOnTimer(Self); end; procedure TkzTimer.WndProc(var Message: TMessage); begin case Message.Msg of (WM_APP + 666): try DoTimer; except Vcl.Forms.Application.HandleException(Self); end else Message.Result := Winapi.Windows.DefWindowProc(FHWND, Message.Msg, Message.WParam, Message.LParam); end; end; constructor TkzTimer.Create(AOwner: TComponent); begin inherited Create(AOwner); FEnabled := False; FInterval := 1000; FOnTimer := nil; FHandle := Winapi.Windows.INVALID_HANDLE_VALUE; FHWND := System.Classes.AllocateHWnd(WndProc); end; destructor TkzTimer.Destroy; begin FOnTimer := nil; DisableTimer; System.Classes.DeallocateHWnd(FHWND); inherited Destroy; end; procedure TkzTimer.SetEnabled(const AValue: Boolean); begin if AValue then EnableTimer else DisableTimer; end; procedure TkzTimer.SetInterval(const AValue: DWORD); begin FInterval := AValue; if (FInterval < 1) then FInterval := 1; if FEnabled then EnableTimer; end; procedure TkzTimer.EnableTimer; begin if (FHandle <> Winapi.Windows.INVALID_HANDLE_VALUE) then DisableTimer; FEnabled := Winapi.Windows.CreateTimerQueueTimer(FHandle, 0, @TimerCallback, Self, FInterval, FInterval, Winapi.Windows.WT_EXECUTEDEFAULT or Winapi.Windows.WT_EXECUTELONGFUNCTION); end; procedure TkzTimer.DisableTimer; begin if Winapi.Windows.DeleteTimerQueueTimer(0, FHandle, 0) then begin FHandle := Winapi.Windows.INVALID_HANDLE_VALUE; FEnabled := False; end; end; end. Alpha version 🙂
  6. KodeZwerg

    More precise countdown

    // removed obsolete
  7. KodeZwerg

    More precise countdown

    Whats the benefit compared to multimedia timer that already run in its own thread? @aehimself (No complain against your timer project!!! Lots of kudos for you for sharing it!)
  8. 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.
  9. Since I do not know how your registry code looks like, may it be a 32/64bit issue? //for 32bit Reg := TRegistry.Create(KEY_READ or KEY_WOW64_32KEY); //for 64bit Reg := TRegistry.Create(KEY_READ or KEY_WOW64_64KEY);
  10. KodeZwerg

    Detect if WebView2 Runtime is installed

    I did asked myself today the same question and did made a different approach and would like to know what you think about it? On the form with the TWebBrowser that has its SelectedEngine property set to "EdgeIfAvailable" I put in FormShow event: WebBrowser.Navigate('about:blank'); For the WebBrowser I did created an Event for "OnNavigateBefore2" with the following content: if string(URL) = string('about:blank') then if WebBrowser.ActiveEngine <> Edge then begin // here I let my form display a message that Edge Runtime is missing and a button to open the official download site end; For me it worked and now I searched for other solutions and found this thread. (I was aware of the Registry Key but that does not ensure if user might has deleted the WebView2Loader.dll...)
  11. I did today my first baby steps, thanks to your post I finally got my browser working with it (it stayed just white all the time for no reason) From here i downloaded both runtimes (x86/x64) and did not find the file you mentioned on my system (WebView2Loader.dll) After searching about that specific needed file, I found out that I do need the WebView2 SDK... but from where? Finally I ended up here, I clicked on Versions and selected the latest stable (in my case from today it is/was 1.0.1518.46) and clicked on the right side on Download package. That file is a renamed Zip archive, so I renamed it and extracted everything in a seperate folder. Inside \runtimes\win-x64\native\ or or \runtimes\win-x86\native\ you will find that file, copy your needed variant x86/x64 next to your compiler project and now no more white screen, app is working. I hope that helps if someone else want to have the new technology working which by default isnt. Cheers
  12. Many thanks! Was searching for a solution and yours is exactly matching my needs @dummzeuch
  13. I did discovered a bug i guess by accident. I wanted to expand my own .inc file to support FreePascal but compiler did not let me. {$IF Defined(FPC)} {$IF Declared(FPC_VERSION)} {$IF FPC_VERSION >= 3} // [Pascal Error] kz.inc(80): E2026 Constant expression expected {$DEFINE UNICODE} {$IFEND FPC_VERSION} {$IFEND FPC_VERSION} {$IFEND FPC} A fix was to do it like this, himitsu from german Delphi-Praxis came up with: {$IF Defined(FPC) and Declared(FPC_VERSION) and (FPC_VERSION >= 3)} {$DEFINE UniCode} { FreePascal UniCode support } {$IFEND} I did open a Report -> Conditional Compiling dont work as expect If you think i was wrong, please correct me.
  14. KodeZwerg

    did Sherlock left DP?

    Good day! I wonder why he does not log in anymore?! Since english DP started he aint active on german DP anymore and now inactive since start of 2021. Is he okay? @Sherlock
  15. KodeZwerg

    TJsonTextWriter out of memory

    Since you did not told for what purpose you need to have everything stored to memory, another approach can be to use a database and only get/put data that you actual need for current task.
  16. Good day everone! I did opened this https://quality.embarcadero.com/browse/RSP-33937 to have Segoe UI (Windows Vista+) as Default Font instead of Tahoma (Windows XP) Stay healthy!
  17. Hopefully that should give the doubters enough courage to vote 👍
  18. Thank you for voting, here is my workaround way to have it scaled properly: procedure ApplyFontAndScale(aForm: TForm); var OldSize : Integer; Font : TFont; begin OldSize := aForm.Font.Size; if Screen.MessageFont.Size <> OldSize then begin Font := TFont.Create; try Font.Assign(Screen.MessageFont); Font.Size := OldSize; aForm.Font := Font; finally Font.Free; end; aForm.ScaleBy(Abs(Screen.MessageFont.Size), Abs(OldSize)); end else aForm.Font := Screen.MessageFont; if aForm.BorderStyle <> bsSizeable then begin if aForm.Height > Screen.WorkAreaHeight then aForm.ScaleBy(Screen.WorkAreaHeight, aForm.Height); if aForm.Width > Screen.WorkAreaWidth then aForm.ScaleBy(Screen.WorkAreaWidth, aForm.Width); end; end; calling within OnCreate event.
  19. You can read what Microsoft write in this link. Using "MS Shell Dlg 2" pseudo font is to be backward compatible i guess. (Would be fatal if from now on that HKEY would lead to Segoe UI, font size would not match on old applications....) Feel free to use the classic Windows XP way, my wish is to be more modern and not support Windows XP.
  20. KodeZwerg

    Prevent Alt or Ctrl + Print Screen

    Thank you Mr. Heffernan, that work! type TfrmMain = class(TForm) protected procedure CreateWnd; override; end; implementation procedure TfrmMain.CreateWnd; begin inherited CreateWnd; SetWindowDisplayAffinity(Handle, WDA_MONITOR); end;
  21. KodeZwerg

    Prevent Alt or Ctrl + Print Screen

    SetWindowDisplayAffinity(Application.MainFormHandle, WDA_MONITOR); Does do nothing, did I called it wrong? //edit SetWindowDisplayAffinity(Application.MainFormHandle, WDA_MONITOR or WDA_EXCLUDEFROMCAPTURE); Also not working. (I called it in FormCreate event) Used Capture Software: Screenshot Captor from DonationCoder.com Tested on latest Windows 10 pro.
  22. KodeZwerg

    did Sherlock left DP?

    My worry = corona virus 😞
  23. KodeZwerg

    Prevent Alt or Ctrl + Print Screen

    Beside analog copy (smartphone) what cant be stopped (but can be a bit mangled if playing with display Hertz) and hooks to eat keyboard you can prevent digital copies (simple screencapture tools) by using overlay to draw screen or write direct to graphic card buffers. Simple Screencapture or Print would end with a black screen.
  24. Equal how you try, it end in a workaround since you publish it with a "write" property.
  25. that i mean, and within your class-code just adjust "_status" to whatever you like. or implement and publish a private setter to adjust only by code not by property if you know what i mean. TMyObject = Class(TObject) strict private _status: String; private procedure mysetter(const AValue: string); public Property Status: String Read _status; End;
×