Recent

Author Topic: [SOLVED] Code clean up at procedure TScreen.EndTempCursor  (Read 2264 times)

lagprogramming

  • Sr. Member
  • ****
  • Posts: 406
[SOLVED] Code clean up at procedure TScreen.EndTempCursor
« on: July 20, 2023, 10:00:49 am »
lcl/include/screen.inc has
Code: Pascal  [Select][+][-]
  1. procedure TScreen.EndTempCursor(const aCursor: TCursor);
  2.   procedure _Delete(const _Index: Integer); // FPC 3.0.x doesn't support Delete() for arrays #36728
  3.   var
  4.     I: Integer;
  5.   begin
  6.     for I := _Index to High(FTempCursors)-1 do
  7.       FTempCursors[I] := FTempCursors[I+1];
  8.     SetLength(FTempCursors, Length(FTempCursors)-1);
  9.   end;
  10. var
  11.   I: Integer;
  12.   OldCursor: TCursor;
  13. begin
  14.   OldCursor := RealCursor;
  15.   for I := High(FTempCursors) downto Low(FTempCursors) do
  16.   begin
  17.     if FTempCursors[I]=aCursor then
  18.     begin
  19.       _Delete(I);
  20.       if OldCursor<>RealCursor then
  21.         WidgetSet.SetCursor(Cursors[RealCursor]);
  22.       Exit;
  23.     end;
  24.   end;
  25.   raise Exception.CreateFmt('Unbalanced BeginTempCursor/EndTempCursor calls for cursor %d', [aCursor]);
  26. end;
The nested procedure is no longer needed.
The following patch removes it by replacing the _Delete(I); line with delete(FTempCursors,I,1);.
Code: Pascal  [Select][+][-]
  1. diff --git a/lcl/include/screen.inc b/lcl/include/screen.inc
  2. index 346dcf03d8..6d4eaa8c34 100644
  3. --- a/lcl/include/screen.inc
  4. +++ b/lcl/include/screen.inc
  5. @@ -438,14 +438,6 @@ begin
  6.  end;
  7.  
  8.  procedure TScreen.EndTempCursor(const aCursor: TCursor);
  9. -  procedure _Delete(const _Index: Integer); // FPC 3.0.x doesn't support Delete() for arrays #36728
  10. -  var
  11. -    I: Integer;
  12. -  begin
  13. -    for I := _Index to High(FTempCursors)-1 do
  14. -      FTempCursors[I] := FTempCursors[I+1];
  15. -    SetLength(FTempCursors, Length(FTempCursors)-1);
  16. -  end;
  17.  var
  18.    I: Integer;
  19.    OldCursor: TCursor;
  20. @@ -455,7 +447,7 @@ begin
  21.    begin
  22.      if FTempCursors[I]=aCursor then
  23.      begin
  24. -      _Delete(I);
  25. +      delete(FTempCursors,I,1);
  26.        if OldCursor<>RealCursor then
  27.          WidgetSet.SetCursor(Cursors[RealCursor]);
  28.        Exit;
« Last Edit: July 20, 2023, 12:04:24 pm by lagprogramming »


Zvoni

  • Hero Member
  • *****
  • Posts: 2620
Re: Code clean up at procedure TScreen.EndTempCursor
« Reply #2 on: July 20, 2023, 10:35:47 am »
Wouldn't it make more sense to put it into a conditional?
Code: Pascal  [Select][+][-]
  1. {$IF FPC_FULLVERSION<=30200}
  2.        //Use Nested Proc
  3. {$ELSE}
  4.        //Use "native" Delete
  5. {$ENDIF}    
  6.  
There might still be people having to use "older" compilers
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

paweld

  • Hero Member
  • *****
  • Posts: 1187
Re: Code clean up at procedure TScreen.EndTempCursor
« Reply #3 on: July 20, 2023, 11:19:01 am »
Quote from: Zvoni
There might still be people having to use "older" compilers
Lazarus supports the last 2 stable versions of fpc, that is, Lazarus trunk version supports fpc 3.2.0 and fpc 3.2.2. so such a condition makes no sense. 
Recently removed old checks: https://gitlab.com/freepascal.org/lazarus/lazarus/-/commit/adfc424e92109b038af669460d5c6bb3b4867f5c
« Last Edit: July 20, 2023, 11:23:01 am by paweld »
Best regards / Pozdrawiam
paweld

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4515
  • I like bugs.
Re: Code clean up at procedure TScreen.EndTempCursor
« Reply #4 on: July 20, 2023, 06:11:46 pm »
There might still be people having to use "older" compilers
Lazarus trunk has not compiled with FPC 3.0.x for some time.
It is better clean the code and remove obsolete IFDEFs.
With older compilers you must use older Lazarus versions. They remain functional.

An "old compiler" is a flexible term. Even the supported FPC 3.2.0 is already old because of the slow release cycle of FPC project. ... and there are no signs for a bug fix release FPC 3.2.4 yet. This FPC policy is annoying to put it mildly.
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

 

TinyPortal © 2005-2018