It is necessary to alter - ready code for reading line by line, using - Readln / Writeln. In order not to load all files into memory ...

procedure multiplyStrings(src1, src2, dst: TStrings); var i, j: integer; begin dst.Clear; for i := 0 to src1.Count - 1 do begin for j := 0 to src2.Count - 1 do begin dst.Add(src1[i] + ';' + src2[j]); end; end; end; var lines1, lines2, destination: TStringList; begin lines1 := TStringList.Create; try lines2 := TStringList.Create; try lines1.LoadFromFile('первый файл'); lines2.LoadFromFile('второй файл'); destination := TStringList.Create; try // Вариант первый multiplyStrings(lines1, lines2, destination); // Вариант второй multiplyStrings(lines2, lines1, destination); destination.SaveToFile('новый файл'); finally destination.Fre; end; finally lines2.Free; end; finally lines1.Free; end; end; 

I do this (but I can’t do it completely):

 procedure TForm1.Button18Click(Sender: TObject); var f1,f2,f3:TextFile; s,str:string; i:integer; begin if OpenDialog1.Execute then begin AssignFile(f1,OpenDialog1.FileName); Reset(f1); if OpenDialog2.Execute then begin AssignFile(f2,OpenDialog2.FileName); Reset(f2); AssignFile(f3, '\Save.txt'); Rewrite(f3); while not Eof(f1) do begin Readln(f1,s); Readln(f2,str); /// и тут не знаю как цикл переделать как в коде что выше.....? Writeln(f3,s); end; CloseFile(f1); CloseFile(f2); CloseFile(f3); end; end; end; 
  • @Igor, Created a new topic ... - Denis
  • one
    Did you try to do anything other than copying someone else's code? - Vladimir Klykov
  • @Vladimir Klykov, Tried, simply, a month I started learning Delphi. And it is very hard, so far given. - Denis
  • one
    AND..? result? You copied a line to a line from the last request .... Is that all you learned in a month? Opening a file - AssignFile or FileOpen Both methods allow you to read a text file line by line, how to make a loop - there is a code from the question. think a little bit yourself, and afterwards go ask the site - Vladimir Klykov
  • 2
    If the source files are difficult to load into memory, they are of the order of a gigabyte and contain about 10-100 million lines. And the result will contain a quadrillion lines ... It's not too late to stop;) - MBo

2 answers 2

 if OpenDialog1.Execute and OpenDialog2.Execute then begin AssignFile(f1,OpenDialog1.FileName); AssignFile(f2,OpenDialog2.FileName); AssignFile(f3, '\Save.txt'); Rewrite(f3); Reset(f1); while not EOF(f1) do begin ReadLn(f1, s1); Reset(f2); while not EOF(f2) do begin ReadLn(f2, s2); WriteLn(f3, s1 + ';' + s2); // или WriteLn(f3, s2 + ';' + s1); end; CloseFile(f2); end; CloseFile(f1); CloseFile(f3); end; 
  • I do not pretend to the truth, but does ReadLn work as indicated? s1 := ReadLn(f1); to mine (if memory does not change) you will have in s1 or the number of characters read will go away or the result (True \ False) - Vladimir Klykov
  • @ VladimirKlykov yes, you are right. This is generally a procedure. - Igor
  • @Igor, So in this case, the code does not match the condition as in your code (I specifically created a new topic for this): Here is the old topic. ? noredirect = 1 # comment1511106_916910 - Denis
  • @Igor maybe, I didn’t pretend to the truth, I haven’t read files in such a way for a long time, mostly file streams)) - Vladimir Klykov
  • @Denis Hmm, well, change the s1 and s2 places in WriteLn(f3, s1 + ';' + s2); . - Igor
 while not Eof(f1) do begin Readln(f1,s); while not Eof(f2) do Begin Readln(f2,str); str:=s+';'+str; Writeln(f3,str); end; reset(f2); end; 
  • This I know, I just meant that the cycle does not meet the condition: ru.stackoverflow.com/questions/916892/ Gluing - lines -in- two - options / 916910?noredirect=1#comment1511106_916910 - Denis
  • Did you watch the code? the output will be exactly the same as in the first example in the previous question =) Replace the loop in your code, see this result and see - Vladimir Klykov
  • Thanks, it turned out, I still have to learn and teach ... - Denis