Tell me, good people, how can I solve such a task in Delphi, I want to shorten the code if of course as possible as I want
My task in the loop is to create 21 files in one loop, and not to write a bunch of duplicate code like for example below
Example:
Assignfile(AFile, ExtractFilePath(Application.ExeName)+'@a.txt'); Rewrite(AFile); Closefile(AFile); Assignfile(BFile, ExtractFilePath(Application.ExeName)+'@b.txt'); Rewrite(BFile); Closefile(BFile); .... the decision was such
var Tfile: array [0..21] of TextFile; //ΡΠΎΠ·Π΄Π°Π½ΠΈΠ΅ ΠΌΠ°ΡΡΠΈΠ²Π° Π΄Π»Ρ ΡΠΎΠ·Π΄Π°Π½ΠΈΠ΅ ΡΠ°ΠΉΠ»ΠΎΠ² A: array [0..21] of string; // ΡΠΎΠ·Π΄Π°Π½ΠΈΠ΅ ΠΌΠ°ΡΡΠΈΠ²Π° Π΄Π»Ρ ΠΈΠΌΠ΅Π½ ΡΠ°ΠΉΠ»ΠΎΠ² //Π·Π°ΠΏΠΎΠ»Π½Π΅Π½ΠΈΠ΅ ΠΌΠ°ΡΡΠΈΠ²Π° ΠΈΠΌΠ΅Π½Π°ΠΌΠΈ procedure TForm1.FormCreate(Sender: TObject); begin A[0] := '@a'; A[1] := '@b'; end; //ΡΠΎΠ·Π΄Π°Π½ΠΈΠ΅ ΡΠ°ΠΉΠ»ΠΎΠ² Ρ Π½ΡΠΆΠ½ΡΠΌΠΈ ΠΈΠΌΠ΅Π½Π°ΠΌΠΈ<br> procedure TForm1.StartClick(Sender: TObject); var j: integer; begin for j := 0 to 20 do begin Assignfile(Tfile[j], ExtractFilePath(Application.ExeName)+ A[j] + '.txt'); Rewrite(Tfile[j]); Closefile(Tfile[j]); end; end; now to the problem how to write data to the created files now
Append(Tfile[A]); Writeln(Tfile[A],Filez.Strings[num_theards]); Closefile(Tfile[A]); I understand that there should be a string, and I pass the index and the types are not compatible with the array string, how can I solve this?