Board index » delphi » Need help; newbie question--access violation error

Need help; newbie question--access violation error

I need a little help.  This procedure opens a dialog box in which view
angles can be entered. Once clicked, an image of a plant is displayed.  It
works fine the first time through but when I try it again I get an error
message  --exception class C0000005 with message access violation at
0x00000000 read of address 0x000000000. This error occurs at the statement
ViewPlantDlg.ShowModal; .   The first time through it steps to Edit1.Set
Focus, but not the second time.  Any suggestions will be much appreciated.

procedure TForm1.PlantViewClick(Sender: TObject);
begin
  ViewPlantDlg.ShowModal;

if ViewPlantDlg.ModalResult = mrOK then

begin
    HidePanels;
    Caption:=CurrentPlantFile;
    CurrentPage := ShowPlant;
    ReDrawPaintbox;
  end;

end;

procedure TViewPlantDlg.FormActivate(Sender: TObject);
begin
  Edit1.SetFocus;
end;

Bob Pearcy
rwpea...@ucdavis.edu

 

Re:Need help; newbie question--access violation error


Hello Robert!

Robert W. Pearcy <rwpea...@ucdavis.edu> wrote in message
news:850ogu$cf7$1@mark.ucdavis.edu...

Quote
> I need a little help.  This procedure opens a dialog box in which view
> angles can be entered. Once clicked, an image of a plant is displayed.  It
> works fine the first time through but when I try it again I get an error
> message  --exception class C0000005 with message 'access violation at
> 0x00000000 read of address 0x000000000'. This error occurs at the
statement
> ViewPlantDlg.ShowModal; .   The first time through it steps to Edit1.Set
> Focus, but not the second time.  Any suggestions will be much appreciated.

A access violation with adresses of 0x0..0 are normaly a access to a object
via object pointer witch is nil (you will get these messages often :-( ).
I guess you close the dialog window and try to access it in a later turn.
Normaly a form is freed after closing so it is not accessable later. You
have to create a dialog for each time you use it - a common error is to use
the dialog since Delphi adds every new form in a project to its
autocreate-list in the project file (see .dpr file).

Drop me a eMail if you need further help

Martin

Re:Need help; newbie question--access violation error


Thanks very much to Martin.  I fixed it by hiding the form (action
parameter=caHide) rather than closing it (action parameter =caFree)

Bob Pearcy

Re:Need help; newbie question--access violation error


Hello Robert!

Robert W. Pearcy <rwpea...@ucdavis.edu> wrote in message
news:852t6k$bl8$1@mark.ucdavis.edu...

Quote
> Thanks very much to Martin.  I fixed it by hiding the form (action
> parameter=caHide) rather than closing it (action parameter =caFree)

As I don't know your application I can't tell you if you are doing right.
Normaly you have to create and free (or take care for it) dialogs. Don't
take the short, easy way. At least in a bigger project you may get toubles!

Martin

Re:Need help; newbie question--access violation error


Quote
In article <8546rv$3g...@news.netway.at>, "Martin Wei?" <d...@ping.at> writes:
>> Thanks very much to Martin.  I fixed it by hiding the form (action
>> parameter=caHide) rather than closing it (action parameter =caFree)

>As I don't know your application I can't tell you if you are doing right.
>Normaly you have to create and free (or take care for it) dialogs. Don't
>take the short, easy way. At least in a bigger project you may get toubles!

>Martin

I'll go along with that. You shouldn't have any trouble with freeing the
dialog, particularly if it's shown modal (I've lost the rest of the thread so I
don't know).

The way to do this is to remove the dialog from the applications autocreate
list: Project>Options>Forms.

Set the forms visible property to true in the Object inspector (if it isn't the
main form it will default to false).

to show the form

   Application.CreateForm(TYourForm1,YourForm1);
  YourForm1.ShowModal;

In the forms 'close' Set action to caFree (as I recall you've tried).

This should work without fail. If it doesn't there is something else wrong. Are
you trying to access YourForm1 variables when the form hasn't been created or
after it's been freed? If you want to access changed variables from the modal
dialog after it has been freed you need to write those variables to a unit
variable or Form variable (one that isn't nil!) before the dialog closes.

Gordon.
~~~~~~~~~~~~~~~~~~~~~~~~
Certifiable - definitely <g>

http://members.aol.com/mgcsoft/  (the function junction equation editor)
http://members.aol.com/delphistuf/delphstf.htm   (Delphi bits and bobs and a
few links)

MGCSoft

Re:Need help; newbie question--access violation error


Quote
"Martin Wei?" wrote:

> Normaly a form is freed after closing so it is not accessable later.

Oh really? I think not. You can tell Delphi which forms you would like
it to auto create, but having autocreated some forms, it only frees all
of them on program termination.

Anyway, the poster speaks of a dialog box. Perhaps he's creating that
manually (perhaps if the TDialog is not nil), showing modally, and then
freeing it without setting the dialog pointer to nil, thus guaranteeing
carnage the second time round??

MH.

--
Martin Harvey. mar...@pergolesi.demon.co.uk
     http://www.pergolesi.demon.co.uk

The Usenet Oracle has pondered your question deeply.  Your question
was: Will your answer to this question be in the negative?
And in response, thus spake the Oracle: Memory fault.  Core dumped.

Other Threads