unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls;
const max_size=100000;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
private
public
end;
var
Form1: TForm1;
Ar:array of array of byte;
a,b:longint; // use longint to index the array not Integer
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.Button1Click(Sender: TObject);
const rat=100;
begin
// Diable button to stop you pressing it twice
button1.enabled:=false;
application.ProcessMessages;
//for loop below is to show visual indication the program is working, as without some indication user may assume application has crashed
//if you check application processes you should see the memory used increasing
for a:=1 to max_size div rat do
begin
label1.caption:='setting length of array to :'+inttostr(a*rat);
SetLength(ar, a*rat, max_size);//a*rat);
application.ProcessMessages;
end;
SetLength(ar, max_size+1, max_size+1);
// Setting length to max+1 so that you can address all elements of array, as without I was getting sigsev error when indexing elements at max_size
// Loop through array and set all elements of 2 D array to 255
for a:=0 to max_size do
begin
for b:=0 to max_size do
begin
ar[a,b]:=255;
end;
label1.caption:=inttostr(a);
application.ProcessMessages;
end;
button1.Enabled:=true; // Re-enable button
application.ProcessMessages;
end;
end.