Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Declare, define a varibale in a windows form application

Declare, define a varibale in a windows form application

Scheduled Pinned Locked Moved C / C++ / MFC
helpdata-structurestutorialquestion
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Manfr3d
    wrote on last edited by
    #1

    Hello guys, I've the following problem: I want to declare a variable and set its value in a windows form outside a function, but when I buid the the project, the following error occurs: "error C3845: only static data members can be initialized inside a ref class or value type". Declaring the variables as static works but when I want to declare an array, that doesn't. It's not possible to declare the class as non-ref-class. Does anyone have an idea how to manage this? Thanks for your help, and best wishes.

    D M H 3 Replies Last reply
    0
    • M Manfr3d

      Hello guys, I've the following problem: I want to declare a variable and set its value in a windows form outside a function, but when I buid the the project, the following error occurs: "error C3845: only static data members can be initialized inside a ref class or value type". Declaring the variables as static works but when I want to declare an array, that doesn't. It's not possible to declare the class as non-ref-class. Does anyone have an idea how to manage this? Thanks for your help, and best wishes.

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      Austrian_Programmer wrote:

      Declaring the variables as static works but when I want to declare an array, that doesn't.

      How about showing us your code that is not working?

      "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

      "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

      1 Reply Last reply
      0
      • M Manfr3d

        Hello guys, I've the following problem: I want to declare a variable and set its value in a windows form outside a function, but when I buid the the project, the following error occurs: "error C3845: only static data members can be initialized inside a ref class or value type". Declaring the variables as static works but when I want to declare an array, that doesn't. It's not possible to declare the class as non-ref-class. Does anyone have an idea how to manage this? Thanks for your help, and best wishes.

        M Offline
        M Offline
        Matthew Faithfull
        wrote on last edited by
        #3

        I strongly recommmend you move this post to the C# forum before toxcct gets hold of it... Is that the sound a flame thrower warming up [duck]...

        Nothing is exactly what it seems but everything with seems can be unpicked.

        1 Reply Last reply
        0
        • M Manfr3d

          Hello guys, I've the following problem: I want to declare a variable and set its value in a windows form outside a function, but when I buid the the project, the following error occurs: "error C3845: only static data members can be initialized inside a ref class or value type". Declaring the variables as static works but when I want to declare an array, that doesn't. It's not possible to declare the class as non-ref-class. Does anyone have an idea how to manage this? Thanks for your help, and best wishes.

          H Offline
          H Offline
          Hamid Taebi
          wrote on last edited by
          #4

          Your code is managed or unmanaged?

          M 1 Reply Last reply
          0
          • H Hamid Taebi

            Your code is managed or unmanaged?

            M Offline
            M Offline
            Manfr3d
            wrote on last edited by
            #5

            Thanks for your help, I found a solution to the problem: I declare and define the variables in the InitializeComponents() function. By the way, does anyone know a tutorial for visual c++ windows forms using the windows forms project type of VS.NET? Thanks and best wishes.

            H 1 Reply Last reply
            0
            • M Manfr3d

              Thanks for your help, I found a solution to the problem: I declare and define the variables in the InitializeComponents() function. By the way, does anyone know a tutorial for visual c++ windows forms using the windows forms project type of VS.NET? Thanks and best wishes.

              H Offline
              H Offline
              Hamid Taebi
              wrote on last edited by
              #6

              I think you can find articles on the codeproject did you search?

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups