Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Proper way to instantiate a method in another file

$
0
0

This is a variation on the newbie question about, "An object reference is required for the non-static field...."

I'm implementing Gustavo Franco's A* C# code (from here).

I need to call his method (in PathFinder.cs):

        public List<PathFinderNode> FindPath(Point start, Point end)
        {
            PathFinderNode parentNode;
            bool found  = false;

            int gridX = MainWindow.MapWidth;
            int gridY = MainWindow.MapHeight;

            mStop       = false;
            mStopped    = false;
            mOpen.Clear();
            mClose.Clear();
  
            .... etc.

When I try to call it from my file, MainWindow.xaml.cs like this:

 LWPath = PathFinder.FindPath(Start, Goal);

It throws the ever popular error:

Error    1    An object reference is required for the non-static field, method, or property 'DinosaurIsland.PathFinder.FindPath(System.Drawing.Point, System.Drawing.Point)'  

I can't make FindPath static because it causes errors in his class:

   public class PathFinder : IPathFinder
    {
        [System.Runtime.InteropServices.DllImport("KERNEL32.DLL", EntryPoint="RtlZeroMemory")]
        public unsafe static extern bool ZeroMemory(byte* destination, int length);

        #region Variables Declaration

        private  PriorityQueueB<PathFinderNode>  mOpen                   = new PriorityQueueB<PathFinderNode>(new ComparePFNode());
        private  List<PathFinderNode>            mClose                  = new List<PathFinderNode>();
        private  bool                            mStop                   = false;
        private  bool                            mStopped                = true;
        private  int                             mHoriz                  = 0;
        private  HeuristicFormula                mFormula                = HeuristicFormula.Euclidean; // note, changed from Manhattan
        private  bool                            mDiagonals              = true;
        private  int                             mHEstimate              = 2;
... etc.

So, how do I call / instantiate it?

Thanks for all the help!


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>