0

Hello Iam working in a global int in which a variable will be used later. I've made the global variable like this:

    class Foo
    {
       public static int stream = Bass.BASS_StreamCreateFile(path1.Text, 0, 0, BASSFlag.BASS_DEFAULT);
    }

which will be later called like this:

Foo.stream

and it can also contain more then 1 stream for example stream20,30,etc...

The problem here is that it returns me this error:

"An object reference is required for the non-static field, method, or property" where I call the text in path1.Text

How do I fix this?

Joscplan
  • 1,024
  • 2
  • 15
  • 35
  • 1
    Where does `path1.Text` come from? Where is it declared? You must declare path1 as a `static` in order to fix your problem e.g. public static Foo path1`, however this design already smells ugly. – Jason Evans Oct 17 '13 at 15:36
  • Presumably `path1` is an instance variable. Which instance of `Foo` are you expecting to be relevant here? – Jon Skeet Oct 17 '13 at 15:36
  • `path1.Text` is declatated where i made the variable `(path1.Text, 0, 0, BASSFlag.BASS_DEFAULT)` and there I use the path of the file being used. – Joscplan Oct 17 '13 at 15:37

1 Answers1

2

Your better off doing something like this:

public class Foo
{
    public static int GetStream(string path)
    {
        return Bass.BASS_StreamCreateFile(path, 0, 0, BASSFlag.BASS_DEFAULT);
    }
}

int foo = Foo.GetStream(path1.Text); // Or whatever you want to call the method.

Passing the path as a parameter.

EDIT:

Based on your comment, does the following code work for you?

public class Foo
{
    public static int GetStream(string path)
    {
        return 1;
    }
}

int foo = Foo.GetStream(path1.Text);

You should get 1 returned. If that does work then you have a problem with Bass.BASS_StreamCreateFile(). Otherwise, can you please post all of your code so that we can see how you are using the class Foo in your code?

Jason Evans
  • 28,906
  • 14
  • 90
  • 154
  • yeah but what if the "path" is in a Text? like for instance I would use path1.Text as the path. It would return me the same error leaving me where I first started. – Joscplan Oct 17 '13 at 15:43
  • Still getting the same error `An object reference is required for the non-static field, method, or property` plus invalid characters. ¿What did I do wrong? – Joscplan Oct 17 '13 at 15:47
  • I saw you removed the invalid chars but the error is still there. Iam using it exactly how you wrote it. `An object reference is required for the non-static field, method, or property` is there something else missing? – Joscplan Oct 17 '13 at 15:50