I would like to create a program (learning Delphi) that takes 3 different list (from TEdit)
- A list of names
- A list of names to ignore when searching first list
- A list of names to ignore when searching first list
By taking the 3 TEdit and converting the text to TStringList and seperating (I am so far okay with this).
I want to output the first name (or item) of the first list that is neither on 2nd or 3rd list
procedure TForm1.Button1Click(Sender: TObject);
var
i, j ,k : integer;
begin
list := TStringList.Create;
ignoreListFirst := TStringList.Create;
ignoreListSecond := TStringList.Create;
list.Delimiter := ',';
ignoreListFirst.Delimiter := ',';
ignoreListSecond.Delimiter := ',';
list.DelimitedText := EditList.Text;
ignoreListFirst.DelimitedText := EditIgnoreList1.Text;
ignoreListSecond.DelimitedText := EditIgnoreList2.Text;
for k := 0 to list.Count - 1 do
begin
for i := 0 to ignoreListFirst.Count - 1 do
begin
for j := 0 to ignoreListSecond.Count - 1 do
begin
if (list[k] <> ignoreListFirst[i]) and (list[k] <> ignoreListSecond[k]) then
EditResult.Text := list[k];
break;
end;
end;
end;
list.Free;
ignoreListFirst.Free;
ignoreListSecond.Free;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
EditList.Text := 'Katy,Mary,John,Maggie,Carl';
EditIgnoreList1.Text := 'Katy,Mary,John';
EditIgnoreList2.Text := 'John,Carl';
end;
Tried swapping the loop order to see if I can pinpoint the problem.
first list in last loop give me no errors and produces the name 'Katy' which is yes, the first on the list but ignored.
Swapped the the first list to be first loop. produces 'Mary' which I guess ignored (which I wanted) Katy but not others from what I can see.
In this example (which does not work) I want it to result 'Maggie' which is not on either ignore lists.
Thanks and sorry if I explained this wrong. Learning Delphi. Do pinpoint any mistakes.
jnever exceeds0.Begin....End;block use the debugger to follow the error. The if statement is not doing what you think it does.