Try and replace low(aCheck) and hi(aCheck) with 0 and 14 respectively

Chris Albert,
Innovative Technologies.
-----Original Message-----
From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf
Of Bobby Clarke
Sent: Wednesday, July 27, 2005 12:49 PM
To: [email protected]
Subject: [delphi-en] Code not re-useable

Hi



I have a dynamically created form (called P in the code below) which creates
an array of checkboxes in the FormCreate procedure. The code works the first
time. The code will even work again, repeatedly, provided that no other work
is done. If other work is done (presumably overwriting memory), then the
line

ACheck[i] := TCheckBox.Create(P);

gives an abstract error or an access violation.

Originally, in FormClose, I tried a simple ACheck[I].Free and moved to
FreeAndNil(ACheck[I]) following a  suggestion from the group to someone else
's problem. I also tried a FreeAndNil on the whole array with the same
result.

How can I completely remove the CheckBox array to return to the first time
situation? (Delphi 7)



Bobby Clarke





MAIN FORM


procedure TMain.P1Click(Sender: TObject);
begin
  P := TP.Create(Main);           // Also tried Create(Self) but this made
no difference
  P.Show;
end;


FORM P


private
  ACheck : array [0..14] of TCheckBox;
End;

procedure TP.FormCreate(Sender: TObject);
var
  i : integer;
begin
  for i := low(ACheck) to high(ACheck) do
    begin
     ACheck[i] := TCheckBox.Create(P);      // can give an abstract or
access violation error
     ACheck[i].Left := 32;
     ACheck[i].Top  := 50 + i*18;
     ACheck[i].Parent := Panel;
     ACheck[i].Caption := 'text';
     ACheck[i].Alignment := taLeftJustify;
   end;

procedure TP.FormClose(Sender: TObject;  var Action: TCloseAction);
var
  i : integer;
begin
  Action := caFree;

  for i := low(ACheck) to high(ACheck) do
    begin
      try FreeAndNil(ACheck[i])    except end;   // Originally
ACheck[i].Free
    end;
  // FreeAndNil(ACheck);
end;



-----------------------------------------------------
Home page: http://groups.yahoo.com/group/delphi-en/
To unsubscribe: [EMAIL PROTECTED] 
Yahoo! Groups Links



 





-----------------------------------------------------
Home page: http://groups.yahoo.com/group/delphi-en/
To unsubscribe: [EMAIL PROTECTED] 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/delphi-en/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 


Reply via email to