unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, wincrt, Process, Forms, Controls, Graphics, Dialogs, StdCtrls;
type
grouper = array of string;
{ TForm1 }
TForm1 = class(TForm)
Button13: TButton;
procedure Button13Click(Sender: TObject); //Writes to array, reads from the array and writes to a text file.
procedure readline(filename:string; var textstr:string); //Read one line from one of four simulated text files (array).
procedure writeline(filename:string;textstr:string); //Write one line to one of four simulated text files (array).
var
arraycount1,arraycout2,arraycout3,arraycout4:integer; //Each counter goes with a particular array (simulated text file).
simtextfile1,simtextfile2,simtextfile3,simtextfile4:grouper; //Four simulated text files.
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.Button13Click(Sender: TObject);
var i:integer;
filename1,tempstr:string;
writefile:TextFile;
begin
setlength(simtextfile1,6);
arraycount1 := 0; //arraycount1 is associated with simtextfile1 etc.
filename1 := 'simtextfile1';
//Write seven lines of text into the array. Each element of the array represents a line of string text.
writeline(filename1,'Four'); //Write a line using the procedure "writeline".
writeline(filename1,'score');
writeline(filename1,'and');
writeline(filename1,'seven');
writeline(filename1,'years');
writeline(filename1,'ago');
//Set the counter back to zero so as to read the first line in the array "simtextfile1"..
arraycount1 := 0;
assignfile(writefile,'testfile.txt');
rewrite(writefile);
//Read six lines from an array (simulated text file) and write those same six lines to a test text file.
readline(filename1,tempstr);
writeln(writefile,tempstr);
readline(filename1,tempstr);
writeln(writefile,tempstr);
readline(filename1,tempstr);
writeln(writefile,tempstr);
readline(filename1,tempstr);
writeln(writefile,tempstr);
readline(filename1,tempstr);
writeln(writefile,tempstr);
readline(filename1,tempstr);
writeln(writefile,tempstr);
closefile(writefile);
setlength(simtextfile1,0); //Shut down the array and return its memory to the system.
sound(350);
end;
procedure TForm1.readline(filename:string; var textstr:string);
var tempcount:integer;
begin
if filename = 'simtextfile1' then
begin
arraycount1 := arraycount1 + 1;
tempcount := arraycount1 - 1;
textstr := simtextfile1[tempcount];
end;
if filename = 'simtextfile2' then
begin
arraycount2 := arraycount2 + 1;
tempcount := arraycount2 - 1;
textstr := simtextfile2[tempcount];
end;
if filename = 'simtextfile3' then
begin
arraycount3 := arraycount3 + 1;
tempcount := arraycount3 - 1;
textstr := simtextfile3[tempcount];
end;
if filename = 'simtextfile4' then
begin
arraycount4 := arraycount4 + 1;
tempcount := arraycount4 - 1;
textstr := simtextfile4[tempcount];
end;
end;
procedure TForm1.writeline(filename:string;textstr:string);
var tempcount:integer;
begin
if filename = 'simtextfile1' then
begin
arraycount1 := arraycount1 + 1;
tempcount := arraycount1 - 1;
simtextfile1[tempcount] := textstr;
end;
if filename = 'simtextfile2' then
begin
arraycount2 := arraycount2 + 1;
tempcount := arraycount2 - 1;
simtextfile2[tempcount] := textstr;
end;
if filename = 'simtextfile3' then
begin
arraycount3 := arraycount3 + 1;
tempcount := arraycount3 - 1;
simtextfile3[tempcount] := textstr;
end;
if filename = 'simtextfile4' then
begin
arraycount4 := arraycount4 + 1;
tempcount := arraycount4 - 1;
simtextfile4[tempcount] := textstr;
end;
end;
end.