I'm trying to compare 2 stringlist by substring search, and match the found items into another stringlist.
"Stringlist_SCSILogicalUnit" contains data like:
SCSIBus=0;SCSILogicalUnit=0;SCSIPort=1;SCSITargetId=0;Status=OK
SCSIBus=0;SCSILogicalUnit=1;SCSIPort=2;SCSITargetId=0;Status=OK
SCSIBus=0;SCSILogicalUnit=2;SCSIPort=2;SCSITargetId=0;Status=OK
SCSIBus=0;SCSILogicalUnit=3;SCSIPort=2;SCSITargetId=0;Status=OK
SCSIBus=0;SCSILogicalUnit=4;SCSIPort=2;SCSITargetId=0;Status=OK
SCSIBus=0;SCSILogicalUnit=43;SCSIPort=2;SCSITargetId=0;Status=OK
SCSIBus=0;SCSILogicalUnit=44;SCSIPort=2;SCSITargetId=0;Status=OK
SCSIBus=0;SCSILogicalUnit=45;SCSIPort=2;SCSITargetId=0;Status=OK
SCSIBus=0;SCSILogicalUnit=46;SCSIPort=2;SCSITargetId=0;Status=OK
"Stringlist_LUN" contains data like:
LocationInformation REG_SZ Port(2,2,3,3) Bus 0, Target ID 0, LUN 67
;
LocationInformation REG_SZ Port(2,2,3,3) Bus 0, Target ID 0, LUN 43
;
LocationInformation REG_SZ Port(2,2,3,3) Bus 0, Target ID 0, LUN 44
;
LocationInformation REG_SZ Port(2,2,3,3) Bus 0, Target ID 0, LUN 45
;
LocationInformation REG_SZ Port(2,2,3,3) Bus 0, Target ID 0, LUN 50
;
LocationInformation REG_SZ Port(2,2,3,3) Bus 0, Target ID 0, LUN 51
;
I need to match the corespondence between "LUN" value and "SCSILogicalUnit" value (LUN and SCSILogicalUnit have the same value Lun=SCSILogicalUnit)so that the result can be listen in "Stringlist_result". The result shoud look like
"SCSIBus=0;SCSILogicalUnit=46;SCSIPort=2;SCSITargetId=0;Status=OK =>>> LocationInformation REG_SZ Port(2,2,3,3) Bus 0, Target ID 0, LUN 46
;"
I'm using the following function but the result is not consistent:
function stringlist_mmg_FastJoin(List1, List2: TStringList): TStringList;
var
L1Idx, L2Idx,
L1Max, L2Max: Integer;
v: Integer;
begin
// Create Result list, set it's min size
Result := TStringList.Create;
Result.Capacity := Max(List1.Count, List2.Count);
// limits
L1Idx := 0;
L2Idx := 0;
L1Max := List1.Count;
L2Max := List2.Count;
// forse sort
List1.Sorted := True;
List2.Sorted := True;
// iterate
while (L1Idx<L1Max) and (L2Idx<L2Max) do
begin
if pos(extracttextbetween(List1[L1idx],'SCSILogicalUnit=',';'),List2[L2idx])>1 then
begin
Result.Add(List1[L1Idx]+' = '+List2[L2idx]);
Inc(L1Idx);
Inc(L2Idx);
end
else if v < 0 then // Add from List 1
begin
//Result.Add(List1[L1Idx]);
Inc(L1Idx);
end
else // v > 0 // Add from List 2
begin
//Result.Add(List2[L2Idx]);
Inc(L2Idx);
end;
end;
// Add all remainders from second list
while L2Idx < L2Max do
begin
//Result.Add(List2[L2Idx]);
Inc(L2Idx);
end;
end;
stringlist_resultat:=Tstringlist.create;
stringlist_rezultat.addstrings(stringlist_mmg_FastJoin(Stringlist_SCSILogicalUnit,stringlist_LUN));
The result shoud be:
PNPDeviceID=MPIOSCSIBus=0;SCSILogicalUnit=67;SCSIPort=2;SCSITargetId=0;Status=OK =>>> LocationInformation REG_SZ Port(2,2,3,3) Bus 0, Target ID 0, LUN 67
;
When I run the function I get a sigle result.
Could someone please tell what am I doing wrong? Can this task be obtimized without a stringlist?
Thank you!