mirror of
				https://gitlab.com/freepascal.org/lazarus/lazarus.git
				synced 2025-10-26 05:02:50 +01:00 
			
		
		
		
	IDE: started searching in fpdoc files
git-svn-id: trunk@15964 -
This commit is contained in:
		
							parent
							
								
									6366cefff6
								
							
						
					
					
						commit
						a261ea868b
					
				| @ -856,7 +856,7 @@ begin | |||||||
|   if Root=nil then exit; |   if Root=nil then exit; | ||||||
|   ANode:=Root; |   ANode:=Root; | ||||||
|   while (ANode.NextBrother<>nil) do ANode:=ANode.NextBrother; |   while (ANode.NextBrother<>nil) do ANode:=ANode.NextBrother; | ||||||
|   debugln('TCodeTree.FindLastPosition A ',Anode.DescAsString,' ANode.StartPos=',dbgs(ANode.StartPos),' ANode.EndPos=',dbgs(ANode.EndPos)); |   //debugln('TCodeTree.FindLastPosition A ',Anode.DescAsString,' ANode.StartPos=',dbgs(ANode.StartPos),' ANode.EndPos=',dbgs(ANode.EndPos)); | ||||||
|   Result:=ANode.EndPos; |   Result:=ANode.EndPos; | ||||||
| end; | end; | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -3586,7 +3586,7 @@ var | |||||||
|     and ((not IsComment) |     and ((not IsComment) | ||||||
|          or ((not SkipComments) and UnitStartFound)) |          or ((not SkipComments) and UnitStartFound)) | ||||||
|     then begin |     then begin | ||||||
|       debugln('Identifier with same name found at: ', |       {debugln('Identifier with same name found at: ', | ||||||
|         dbgs(StartPos),' ',GetIdentifier(@Src[StartPos]), |         dbgs(StartPos),' ',GetIdentifier(@Src[StartPos]), | ||||||
|         ' CleanDeclCursorPos=',dbgs(CleanDeclCursorPos), |         ' CleanDeclCursorPos=',dbgs(CleanDeclCursorPos), | ||||||
|         ' MaxPos='+dbgs(MaxPos), |         ' MaxPos='+dbgs(MaxPos), | ||||||
| @ -3594,10 +3594,10 @@ var | |||||||
|         ' SkipComments='+dbgs(SkipComments), |         ' SkipComments='+dbgs(SkipComments), | ||||||
|         ' UnitStartFound='+dbgs(UnitStartFound)); |         ' UnitStartFound='+dbgs(UnitStartFound)); | ||||||
|       if CleanPosToCaret(StartPos,ReferencePos) then |       if CleanPosToCaret(StartPos,ReferencePos) then | ||||||
|         debugln('  x=',dbgs(ReferencePos.X),' y=',dbgs(ReferencePos.Y),' ',ReferencePos.Code.Filename); |         debugln('  x=',dbgs(ReferencePos.X),' y=',dbgs(ReferencePos.Y),' ',ReferencePos.Code.Filename);} | ||||||
| 
 | 
 | ||||||
|       CursorNode:=BuildSubTreeAndFindDeepestNodeAtPos(StartPos,true); |       CursorNode:=BuildSubTreeAndFindDeepestNodeAtPos(StartPos,true); | ||||||
|       debugln('  CursorNode=',CursorNode.DescAsString,' Forward=',dbgs(CursorNode.SubDesc and ctnsForwardDeclaration)); |       //debugln('  CursorNode=',CursorNode.DescAsString,' Forward=',dbgs(CursorNode.SubDesc and ctnsForwardDeclaration)); | ||||||
| 
 | 
 | ||||||
|       if (DeclarationTool=Self) |       if (DeclarationTool=Self) | ||||||
|       and ((StartPos=CleanDeclCursorPos) or (CursorNode=AliasDeclarationNode)) |       and ((StartPos=CleanDeclCursorPos) or (CursorNode=AliasDeclarationNode)) | ||||||
| @ -3615,7 +3615,7 @@ var | |||||||
|         Params.Flags:=[fdfSearchInParentNodes,fdfSearchInAncestors, |         Params.Flags:=[fdfSearchInParentNodes,fdfSearchInAncestors, | ||||||
|                        fdfExceptionOnNotFound,fdfIgnoreCurContextNode]; |                        fdfExceptionOnNotFound,fdfIgnoreCurContextNode]; | ||||||
|         if NodeIsForwardDeclaration(CursorNode) then begin |         if NodeIsForwardDeclaration(CursorNode) then begin | ||||||
|           debugln('Node is forward declaration'); |           //debugln('Node is forward declaration'); | ||||||
|           Params.Flags:=Params.Flags+[fdfSearchForward]; |           Params.Flags:=Params.Flags+[fdfSearchForward]; | ||||||
|         end; |         end; | ||||||
|         Params.ContextNode:=CursorNode; |         Params.ContextNode:=CursorNode; | ||||||
| @ -3636,7 +3636,7 @@ var | |||||||
|             raise; |             raise; | ||||||
|         end; |         end; | ||||||
| 
 | 
 | ||||||
|         debugln(' Found=',dbgs(Found)); |         //debugln(' Found=',dbgs(Found)); | ||||||
|         if Found and (Params.NewNode<>nil) then begin |         if Found and (Params.NewNode<>nil) then begin | ||||||
|           if (Params.NewNode.Desc=ctnProcedure) |           if (Params.NewNode.Desc=ctnProcedure) | ||||||
|           and (Params.NewNode.FirstChild<>nil) |           and (Params.NewNode.FirstChild<>nil) | ||||||
| @ -3647,7 +3647,7 @@ var | |||||||
|             Params.NewCodeTool.MoveCursorToProcName(Params.NewNode,true); |             Params.NewCodeTool.MoveCursorToProcName(Params.NewNode,true); | ||||||
|             Params.NewCleanPos:=Params.NewCodeTool.CurPos.StartPos; |             Params.NewCleanPos:=Params.NewCodeTool.CurPos.StartPos; | ||||||
|           end; |           end; | ||||||
|           debugln('Context=',Params.NewNode.DescAsString,' ',dbgs(Params.NewNode.StartPos),' ',dbgs(DeclarationNode.StartPos)); |           //debugln('Context=',Params.NewNode.DescAsString,' ',dbgs(Params.NewNode.StartPos),' ',dbgs(DeclarationNode.StartPos)); | ||||||
|           if (Params.NewNode=DeclarationNode) |           if (Params.NewNode=DeclarationNode) | ||||||
|           or (Params.NewNode=AliasDeclarationNode) then |           or (Params.NewNode=AliasDeclarationNode) then | ||||||
|             AddReference; |             AddReference; | ||||||
| @ -3797,7 +3797,7 @@ var | |||||||
|     end; |     end; | ||||||
| 
 | 
 | ||||||
|     // find alias declaration node |     // find alias declaration node | ||||||
|     debugln('FindDeclarationNode DeclarationNode=',DeclarationNode.DescAsString); |     //debugln('FindDeclarationNode DeclarationNode=',DeclarationNode.DescAsString); | ||||||
|     AliasDeclarationNode:=nil; |     AliasDeclarationNode:=nil; | ||||||
|     case DeclarationNode.Desc of |     case DeclarationNode.Desc of | ||||||
| 
 | 
 | ||||||
| @ -3837,7 +3837,7 @@ var | |||||||
|     and (AliasDeclarationNode.FirstChild.Desc=ctnProcedureHead) then |     and (AliasDeclarationNode.FirstChild.Desc=ctnProcedureHead) then | ||||||
|       AliasDeclarationNode:=AliasDeclarationNode.FirstChild; |       AliasDeclarationNode:=AliasDeclarationNode.FirstChild; | ||||||
|     if AliasDeclarationNode<>nil then begin |     if AliasDeclarationNode<>nil then begin | ||||||
|       debugln('FindDeclarationNode AliasDeclarationNode=',AliasDeclarationNode.DescAsString); |       //debugln('FindDeclarationNode AliasDeclarationNode=',AliasDeclarationNode.DescAsString); | ||||||
|     end; |     end; | ||||||
| 
 | 
 | ||||||
|     Result:=true; |     Result:=true; | ||||||
| @ -3845,7 +3845,7 @@ var | |||||||
|    |    | ||||||
| begin | begin | ||||||
|   Result:=false; |   Result:=false; | ||||||
|   debugln('FindReferences CursorPos=',CursorPos.Code.Filename,' x=',dbgs(CursorPos.X),' y=',dbgs(CursorPos.Y),' SkipComments=',dbgs(SkipComments)); |   //debugln('FindReferences CursorPos=',CursorPos.Code.Filename,' x=',dbgs(CursorPos.X),' y=',dbgs(CursorPos.Y),' SkipComments=',dbgs(SkipComments)); | ||||||
|    |    | ||||||
|   ListOfPCodeXYPosition:=nil; |   ListOfPCodeXYPosition:=nil; | ||||||
|   Params:=nil; |   Params:=nil; | ||||||
|  | |||||||
| @ -1,6 +1,6 @@ | |||||||
| <?xml version="1.0"?> | <?xml version="1.0"?> | ||||||
| <CONFIG> | <CONFIG> | ||||||
|   <Package Version="2"> |   <Package Version="3"> | ||||||
|     <Name Value="RunTimeTypeInfoControls"/> |     <Name Value="RunTimeTypeInfoControls"/> | ||||||
|     <Author Value="Mattias Gaertner"/> |     <Author Value="Mattias Gaertner"/> | ||||||
|     <CompilerOptions> |     <CompilerOptions> | ||||||
| @ -37,6 +37,7 @@ | |||||||
|         <Type Value="LRS"/> |         <Type Value="LRS"/> | ||||||
|       </Item3> |       </Item3> | ||||||
|     </Files> |     </Files> | ||||||
|  |     <LazDoc Paths="/home/mattias/pascal/wichtig/lazarus/components/rtticontrols/fpdoc/"/> | ||||||
|     <Type Value="RunAndDesignTime"/> |     <Type Value="RunAndDesignTime"/> | ||||||
|     <RequiredPkgs Count="3"> |     <RequiredPkgs Count="3"> | ||||||
|       <Item1> |       <Item1> | ||||||
|  | |||||||
| @ -208,6 +208,9 @@ type | |||||||
|                                        out CacheWasUsed: boolean; |                                        out CacheWasUsed: boolean; | ||||||
|                                        out AnOwner: TObject;// package or project |                                        out AnOwner: TObject;// package or project | ||||||
|                                        CreateIfNotExists: boolean = false): string; |                                        CreateIfNotExists: boolean = false): string; | ||||||
|  |     procedure GetFPDocFilenamesForSources(SrcFilenames: TStringToStringTree; | ||||||
|  |                                           ResolveIncludeFiles: boolean; | ||||||
|  |                                           var FPDocFilenames: TStringToStringTree); | ||||||
|     function FindModuleOwner(const Modulename: string): TObject; |     function FindModuleOwner(const Modulename: string): TObject; | ||||||
|     function GetOwnerModuleName(TheOwner: TObject): string; |     function GetOwnerModuleName(TheOwner: TObject): string; | ||||||
|     function ExpandFPDocLinkID(const LinkID, DefaultUnitName, |     function ExpandFPDocLinkID(const LinkID, DefaultUnitName, | ||||||
| @ -1248,6 +1251,33 @@ begin | |||||||
|   end; |   end; | ||||||
| end; | end; | ||||||
| 
 | 
 | ||||||
|  | procedure TCodeHelpManager.GetFPDocFilenamesForSources( | ||||||
|  |   SrcFilenames: TStringToStringTree; ResolveIncludeFiles: boolean; | ||||||
|  |   var FPDocFilenames: TStringToStringTree); | ||||||
|  | var | ||||||
|  |   Node: TAvgLvlTreeNode; | ||||||
|  |   Item: PStringToStringItem; | ||||||
|  |   SrcFilename: String; | ||||||
|  |   CacheWasUsed: boolean; | ||||||
|  |   AnOwner: TObject; | ||||||
|  |   FPDocFilename: String; | ||||||
|  | begin | ||||||
|  |   Node:=SrcFilenames.Tree.FindLowest; | ||||||
|  |   while Node<>nil do begin | ||||||
|  |     Item:=PStringToStringItem(Node.Data); | ||||||
|  |     SrcFilename:=Item^.Name; | ||||||
|  |     FPDocFilename:=GetFPDocFilenameForSource(SrcFilename,ResolveIncludeFiles, | ||||||
|  |                                              CacheWasUsed,AnOwner); | ||||||
|  |     //DebugLn(['TCodeHelpManager.GetFPDocFilenamesForSources FPDoc=',FPDocFilename,' Src=',SrcFilename]); | ||||||
|  |     if FPDocFilename<>'' then begin | ||||||
|  |       if FPDocFilenames=nil then | ||||||
|  |         FPDocFilenames:=CreateFilenameToStringTree; | ||||||
|  |       FPDocFilenames[FPDocFilename]:=SrcFilename; | ||||||
|  |     end; | ||||||
|  |     Node:=SrcFilenames.Tree.FindSuccessor(Node); | ||||||
|  |   end; | ||||||
|  | end; | ||||||
|  | 
 | ||||||
| function TCodeHelpManager.FindModuleOwner(const Modulename: string): TObject; | function TCodeHelpManager.FindModuleOwner(const Modulename: string): TObject; | ||||||
| var | var | ||||||
|   AProject: TLazProject; |   AProject: TLazProject; | ||||||
|  | |||||||
| @ -31,7 +31,7 @@ interface | |||||||
| 
 | 
 | ||||||
| uses | uses | ||||||
|   Classes, SysUtils, LCLProc, LResources, Forms, Controls, Graphics, Dialogs, |   Classes, SysUtils, LCLProc, LResources, Forms, Controls, Graphics, Dialogs, | ||||||
|   StdCtrls, Buttons, ExtCtrls, |   StdCtrls, Buttons, ExtCtrls, AvgLvlTree, | ||||||
|   // codetools |   // codetools | ||||||
|   AVL_Tree, CodeAtom, CodeCache, CodeToolManager, |   AVL_Tree, CodeAtom, CodeCache, CodeToolManager, | ||||||
|   // IDE |   // IDE | ||||||
| @ -272,27 +272,23 @@ function GatherFPDocReferences(PascalFiles: TStringList; | |||||||
|   DeclarationCode: TCodeBuffer; const DeclarationCaretXY: TPoint; |   DeclarationCode: TCodeBuffer; const DeclarationCaretXY: TPoint; | ||||||
|   var TreeOfPCodeXYPosition: TAVLTree): TModalResult; |   var TreeOfPCodeXYPosition: TAVLTree): TModalResult; | ||||||
| var | var | ||||||
|   i: Integer; |   PascalFilenames, FPDocFilenames: TStringToStringTree; | ||||||
|   PascalFilename: string; |  | ||||||
|   Filename: string; |  | ||||||
|   CurOwner: TObject; |  | ||||||
|   CacheWasUsed: boolean; |  | ||||||
| begin | begin | ||||||
|   Result:=mrCancel; |   Result:=mrCancel; | ||||||
|   TreeOfPCodeXYPosition:=nil; |   TreeOfPCodeXYPosition:=nil; | ||||||
|  |   PascalFilenames:=nil; | ||||||
|  |   FPDocFilenames:=nil; | ||||||
|   try |   try | ||||||
|     CleanUpFileList(PascalFiles); |     CleanUpFileList(PascalFiles); | ||||||
| 
 | 
 | ||||||
|     // search fpdoc files |     PascalFilenames:=CreateFilenameToStringTree; | ||||||
|     for i:=0 to PascalFiles.Count-1 do begin |     PascalFilenames.AddValues(PascalFiles); | ||||||
|       PascalFilename:=PascalFiles[i]; |     CodeHelpBoss.GetFPDocFilenamesForSources(PascalFilenames,true,FPDocFilenames); | ||||||
|       Filename:=CodeHelpBoss.GetFPDocFilenameForSource(PascalFilename,true, |  | ||||||
|         CacheWasUsed,CurOwner); |  | ||||||
|       if Filename='' then continue; |  | ||||||
|     end; |  | ||||||
| 
 | 
 | ||||||
|     Result:=mrOk; |     Result:=mrOk; | ||||||
|   finally |   finally | ||||||
|  |     PascalFilenames.Free; | ||||||
|  |     FPDocFilenames.Free; | ||||||
|     if Result<>mrOk then |     if Result<>mrOk then | ||||||
|       CodeToolBoss.FreeTreeOfPCodeXYPosition(TreeOfPCodeXYPosition); |       CodeToolBoss.FreeTreeOfPCodeXYPosition(TreeOfPCodeXYPosition); | ||||||
|   end; |   end; | ||||||
|  | |||||||
| @ -232,6 +232,11 @@ procedure FreeListObjects(List: TList; FreeList: boolean); | |||||||
| procedure FreeListObjects(List: TFPList; FreeList: boolean); | procedure FreeListObjects(List: TFPList; FreeList: boolean); | ||||||
| function CompareMemStreamText(s1, s2: TMemoryStream): Boolean; | function CompareMemStreamText(s1, s2: TMemoryStream): Boolean; | ||||||
| 
 | 
 | ||||||
|  | function CompareStringToStringItemsFilename(Data1, Data2: Pointer): integer; | ||||||
|  | function ComparePAnsiStringWithStrToStrItemFilename(Key, Data: Pointer): Integer; | ||||||
|  | function CreateFilenameToStringTree: TStringToStringTree; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| implementation | implementation | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| @ -2588,6 +2593,23 @@ begin | |||||||
|   end; |   end; | ||||||
| end; | end; | ||||||
| 
 | 
 | ||||||
|  | function CompareStringToStringItemsFilename(Data1, Data2: Pointer): integer; | ||||||
|  | begin | ||||||
|  |   Result:=CompareFilenames(PStringToStringItem(Data1)^.Name, | ||||||
|  |                            PStringToStringItem(Data2)^.Name); | ||||||
|  | end; | ||||||
|  | 
 | ||||||
|  | function ComparePAnsiStringWithStrToStrItemFilename(Key, Data: Pointer | ||||||
|  |   ): Integer; | ||||||
|  | begin | ||||||
|  |   Result:=CompareFilenames(PAnsiString(Key)^,PStringToStringItem(Data)^.Name); | ||||||
|  | end; | ||||||
|  | 
 | ||||||
|  | function CreateFilenameToStringTree: TStringToStringTree; | ||||||
|  | begin | ||||||
|  |   Result:=TStringToStringTree.Create(@CompareStringToStringItemsFilename, | ||||||
|  |                                    @ComparePAnsiStringWithStrToStrItemFilename); | ||||||
|  | end; | ||||||
| 
 | 
 | ||||||
| end. | end. | ||||||
| 
 | 
 | ||||||
|  | |||||||
							
								
								
									
										29
									
								
								ide/main.pp
									
									
									
									
									
								
							
							
						
						
									
										29
									
								
								ide/main.pp
									
									
									
									
									
								
							| @ -12282,7 +12282,7 @@ var | |||||||
|   ExtraFiles: TStrings; |   ExtraFiles: TStrings; | ||||||
|   Files: TStringList; |   Files: TStringList; | ||||||
|   Identifier: string; |   Identifier: string; | ||||||
|   TreeOfPCodeXYPosition: TAVLTree; |   PascalReferences, FPDocReferences: TAVLTree; | ||||||
| begin | begin | ||||||
|   Result:=mrCancel; |   Result:=mrCancel; | ||||||
|   if not BeginCodeTool(TargetSrcEdit,TargetUnitInfo,[]) then exit; |   if not BeginCodeTool(TargetSrcEdit,TargetUnitInfo,[]) then exit; | ||||||
| @ -12314,7 +12314,8 @@ begin | |||||||
| 
 | 
 | ||||||
|   Files:=nil; |   Files:=nil; | ||||||
|   OwnerList:=nil; |   OwnerList:=nil; | ||||||
|   TreeOfPCodeXYPosition:=nil; |   PascalReferences:=nil; | ||||||
|  |   FPDocReferences:=nil; | ||||||
|   try |   try | ||||||
|     // create the file list |     // create the file list | ||||||
|     Files:=TStringList.Create; |     Files:=TStringList.Create; | ||||||
| @ -12363,30 +12364,39 @@ begin | |||||||
| 
 | 
 | ||||||
|     // search pascal source references |     // search pascal source references | ||||||
|     Result:=GatherIdentifierReferences(Files,DeclarationUnitInfo.Source, |     Result:=GatherIdentifierReferences(Files,DeclarationUnitInfo.Source, | ||||||
|       DeclarationCaretXY,Options.SearchInComments,TreeOfPCodeXYPosition); |       DeclarationCaretXY,Options.SearchInComments,PascalReferences); | ||||||
|     if CodeToolBoss.ErrorMessage<>'' then |     if CodeToolBoss.ErrorMessage<>'' then | ||||||
|       DoJumpToCodeToolBossError; |       DoJumpToCodeToolBossError; | ||||||
|     if Result<>mrOk then begin |     if Result<>mrOk then begin | ||||||
|       debugln('TMainIDE.DoFindRenameIdentifier unable to gather identifiers'); |       debugln('TMainIDE.DoFindRenameIdentifier GatherIdentifierReferences failed'); | ||||||
|       exit; |       exit; | ||||||
|     end; |     end; | ||||||
| 
 | 
 | ||||||
|     // ToDo: designer references |     {$IFDEF EnableFPDocRename} | ||||||
|     // ToDo: search lfm source references |  | ||||||
|     // ToDo: search fpdoc references |     // ToDo: search fpdoc references | ||||||
|  |     Result:=GatherFPDocReferences(Files,DeclarationUnitInfo.Source, | ||||||
|  |                                   DeclarationCaretXY,FPDocReferences); | ||||||
|  |     if Result<>mrOk then begin | ||||||
|  |       debugln('TMainIDE.DoFindRenameIdentifier GatherFPDocReferences failed'); | ||||||
|  |       exit; | ||||||
|  |     end; | ||||||
|  |     {$ENDIF} | ||||||
|  | 
 | ||||||
|  |     // ToDo: search lfm source references | ||||||
|     // ToDo: search i18n references |     // ToDo: search i18n references | ||||||
|  |     // ToDo: designer references | ||||||
| 
 | 
 | ||||||
|     // show result |     // show result | ||||||
|     if (not Options.Rename) or (not Rename) then begin |     if (not Options.Rename) or (not Rename) then begin | ||||||
|       CreateSearchResultWindow; |       CreateSearchResultWindow; | ||||||
|       Result:=ShowIdentifierReferences(DeclarationUnitInfo.Source, |       Result:=ShowIdentifierReferences(DeclarationUnitInfo.Source, | ||||||
|         DeclarationCaretXY,TreeOfPCodeXYPosition); |         DeclarationCaretXY,PascalReferences); | ||||||
|       if Result<>mrOk then exit; |       if Result<>mrOk then exit; | ||||||
|     end; |     end; | ||||||
| 
 | 
 | ||||||
|     // rename identifier |     // rename identifier | ||||||
|     if Options.Rename and Rename then begin |     if Options.Rename and Rename then begin | ||||||
|       if not CodeToolBoss.RenameIdentifier(TreeOfPCodeXYPosition, |       if not CodeToolBoss.RenameIdentifier(PascalReferences, | ||||||
|         Identifier,Options.RenameTo) |         Identifier,Options.RenameTo) | ||||||
|       then begin |       then begin | ||||||
|         DoJumpToCodeToolBossError; |         DoJumpToCodeToolBossError; | ||||||
| @ -12399,7 +12409,8 @@ begin | |||||||
|   finally |   finally | ||||||
|     Files.Free; |     Files.Free; | ||||||
|     OwnerList.Free; |     OwnerList.Free; | ||||||
|     CodeToolBoss.FreeTreeOfPCodeXYPosition(TreeOfPCodeXYPosition); |     CodeToolBoss.FreeTreeOfPCodeXYPosition(FPDocReferences); | ||||||
|  |     CodeToolBoss.FreeTreeOfPCodeXYPosition(PascalReferences); | ||||||
|   end; |   end; | ||||||
| end; | end; | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -177,8 +177,9 @@ type | |||||||
| 
 | 
 | ||||||
|   TStringToStringTree = class |   TStringToStringTree = class | ||||||
|   private |   private | ||||||
|  |     FCompareItems: TListSortCompare; | ||||||
|  |     FCompareNameWithItem: TListSortCompare; | ||||||
|     FItems: TAvgLvlTree; |     FItems: TAvgLvlTree; | ||||||
|     fCaseSensitive: Boolean; |  | ||||||
|     function GetCount: Integer; |     function GetCount: Integer; | ||||||
|     function GetValues(const Name: string): string; |     function GetValues(const Name: string): string; | ||||||
|     procedure SetValues(const Name: string; const AValue: string); |     procedure SetValues(const Name: string; const AValue: string); | ||||||
| @ -186,10 +187,13 @@ type | |||||||
|     function GetNode(Node: TAvgLvlTreeNode; out Name, Value: string): Boolean; |     function GetNode(Node: TAvgLvlTreeNode; out Name, Value: string): Boolean; | ||||||
|   public |   public | ||||||
|     constructor Create(CaseSensitive: boolean); |     constructor Create(CaseSensitive: boolean); | ||||||
|  |     constructor Create(const ACompareItems, ACompareNameWithItem: TListSortCompare); | ||||||
|     destructor Destroy; override; |     destructor Destroy; override; | ||||||
|     procedure Clear; |     procedure Clear; | ||||||
|     function Contains(const Name: string): Boolean; |     function Contains(const Name: string): Boolean; | ||||||
|     procedure Add(const Name, Value, Delimiter: string); |     procedure Add(const Name, Value, Delimiter: string); | ||||||
|  |     procedure AddNameValues(List: TStrings); | ||||||
|  |     procedure AddValues(List: TStrings); | ||||||
|     function GetFirst(out Name, Value: string): Boolean; |     function GetFirst(out Name, Value: string): Boolean; | ||||||
|     function GetLast(out Name, Value: string): Boolean; |     function GetLast(out Name, Value: string): Boolean; | ||||||
|     function GetNext(const Name: string; out NextName, NextValue: string): Boolean; |     function GetNext(const Name: string; out NextName, NextValue: string): Boolean; | ||||||
| @ -197,11 +201,13 @@ type | |||||||
|     property Count: Integer read GetCount; |     property Count: Integer read GetCount; | ||||||
|     property Values[const Name: string]: string read GetValues write SetValues; default; |     property Values[const Name: string]: string read GetValues write SetValues; default; | ||||||
|     property Tree: TAvgLvlTree read FItems; |     property Tree: TAvgLvlTree read FItems; | ||||||
|  |     property CompareItems: TListSortCompare read FCompareItems; | ||||||
|  |     property CompareNameWithItem: TListSortCompare read FCompareNameWithItem; | ||||||
|   end; |   end; | ||||||
| 
 | 
 | ||||||
| function CompareStringToStringItems(Data1, Data2: Pointer): integer; | function CompareStringToStringItems(Data1, Data2: Pointer): integer; | ||||||
| function CompareStringToStringItemsI(Data1, Data2: Pointer): integer; |  | ||||||
| function ComparePAnsiStringWithStrToStrItem(Key, Data: Pointer): Integer; | function ComparePAnsiStringWithStrToStrItem(Key, Data: Pointer): Integer; | ||||||
|  | function CompareStringToStringItemsI(Data1, Data2: Pointer): integer; | ||||||
| function ComparePAnsiStringWithStrToStrItemI(Key, Data: Pointer): Integer; | function ComparePAnsiStringWithStrToStrItemI(Key, Data: Pointer): Integer; | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| @ -1362,10 +1368,7 @@ end; | |||||||
| 
 | 
 | ||||||
| function TStringToStringTree.FindNode(const Name: string): TAvgLvlTreeNode; | function TStringToStringTree.FindNode(const Name: string): TAvgLvlTreeNode; | ||||||
| begin | begin | ||||||
|   if fCaseSensitive then |    Result:=FItems.FindKey(@Name,FCompareNameWithItem); | ||||||
|     Result:=FItems.FindKey(@Name,@ComparePAnsiStringWithStrToStrItem) |  | ||||||
|   else |  | ||||||
|     Result:=FItems.FindKey(@Name,@ComparePAnsiStringWithStrToStrItemI) |  | ||||||
| end; | end; | ||||||
| 
 | 
 | ||||||
| function TStringToStringTree.GetNode(Node: TAvgLvlTreeNode; | function TStringToStringTree.GetNode(Node: TAvgLvlTreeNode; | ||||||
| @ -1387,11 +1390,18 @@ end; | |||||||
| 
 | 
 | ||||||
| constructor TStringToStringTree.Create(CaseSensitive: boolean); | constructor TStringToStringTree.Create(CaseSensitive: boolean); | ||||||
| begin | begin | ||||||
|   fCaseSensitive:=CaseSensitive; |   if CaseSensitive then | ||||||
|   if fCaseSensitive then |     Create(@CompareStringToStringItems,@ComparePAnsiStringWithStrToStrItem) | ||||||
|     FItems:=TAvgLvlTree.Create(@CompareStringToStringItems) |  | ||||||
|   else |   else | ||||||
|     FItems:=TAvgLvlTree.Create(@CompareStringToStringItemsI); |     Create(@CompareStringToStringItemsI,@ComparePAnsiStringWithStrToStrItemI); | ||||||
|  | end; | ||||||
|  | 
 | ||||||
|  | constructor TStringToStringTree.Create(const ACompareItems, | ||||||
|  |   ACompareNameWithItem: TListSortCompare); | ||||||
|  | begin | ||||||
|  |   FCompareItems:=ACompareItems; | ||||||
|  |   FCompareNameWithItem:=ACompareNameWithItem; | ||||||
|  |   FItems:=TAvgLvlTree.Create(FCompareItems); | ||||||
| end; | end; | ||||||
| 
 | 
 | ||||||
| destructor TStringToStringTree.Destroy; | destructor TStringToStringTree.Destroy; | ||||||
| @ -1431,6 +1441,22 @@ begin | |||||||
|   Values[Name]:=OldValue; |   Values[Name]:=OldValue; | ||||||
| end; | end; | ||||||
| 
 | 
 | ||||||
|  | procedure TStringToStringTree.AddNameValues(List: TStrings); | ||||||
|  | var | ||||||
|  |   i: Integer; | ||||||
|  | begin | ||||||
|  |   for i:=0 to List.Count-1 do | ||||||
|  |     Values[List.Names[i]]:=List.ValueFromIndex[i]; | ||||||
|  | end; | ||||||
|  | 
 | ||||||
|  | procedure TStringToStringTree.AddValues(List: TStrings); | ||||||
|  | var | ||||||
|  |   i: Integer; | ||||||
|  | begin | ||||||
|  |   for i:=0 to List.Count-1 do | ||||||
|  |     Values[List[i]]:=''; | ||||||
|  | end; | ||||||
|  | 
 | ||||||
| function TStringToStringTree.GetFirst(out Name, Value: string): Boolean; | function TStringToStringTree.GetFirst(out Name, Value: string): Boolean; | ||||||
| begin | begin | ||||||
|   Result:=GetNode(Tree.FindLowest,Name,Value); |   Result:=GetNode(Tree.FindLowest,Name,Value); | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 mattias
						mattias