If you can sort the data (Turbo powers SysTools has a good sort routine which works well) then you can do this in code fairly quickly with two input lists and an output list. The concept behind this is simple:
- Take two lists, sorted in the same manner
- If the left side is less than the right side, then the right side is missing that value so add it to your "missing list" and increment the cursor for the left side.
- If they are equal, then increment both,
- If the right side is less than the left side, then only increment the right side (optionally add to the "must delete" list).
This process is sometimes refered to as the "Old Master/New Master" process and is extremely fast as your only walking both lists once.
Simple example:
var
ListL : tStringList; // the left list
ListR : tSTringList; // the right list
ListA : tSTringList; // the Add List (should start empty)
ListD : tStringList; // the Delete list (should start empty)
iCurL : integer; // Left Cursor
iCurR : integer; // Right Cursor
iRes : integer; // result of compare
begin
iCurL := 0;
iCurR := 0;
ListL := tStringList.create;
ListR := tSTringList.create;
ListA := tSTringList.create;
ListD := tStringList.create;
InitAndLoadLists(ListL,ListR,ListA,ListD);
while (iCurL <= ListL.Count-1) and (iCurR <= ListR.Count-1) do
begin
iRes := CompareStr(ListL.Strings[iCurL],ListR.Strings[iCurR]);
if iRes = 0 then
begin
inc(iCurL);
inc(iCurR);
end;
if iRes < 0 then
begin
ListA.Add(ListL.Strings[iCurL]);
inc(iCurL);
end;
if iRes > 0 then
begin
listD.Add(ListR.Strings[iCurR]);
inc(iCurR);
end;
end;
while (iCurL <= ListL.Count-1) do
begin
listA.Add(ListL.Strings[iCurL]);
inc(iCurL);
end;
while (iCurR <= ListR.Count-1) do
begin
listD.Add(ListR.Strings[iCurR]);
inc(iCurR);
end;
ShowMessage( 'ADDS' + ^M+^J + ListA.Text);
ShowMessage( 'DELS' + ^M+^J + ListD.Text);
end;
The following code is what I used for testing. This is just an example, but in a real world situation I would build my keys so that they would sort properly, right padding numbers, and forcing case where appropriate. If your using the turbo power sort routines, you can use TWO sorts instead of two lists, but the end effect is the same.
procedure InitAndLoadLists(ListL, ListR, ListA, ListD: TStringList);
begin
ListL.Add('A,1');
ListL.Add('B,3');
ListL.Add('C,2');
ListR.Add('A,2');
ListR.Add('B,3');
ListR.Add('C,4');
end;
Edit: Code tested in Delphi 2009 and behaves properly.