I have two StringList
that are loaded (from a file) with users and users + password respectivally. I'm comparing these lists to determine what user (of first list) already have a password (in second list) and then insert on ListView
who have and also who still not have.
But exists a problem here that from second ListItem.Caption
(user) is repeting two times.
How i can solve this?
My files that are loaded on lists are:
users.dat
- User01
- User02
- User03
logins.dat
- User01|test01
- User01|test01
And this was my last attempt of code:
type
TForm1 = class(TForm)
Button1: TButton;
ListView1: TListView;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
L1, L2, LSplit: TStringList;
L: TListItem;
I, J: Integer;
begin
L1 := TStringList.Create;
L2 := TStringList.Create;
LSplit := TStringList.Create;
L1.LoadFromFile('users.dat');
L2.LoadFromFile('logins.dat');
for I := 0 to L1.Count - 1 do
begin
for J := 0 to L2.Count - 1 do
begin
LSplit.Clear;
ExtractStrings(['|'], [], PChar(L2[J]), LSplit);
if L1[I] = LSplit[0] then
begin
L := ListView1.Items.Add;
L.Caption := LSplit[0];
L.SubItems.Add(LSplit[1]);
Break;
end;
L := ListView1.Items.Add;
L.Caption := L1[I];
end;
end;
L1.Free;
L2.Free;
LSplit.Free;
end;
end.