Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Access violation at address 0045D810 in module 'Project1.exe'

Status
Not open for further replies.

johanzold

Programmer
Feb 2, 2008
3
HU
Hello,

i try to test the well known ping.pas / icmp.pas, without any luck :(

---

This the first few lines of the head of the Unit1:

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,Dialogs, StdCtrls, Ping;

type
TForm1 = class(TForm)

If i Write here :
Ping1:Tping;


then later i call: Ping1.Timeout := 3000;

I get the following error message: Exceptional class EAccessViolation with message Access violation at address 0045D810 in module 'Project1.exe'. Read of address 00000030.

If save and close the project, and open it again I get the following error message:

Field Form1.Ping1 does not have a corresponing component. Remove the declatation ?
---

If I move Ping1:Tping; to the 'var' part:

var
Form1: TForm1;
Ping1:Tping;

I get the following error message: Exceptional class EAccessViolation with message Access violation at address 0045CB98 in module 'Project1.exe'. Read of address 00000030.

---

If I add Ping1: Tping to Unit1.dfm:

object Form1: TForm1
Ping1= TPing

I get the first erro I had described.

---------

My question is: what am i doing wrong ?
 
Hi,

your trying to access an object that's not created yet, hence the AV. the ping variable is nothing more than a pointer to a structure (the TPing object) in memory.

If save and close the project, and open it again I get the following error message:

Field Form1.Ping1 does not have a corresponing component. Remove the declatation ?

add the ping : TPing line in the public section of the form object (look for the keyword public), or, as you did declare it as a global variable.

then you must do something like this

Code:
....
 Ping := TPing.Create; // this will create your actual object
 // now you can reference the object
 Ping.Timeout := 3000;
 DoSomethingWithPing;
 // now free the allocated memory 
 FreeAndNil(Ping);
 // object is now destroyed
 Ping.Timeout := 3000; // ---> this will create an AV since the object no longer exists

...

I hope this makes sense....

Cheers,
Daddy

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
Thank you! The ' Ping := TPing.Create; ' version works fine. Unfortunately I compline the program, it needs additional 10 second to complile it, but it is okay.

The first version (ping1 : TPing; in the public part)
unfortunately still don't work.

1.
type
TForm1 = class(TForm)
r1: TMemo;
public
ping1 : TPing;
procedure FormShow(Sender: TObject);


It will gives an error message: Error reading Form1.OnShow: Invalid property value

2.

type
TForm1 = class(TForm)
r1: TMemo;
procedure FormShow(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
ping1 : TPing;
end;


This version still creates an error message :
Exceptional class EAccessViolation with message Access violation at address 0045CB98 in module 'Project1.exe'. Read of address 00000030

Any idea where is the problem ?
 
The original Pingtst1.pas made by F. Piette also starts like these:


unit PingTst1;

{$I ICSDEFS.INC}

interface

uses
Windows, Messages, SysUtils, Classes, Forms, StdCtrls, Controls, Ping;

const
PingTestVersion = 103;
CopyRight : String = ' PingTest (c) 1997-2005 Francois Piette V1.03 ';

type
TPingTstForm = class(TForm)
Ping1: TPing;


So


type
SomeForm = class(TForm)
Ping1: TPing;


should work somehow. But how ?
 
oh I see.

in fact the TPing object is a component.
any reference direct under the class definition is put there by the designer. did you install FPiette's ICS component suite?

if this is the case you just drop a TPing component from the palette onto your form. in that case the TPing.Create is handled by the TForm.

/Daddy

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top