Write Random Numbers procedure
Delphi
procedure WriteRandom(const Size,Count:integer;
                      const filename: string);
  var RandomFile: TextFile;
      J: integer;
begin
  AssignFile(RandomFile, filename);
  Rewrite(RandomFile);
  Randomize;
  for J := 1 to Count do
    Writeln(RandomFile, Random(Size));
  CloseFile(RandomFile);
end;//WriteRandom
 

C++Builder
void WriteRandom(int Size, int Count, char* filename)
  { fstream RandomFile;
    int J;
    RandomFile.open(filename, ios::out);
    Randomize();
    for (J = 1; J <= Count; J++)
      { RandomFile << random(Size) << endl; }
    RandomFile.close();
  } // end WriteRandom
 

Write Random Numbers button click
Delphi
procedure TInsertSortForm.WriteButtonClick(Sender: TObject);
  var NumberSize, NumberCount: integer;
begin
  if SaveDialog.execute then
    begin
      try
         NumberSize := StrToInt(SizeEdit.text)
      except
        NumberSize := 1000
      end;

      try
        NumberCount := StrToInt(CountEdit.text)
      except
        NumberCount := 100
      end;

      WriteRandom(NumberSize, NumberCount, SaveDialog.filename);
    end; // if SaveDialog
end; // TInsertSortForm.WriteButtonClick
 

C++Builder
void __fastcall TInsertSortForm::WriteButtonClick(TObject *Sender)
  { int NumberSize;
    int NumberCount;
    if (SaveDialog->Execute())
      { try
          {NumberSize = StrToInt(SizeEdit -> Text);}
        catch (...)
          {NumberSize = 1000;}

        try
          {NumberCount = StrToInt(CountEdit -> Text);}
        catch (...)
          {NumberCount = 100;}

        WriteRandom(NumberSize, NumberCount, (SaveDialog -> FileName).c_str());
      } // end if(SaveDialog ...
  } // end TInsertSortForm::WriteButtonClick
 
 

Write Array Procedure
Delphi
Procedure WriteArray(const IntArray: array of integer;
                     const Count: integer;
                     const filename: string);
  var ArrayFile: TextFile;
  J: integer;
begin
  AssignFile(ArrayFile, filename);
  Rewrite(ArrayFile);
    For J := 0 to Count-1 do
      Writeln(ArrayFile, IntArray[J]);
  CloseFile(ArrayFile);
end; //WriteArray
 

C++Builder
void WriteArray(int IntArray[], int Count, char* filename)
  { fstream ArrayFile;
    int J;
    ArrayFile.open(filename, ios::out);
    for (J = 0; J < Count; J++)
      { ArrayFile << IntArray[J] << endl; }
    ArrayFile.close();
  } // end WriteArray
 

Read Array Procedure
Delphi
Procedure ReadArray(var IntArray: array of integer;
                    var Count: integer;
                    const filename: string);
  var ArrayFile: TextFile;
begin
  AssignFile(ArrayFile, filename);
  Reset(ArrayFile);
  Count := 0;
  while not eof(ArrayFile) do
    begin
    Readln(ArrayFile, IntArray[Count]);
    inc(Count);
    end;
  CloseFile(ArrayFile);
end; //ReadArray
 

C++Builder
void ReadArray(int IntArray[], int& Count, char* filename)
  { fstream ArrayFile;
    ArrayFile.open(filename, ios::in);
    Count = 0;
    while (! ArrayFile.eof())
      { ArrayFile >> IntArray[Count];
        Count++; }
    ArrayFile.close();
    Count--;
  } // end ReadArray
 
 

Sort Array Procedure
Delphi
Procedure SortArray(var IntArray: array of integer;
                    const Count: integer);
  var pass, K: integer;
      temp: integer;
begin
for pass := 1 to Count-1 do
  begin
  K := pass;
  temp := IntArray[K];
  while (K > 0) and (temp < IntArray[K-1]) do
    begin
    IntArray[K] := IntArray[K-1];
    dec(K);
    end; // while
  IntArray[K] := temp;
  end; // for
end; // SortArray
 

Sort Button Click
Delphi
procedure TInsertSortForm.SortButtonClick(Sender: TObject);
  var A: Array [0..9999] of integer;
      Count: integer;
begin
  If OpenDialog.execute then
    begin
    ReadArray(A, Count, OpenDialog.filename);
    SortArray(A, Count);
    WriteArray(A, Count, OpenDialog.filename);
    end;
end; // TInsertSortForm.SortButtonClick
 

C++Builder
void __fastcall TInsertSortForm::SortButtonClick(TObject *Sender)
{ int A[10000];
  int Count;
  if (OpenDialog -> Execute())
    { ReadArray(A, Count, (OpenDialog -> FileName).c_str());
      SortArray(A, Count);
      WriteArray(A, Count, (OpenDialog -> FileName).c_str());
    }
}  // end TInsertSortForm::SortButtonClick

Display Button Click
Delphi
procedure TInsertSortForm.DisplayButtonClick(Sender: TObject);
begin
if OpenDialog.execute then
  DisplayMemo.lines.LoadFromFile(OpenDialog.filename);
end; // TInsertSortForm.DisplayButtonClick