Board index » delphi » Memo array raises exception

Memo array raises exception

  The following ('Memo[4].Lines.Add('This stupid thing!')') is causing
an exception error:

Project Project1.exe raised exception class EAccessViolation with
message 'Access violation at address 00447F45 in module
'PROJECT1.EXE'...

Memo : ARRAY[1..84] OF TMemo;

procedure FillOutCalendar();
begin
        Memo[4].Lines.Add('This stupid thing!');
end;

  Any suggestions?  Thanks.

 

Re:Memo array raises exception


How about this:

procedure Initialize;
var
  i:integer;
begin
  for i:=1 to 84 do
    Memo[i] := Tmemo.Create(nil);
end;

procedure Finalize;
var
  i:integer;
begin
  for i:=1 to 84 do
    Memo[i].Free;
end;

procedure FillOutCalendar();
begin
 Inizialize;
 Memo[4].Lines.Add('Stupid thing indeed!');
 Finalize;
end;

Regards,
  Jernej

Quote
John wrote in message <3864B8BB.A188D...@arrl.net>...
>  The following ('Memo[4].Lines.Add('This stupid thing!')') is causing
>an exception error:

>Project Project1.exe raised exception class EAccessViolation with
>message 'Access violation at address 00447F45 in module
>'PROJECT1.EXE'...

>Memo : ARRAY[1..84] OF TMemo;

>procedure FillOutCalendar();
>begin
> Memo[4].Lines.Add('This stupid thing!');
>end;

>  Any suggestions?  Thanks.

Re:Memo array raises exception


Quote
In article <3864B8BB.A188D...@arrl.net>, John <W...@arrl.net> writes:
>Memo : ARRAY[1..84] OF TMemo;

>procedure FillOutCalendar();
>begin
>    Memo[4].Lines.Add('This stupid thing!');
>end;

>  Any suggestions?  Thanks.

Every object has to be created before using it (otherwise you get an access
violation), and windows controls (like TMemo) must have a parent (to receive
windows messages from).. You must at least have coded :-

Memo[4] := TMemo.Create(Self); // Self == the form the memo is in
Memo[4].Parent := Self; // or whatever the memo is positioned on

 . . . before coding :-

Memo[4].Lines.Add('This stupid thing!');

Alan Lloyd
alangll...@aol.com

Other Threads