Salut,
Si j'ai bien compris...
Je dirai en modifiant un peu comme ça...
procedure SearchVal(ADirFil, AVal1, AVal2: string; AListView: TListView);
var
ListS : TStringList;
ListW : TStringList;
I,J : Integer;
begin
ListS := TStringList.Create;
ListW := TStringList.Create;
try
ListS.LoadFromFile(ADirFil);
for I := 0 to ListS.Count - 1 do
begin
ListW.CommaText := ListS[I];
for J := 0 to ListW.Count - 1 do
begin
if ListW.Count > 2 then
begin
if (ListW[2] = AVal1) and (ListW[3] = AVal2) then
if (J = 0) or (J = 1) then
AListView.Items[AListView.Items.Count-1].SubItems.Add(ListW[J]);
if (ListW[2] = 'G3') and (J = 2) and (AListView.Items[AListView.Items.Count-1].SubItems.Count = 3) then
begin
ListW.CommaText := ListS[I+1];
AListView.Items[AListView.Items.Count-1].SubItems.Add(ListW[J]);
end;
end;
end;
end;
finally
ListS.Free;
ListW.Free;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
Const
Tab : array [0..3] of string = ('VAR3','CAB1','CAB2','G3');
var
S,W: TStringList;
I,J: Integer;
NewColumn: TListColumn;
begin
ListView1.ViewStyle := vsReport;
for I := 1 to 5 do
begin
NewColumn := ListView1.Columns.Add;
NewColumn.Caption := Format('Col %d',[I]);
end;
ListView1.Items.Add;
ListView1.Items[ListView1.Items.Count-1].Caption := 'CAB';
for I := 0 to High(Tab) do
ListView1.Items[ListView1.Items.Count-1].SubItems.Add(Tab[I]);
S := TStringList.Create;
W := TStringList.Create;
try
S.LoadFromFile(ExtractFilePath(Application.ExeName)+'Test.txt');
for I := 0 to S.Count - 1 do
begin
W.CommaText := S[I];
for J := 0 to W.Count - 1 do
begin
if W.Count > 3 then
begin
if (Pos('BB-',W[3]) <> 0) or (Pos('CC-',W[3]) <> 0) then
begin
if J = 0 then
begin
ListView1.Items.Add;
ListView1.Items[ListView1.Items.Count-1].Caption := W[J];
end;
if J = 3 then
begin
ListView1.Items[ListView1.Items.Count-1].SubItems.Add(W[J]);
if (Pos('BB-',W[3]) <> 0) then
SearchVal(ExtractFilePath(Application.ExeName)+'Test2.txt',Copy(W[3], 0, Pos('-',W[3])-1),Copy(W[3], Pos('-',W[3])+1, Length(W[3])), ListView1);
if (Pos('CC-',W[3]) <> 0) then
SearchVal(ExtractFilePath(Application.ExeName)+'Test2.txt',Copy(W[3], 0, Pos('-',W[3])-1),Copy(W[3], Pos('-',W[3])+1, Length(W[3])), ListView1);
end;
end;
end;
end;
end;
finally
S.Free;
W.Free;
end;
end;
@+