Accessing a member on 'OwnerClass.TempPoint' may cause a runtime exception because it is a field of

  • Thread starter Thread starter Mr. X.
  • Start date Start date
M

Mr. X.

Hello.
I did in my code :

public class OwnerClass
{
private Point FTempP;
}

public class ChildClass
{
OwnerClass FOwner;
....
FOwner.FTempP.X = 10; // This and following line, has got the warning :
Accessing a member on 'OwnerClass.TempPoint' may cause a runtime exception
because it is a field of a marshal-by-reference class
FOwner.FTempP.Y = 10;
....
}
....
Why is the warning, and what should I write instead.

Thanks :)
 
Hello.
I did in my code :

public class OwnerClass
{
private Point FTempP;
}

public class ChildClass
{
OwnerClass FOwner;
...
FOwner.FTempP.X = 10; // This and following line, has got the warning :
Accessing a member on 'OwnerClass.TempPoint' may cause a runtime exception
because it is a field of a marshal-by-reference class
FOwner.FTempP.Y = 10;
...
}
...
Why is the warning, and what should I write instead.

That code can't be real. You declared FTempP private but yet you appear to
be accessing it from an object instance:

FOwner.FTempP.X = 10;

Also, the error message says "TempPoint" and that doesn't appear anywhere.
First post the real code (or enough equivalent code for us to reproduce the
problem), then maybe we can help.

You can usually do a Google search on the exact text of an error message (or
the compiler error code) and find all sorts of help. The first hit I got
points right to MSDN.
 
FTempP = FTempPoint.

The two classes are on the same file.
I want to use FTempP in both the classes of the same file (and only by the
both classes).
Even I declare FTempP as public, I got the message.
Instead of :
FOwner.FTempP.X = 10;
FOwner.FTempP.Y = 10;
I did :
FOwner.FTempP = new Point(10, 10);
and problem was solved.

Thanks :)

Should I declare this variable as private, or something else.
 
Back
Top