From 453bbc4ddb7b3108893b2a93891ab8df36c0aed0 Mon Sep 17 00:00:00 2001 From: skalogryz Date: Fri, 25 Mar 2016 03:50:21 +0000 Subject: [PATCH] iphonelazext: skip IDs that are already in use, when writeing pbx container file git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@4593 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- components/iphonelazext/pbx/pbxcontainer.pas | 34 ++++++++++++++++---- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/components/iphonelazext/pbx/pbxcontainer.pas b/components/iphonelazext/pbx/pbxcontainer.pas index 4c2791ab5..81dcb9f01 100644 --- a/components/iphonelazext/pbx/pbxcontainer.pas +++ b/components/iphonelazext/pbx/pbxcontainer.pas @@ -748,21 +748,41 @@ begin end; end; +function GetNextID(hash: TFPHashObjectList; var id: Int64): string; +begin + repeat + Result:=IntToHex(id, 24); + inc(id); + until not Assigned(hash.Find(Result)); +end; + + procedure PBXAssignRef(list: TList); var i : Integer; p : PBXObject; id: Int64; + usedid: TFPHashObjectList; begin if not Assigned(list) then Exit; - id:=2; // root! :) - for i:=0 to list.Count-1 do begin - p:=PBXObject(list[i]); - if not Assigned(p) then Continue; - if (p._id='') then begin - p._id:=IntToHex(id, 24); - inc(id); + usedid:=TFPHashObjectList.Create(false); + try + for i:=0 to list.Count-1 do begin + p:=PBXObject(list[i]); + if p._id<>'' then usedid.Add(p._id, p);; end; + + + id:=2; // root! :) + for i:=0 to list.Count-1 do begin + p:=PBXObject(list[i]); + if not Assigned(p) then Continue; + if (p._id='') then begin + p._id:=GetNextID(usedid, id); + end; + end; + finally + usedid.Free; end; // 0AFA6EA519F60EFD004C8FD9 // 123456789012345678901234