Mike

I tried all your suggestions and the problem disappeared so I undid them one
at a time. The one that does the magic is

Added FormDestroy event to kill the form
P := nil;

I then reverted all the FreeAndNil to Free and it still works so I guess P
:= nil is the answer.

I really do appreciate that. Who said Delphi was easy!



Bobby Clarke



  -----Original Message-----
  From: [email protected] [mailto:[EMAIL PROTECTED]
Behalf Of Mike Lucek
  Sent: 27 July 2005 12:45
  To: [email protected]
  Subject: RE: [delphi-en] Code not re-useable


  Tried your code, made a few changes and don't get the problem.

  In your FormCreate added ACheck[i].Name := 'Check'+IntToStr(i);
  To give each checkbox a name.

  In your FormClose changed to:

  for i := 0 to ComponentCount - 1 do
  begin
      if Components[i] is TCheckBox then
        TCheckBox(Components[i]).Free;
  end;
  Action := caFree; <-----------------put it after freeing the checkboxes


  Added FormDestroy event to kill the form
  P := nil;

  Try it and see how you go
  Mike

  -----Original Message-----
  From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf
  Of Bobby Clarke
  Sent: Wednesday, 27 July 2005 7: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]



  SPONSORED LINKS C programming language  Computer programming languages
The c programming language
        C programming language  List of programming languages  Delphi
programmer


----------------------------------------------------------------------------
--
  YAHOO! GROUPS LINKS

    a..  Visit your group "delphi-en" on the web.

    b..  To unsubscribe from this group, send an email to:
     [EMAIL PROTECTED]

    c..  Your use of Yahoo! Groups is subject to the Yahoo! Terms of
Service.


----------------------------------------------------------------------------
--




[Non-text portions of this message have been removed]



-----------------------------------------------------
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