From 8576232676c232cd1c94b070e7db728bf0868b7b Mon Sep 17 00:00:00 2001 From: mattias Date: Mon, 26 May 2025 11:34:18 +0200 Subject: [PATCH] codetools: gatherlfm: fixed skipping binary data --- components/codetools/stdcodetools.pas | 24 ++++++-- components/codetools/tests/testlfmtrees.pas | 23 ++++++++ .../codetools/tests/testrefactoring.pas | 59 +++++++++++++++++++ 3 files changed, 100 insertions(+), 6 deletions(-) diff --git a/components/codetools/stdcodetools.pas b/components/codetools/stdcodetools.pas index a9de7e995c..0ee1edb49e 100644 --- a/components/codetools/stdcodetools.pas +++ b/components/codetools/stdcodetools.pas @@ -2863,7 +2863,7 @@ var procedure FindCandidates; var s: String; - LFMStream: TMemoryStream; + LFMStream, MemStream: TMemoryStream; Parser: TParser; p: SizeInt; begin @@ -2879,11 +2879,23 @@ var Parser := TParser.Create(LFMStream); repeat Parser.NextToken; - if Parser.Token=#0 then - break - else if Parser.TokenSymbolIs(Identifier) then begin - p:=Parser.SourcePos+1-Length(Identifier); - Insert(p,IdentifierPositions,length(IdentifierPositions)); + case Parser.Token of + #0: break; + toSymbol: + begin + p:=Parser.SourcePos+1-Length(Identifier); + Insert(p,IdentifierPositions,length(IdentifierPositions)); + end; + '{': + begin + MemStream := TMemoryStream.Create; + try + Parser.HexToBinary(MemStream); + finally + MemStream.Free; + end; + Parser.NextToken; + end; end; until false; finally diff --git a/components/codetools/tests/testlfmtrees.pas b/components/codetools/tests/testlfmtrees.pas index b37e8548ed..d7551925d0 100644 --- a/components/codetools/tests/testlfmtrees.pas +++ b/components/codetools/tests/testlfmtrees.pas @@ -50,6 +50,7 @@ type procedure LFMUnitname; procedure LFM_RootUnitnameWrong; procedure LFM_ChildUnitnameWrong; + procedure LFM_BinaryData; end; implementation @@ -111,9 +112,12 @@ begin ' property OnClick: TNotifyEvent;', ' end;', '', + ' TBitmap = class(TPersistent)', + ' end;', ' TButton = class(TControl)', ' published', ' property Default: Boolean;', + ' property Glyph: TBitmap;', ' end;', '', ' TFormStyle = (fsNormal, fsMDIChild, fsMDIForm, fsStayOnTop, fsSplash, fsSystemStayOnTop);', @@ -340,6 +344,25 @@ begin CheckLFMParseError(lfmeObjectIncompatible,CodeXYPosition(19,2,FLFMCode),'Controls expected, but Fool found. See unit1.pas(7,5)'); end; +procedure TTestLFMTrees.LFM_BinaryData; +begin + AddControls; + AddFormUnit(['Button1: TButton']); + FLFMCode:=AddSource('unit1.lfm',LinesToStr([ + 'object Form1: TForm1', + ' object Button1: TButton', + ' Glyph.Data = {', + ' 36040000424D3604000000000000360000002800000010000000100000000100', + ' 49EE000000000004000064000000640000000000000000000000000000000000', + ' }', + ' Caption = ''ClickMe''', + ' Default = True', + ' end', + 'end' + ])); + CheckLFMParseError(lfmeIdentifierNotFound,CodeXYPosition(11,3,FLFMCode),'identifier Data not found in class "TBitmap"'); +end; + initialization RegisterTest(TTestLFMTrees); diff --git a/components/codetools/tests/testrefactoring.pas b/components/codetools/tests/testrefactoring.pas index ce1fc8c3ed..297d3b6a20 100644 --- a/components/codetools/tests/testrefactoring.pas +++ b/components/codetools/tests/testrefactoring.pas @@ -89,6 +89,7 @@ type // rename also in lfm procedure TestRenameAlsoLFM_Variable; procedure TestRenameAlsoLFM_Event; + procedure TestRenameAlsoLFM_SkipBinaryData; end; implementation @@ -2109,6 +2110,64 @@ begin end; end; +procedure TTestRefactoring.TestRenameAlsoLFM_SkipBinaryData; +var + Test1LFM, RedUnit: TCodeBuffer; +begin + RedUnit:=CodeToolBoss.CreateFile('red.pas'); + Test1LFM:=CodeToolBoss.CreateFile(ChangeFileExt(Code.Filename,'.lfm')); + try + RedUnit.Source:='unit Red;'+LineEnding + +'interface'+LineEnding + +'type'+LineEnding + +' TForm = class'+LineEnding + +' end;'+LineEnding + +' TBitmap = class'+LineEnding + +' end;'+LineEnding + +' TButton = class'+LineEnding + +' published'+LineEnding + +' property Glyph: TBitmap;'+LineEnding + +' end;'+LineEnding + +'implementation'+LineEnding + +'end.'; + + Test1LFM.Source:=LinesToStr([ + 'object Form1: TForm1', + ' object Button1: TButton', + ' Glyph.Data = {', + ' 36040000424D3604000000000000360000002800000010000000100000000100', + ' 49EE000000000004000064000000640000000000000000000000000000000000', + ' }', + ' end', + 'end']); + + Add(['unit Test1;', + '{$mode objfpc}{$H+}', + 'interface', + 'uses red;', + 'type', + ' TForm1 = class(TForm)', + ' Button1{#Rename}: TButton;', + ' end;', + 'implementation', + 'end.']); + RenameReferences('OkBtn',frfAllLFM); + CheckDiff(Test1LFM,[ + 'object Form1: TForm1', + ' object OkBtn: TButton', + ' Glyph.Data = {', + ' 36040000424D3604000000000000360000002800000010000000100000000100', + ' 49EE000000000004000064000000640000000000000000000000000000000000', + ' }', + ' end', + 'end']); + + finally + RedUnit.IsDeleted:=true; + Test1LFM.IsDeleted:=true; + end; +end; + initialization RegisterTests([TTestRefactoring]); end.