OpenDialog working in a loop
How to process multiple files by opening them via OpenDialog. Added to the code:
OpenDialog1.Options := OpenDialog1.Options + [ofAllowMultiSelect];
if OpenDialog1.Execute then
And after:
procedure Tfrm_Main.Button1Click(Sender: TObject);
const
x: byte = 16;
bufsize = 1024;
var
f1, f2: File;
buf: array [1 .. bufsize] of byte;
i, count: integer;
begin
OpenDialog1.Options := OpenDialog1.Options + [ofAllowMultiSelect]; // Выбор несколько файлов...
if OpenDialog1.Execute then
begin
assignfile(f1, 'in.txt'); ///////////////// Вот тут понимаю что нужно в цикле но как?
assignfile(f2, 'out.txt');//////////////// Вот тут понимаю что нужно в цикле но как?
reset(f1, 1);
rewrite(f2, 1);
while not eof(f1) do
begin
BlockRead(f1, buf, bufsize, count);
for i := 1 to count do
buf[i] := buf[i] xor x;
BlockWrite(f2, buf, count);
end;
closefile(f1);
closefile(f2);
end;
end;
Now what you need to write here:
assignfile(f1, 'in.txt'); // Входящий файл
assignfile(f2, 'out.txt'); // исходящий
I assume that in a loop or array ? what is the correct way to do it ? Or maybe:
If OpenDialog1.Execute Then
For i := 0 to OpenDialog1.Files.Count-1 do
begin
CurrentFile := OpenDialog1.Files.Strings[i];
Где CurrentFile: array of string; /////////////////
I do not understand how to correctly ?.
1
1 answers
if OpenDialog1.Execute then
begin
for i := 0 to OpenDialog1.Files.Count - 1 do
begin
AssignFile(f1, OpenDialog1.Files[i]);
AssignFile(f2, 'out' + IntToStr(i + 1) + '.txt');
Reset(f1, 1);
Rewrite(f2, 1);
...
CloseFile(f1);
CloseFile(f2);
end;
end;
2
Author: Igor, 2020-04-19 21:41:12