see code
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
StdCtrls;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
words: array of string;
end;
var
Form1: TForm1;
implementation
{ TForm1 }
procedure TForm1.Button1Click(Sender: TObject);
begin
SetLength(words ,5);
words[0] := 'hello';
words[1] := 'how';
words[2] := 'are';
words[3] := 'you';
words[4] := 'today';
end;
procedure TForm1.Button2Click(Sender: TObject);
var
arrayfree : integer;
begin
for arrayfree:=Low(words) to High(words) do
words[arrayfree].free; //errors on this command
end;
initialization
{$I unit1.lrs}
end.
should I just use setlength?? this works for dynamically created object and freeing them but I can't free my arrays of strings