Dodanie kolejnych linii do Tstringlist po znalezieniu pierwszej

0

Witam mam problem z podstawami.

Przykładowy tekst w pliku:

saba
baba << to
tata
mama
osioł
lew
lala
kira

i chodzi mi o to, ze che po znalezieniu baba dodać kolejnych pięciu linii po znalezieniu pierwszej do sl czyli od baba do lew. Pierwsza mam a pozostałe jak dodać ?

var
  myFile : TextFile;
  text, s   : string;
  sl := TStringList;
begin
  s := 'baba';
  
  sl := TStringList.Create;

  AssignFile(myFile, 'Dane.txt');

  Reset(myFile);

  while not Eof(myFile) do
  begin
    ReadLn(myFile, text);
    if pos(s, text) > 0 then
    sl.Add(text);
  end;

  sl.Free;
  CloseFile(myFile);
end;
2
... then
begin
    for I:=1 to 5 do
    begin
      sl.Add(text);
      ReadLn(myFile,text);
    end;
end;
1

nie bardzo kumam - jak chcesz coś dodać w środku listy to masz insert a nie add

0

_13th_Dragon działa super. Dziękuję bardzo :)

0

A mam pytanie jak odwrócić sytuację i znaleźć od słowa baba słowa 3 wstecz ?

0
var myFile:TextFile;
var text:String;
var tb:array[0..2]of String;
var p,i:Integer;
const find:String='baba';
begin
  AssignFile(myFile,'Dane.txt'); 
  Reset(myFile); 
  while not Eof(myFile) do
  begin
    ReadLn(myFile,text);
    if pos(find,text)=1 then for i:=0 to 2 do WriteLn(tb[(p+i)mod(3)]); 
    tb[p]=text;
    p=(p+1)mod(3);
  end;
  CloseFile(myFile);
end;

1 użytkowników online, w tym zalogowanych: 0, gości: 1