From a2e773c07762816bd2b57f399d23bf0c9fec9e77 Mon Sep 17 00:00:00 2001 From: Martijn Laan <1092369+martijnlaan@users.noreply.github.com> Date: Thu, 13 Jun 2024 20:57:30 +0200 Subject: [PATCH] Use SCI_GETDIRECTSTATUSFUNCTION from 5.1.0, halving the number of calls to Scintilla. --- Components/ScintEdit.pas | 18 +++++++++++++----- Components/ScintInt.pas | 13 +++++++++++-- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/Components/ScintEdit.pas b/Components/ScintEdit.pas index 224724d57..e591dc3a2 100644 --- a/Components/ScintEdit.pas +++ b/Components/ScintEdit.pas @@ -82,6 +82,7 @@ TScintEdit = class(TWinControl) FAutoCompleteFontSize: Integer; FCodePage: Integer; FDirectPtr: Pointer; + FDirectStatusFunction: SciFnDirectStatus; FEffectiveCodePage: Integer; FEffectiveCodePageDBCS: Boolean; FFillSelectionToEdge: Boolean; @@ -532,19 +533,20 @@ procedure TScintEdit.BeginUndoAction; end; function TScintEdit.Call(Msg: Cardinal; WParam: Longint; LParam: Longint): Longint; -var - ErrorStatus: LRESULT; + begin HandleNeeded; if FDirectPtr = nil then Error('Call: FDirectPtr is nil'); - Result := Scintilla_DirectFunction(FDirectPtr, Msg, WParam, LParam); + if not Assigned(FDirectStatusFunction) then + Error('Call: FDirectStatusFunction is nil'); + var ErrorStatus: Integer; + Result := FDirectStatusFunction(FDirectPtr, Msg, WParam, LParam, ErrorStatus); - ErrorStatus := Scintilla_DirectFunction(FDirectPtr, SCI_GETSTATUS, 0, 0); if ErrorStatus <> 0 then begin - Scintilla_DirectFunction(FDirectPtr, SCI_SETSTATUS, 0, 0); ErrorFmt('Error status %d returned after Call(%u, %d, %d) = %d', [ErrorStatus, Msg, WParam, LParam, Result]); + FDirectStatusFunction(FDirectPtr, SCI_SETSTATUS, 0, 0, ErrorStatus); end; end; @@ -679,10 +681,15 @@ procedure TScintEdit.CreateParams(var Params: TCreateParams); procedure TScintEdit.CreateWnd; begin + if IsscintLibary = 0 then + Error('CreateWnd: IsscintLibary is 0'); inherited; FDirectPtr := Pointer(SendMessage(Handle, SCI_GETDIRECTPOINTER, 0, 0)); if FDirectPtr = nil then Error('CreateWnd: FDirectPtr is nil'); + FDirectStatusFunction := SciFnDirectStatus(SendMessage(Handle, SCI_GETDIRECTSTATUSFUNCTION, WPARAM(FDirectPtr), 0)); + if not Assigned(FDirectStatusFunction) then + Error('CreateWnd: FDirectStatusFunction is nil'); UpdateCodePage; Call(SCI_SETCOMMANDEVENTS, 0, 0); Call(SCI_SETMODEVENTMASK, SC_MOD_INSERTTEXT or SC_MOD_DELETETEXT, 0); @@ -1967,6 +1974,7 @@ procedure TScintEdit.CNNotify(var Message: TWMNotify); procedure TScintEdit.WMDestroy(var Message: TWMDestroy); begin FDirectPtr := nil; + FDirectStatusFunction := nil; inherited; end; diff --git a/Components/ScintInt.pas b/Components/ScintInt.pas index 4e1800b02..c52faf02d 100644 --- a/Components/ScintInt.pas +++ b/Components/ScintInt.pas @@ -1276,9 +1276,18 @@ TSCNotification = record characterSource: Integer; { SCN_CHARADDED } end; -function Scintilla_DirectFunction(ptr: Pointer; iMessage: Cardinal; - wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall; external 'isscint.dll'; + SciFnDirectStatus = function(ptr: Pointer; iMessage: Cardinal; + wParam: WPARAM; lParam: LPARAM; var Status: Integer): LRESULT; cdecl; + +var + IsscintLibary: HMODULE; implementation +uses + PathFunc; + +initialization + IsscintLibary := LoadLibrary(PChar(AddBackslash(PathExtractPath(ParamStr(0))) + 'isscint.dll')); + end.