Forums

public variable

Last post 7/7/2009 5:04 PM by Crono. 6 replies.
Sort Posts: Previous Next
  • ilario santamaria

    public variable

    7/4/2009 5:34 AM
    • Top 500 Contributor
    • Joined on 6/20/2009
    • Monza, Italia
    • Posts 58

     

    hello

    I have a public variable in a Xtraform, I can not read other xtraform or a class

    if I use normal form does
    ciao
    ilario
  • Brendon Muck [DX Squad]

    Re: public variable

    7/5/2009 6:13 PM
    • Top 10 Contributor
    • Joined on 5/16/2007
    • Buffalo, NY
    • Posts 5,810

    It really shouldn't make a difference. What does your code look like?

    Please do not email me directly for support. Use the Support Center or Community Forums so that everyone may benefit.
  • ilario santamaria

    Re: public variable

    7/7/2009 11:48 AM
    • Top 500 Contributor
    • Joined on 6/20/2009
    • Monza, Italia
    • Posts 58

     ciao

     

    I found

    if the variable is  
    public name as string is not working

    but if it is
    public shared name as string works

    only xtraform, with normal form is ok
    thank
    ilario
  • Brendon Muck [DX Squad]

    Re: public variable

    7/7/2009 11:53 AM
    • Top 10 Contributor
    • Joined on 5/16/2007
    • Buffalo, NY
    • Posts 5,810

    That still doesn't sound right to me. You don't necessarily want a static variable depending on your usage. Can you post the code of the XtraForm and the code that accesses the variable from the other forms?

    Please do not email me directly for support. Use the Support Center or Community Forums so that everyone may benefit.
  • ilario santamaria

    Re: public variable

    7/7/2009 12:23 PM
    • Top 500 Contributor
    • Joined on 6/20/2009
    • Monza, Italia
    • Posts 58

     <code>

     

    Class frmprincipale

     

    Public Shared PercorsoDatabase As String

     

    Private Sub frmprincipale_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

     

    'assegna il percorso db

     

    PercorsoDatabase = leggiKeyRegistro(

     

      end Sub

    "SOFTWARE\\M&I\..........", "database") 

    ...........

    </code>

     

    PercorsoDatabase = "Data Source=.\SQLEXPRESS;AttachDbFilename="C:\Documents and Settings\ilario\Desktop\MeI 2010\db uovo.mdf";Integrated Security=True;Connect Timeout=30;User Instance=True"

    In Class clsDati

    <code>

      imports System.Globalization

    Imports

     

    System

    Imports

     

    System.IO

    Imports

     

    DevExpress

    Public

     Class clsDati 

       Public DB As New SqlClient.SqlConnection()

     p

    ublic RecordCorrente As Integer

     

     

     

    Public Sub ConnettiDB(ByVal Nomeform As DevExpress.XtraEditors.XtraForm, Optional ByVal Percorso As String = "")

     

    Try

     

    Nomeform.Cursor = Cursors.WaitCursor

     

     

    If Percorso = "" Then ElseIf Percorso <> "" Then End If

     

    'apri db dati

     

    DB.Open()

    Nomeform.Cursor = Cursors.Default

     

     

    Catch ex As

    Exception

    ShowMessage(ex.Message,

    "", MessageBoxButtons.OK, MessageBoxIcon.Information) End Try 

     

    End Sub

    </code>

     

    if .......   Public Shared PercorsoDatabase As

     

    but

    Public PercorsoDatabase As String      ...... (Public Shared PercorsoDatabase As String)

    PercorsoDatabase =""  [:'(]

     

    ciao

    ilario

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

    String      is OK and

     

    Nomeform.Cursor = Cursors.Default

     

     

    DB.ConnectionString = frmprincipale.PercorsoDatabase

     

     

    DB.ConnectionString = Percorso

     

     

     

     

     

     

     

  • Trevor Westerdahl

    Re: public variable

    7/7/2009 12:27 PM
    • Top 25 Contributor
    • Joined on 5/4/2007
    • Portland, Oregon
    • Posts 2,424
    Sounds to me like you are trying to access the variable without instantiating the form; thus, the static/shared variable is accessible, but not the instance (not shared) variable.
    "ilario santamaria" wrote in message news:267889@community.devexpress.com...

     ciao

     

    I found

    if the variable is  
    public name as string is not working

    but if it is
    public shared name as string works

    only xtraform, with normal form is ok
    thank
    ilario


    http://community.devexpress.com/forums/p/78213/267889.aspx#267889

    Trevor Westerdahl - DX Squad
    BLOG: http://trevorunlocked.blogspot.com/
  • Crono

    Re: public variable

    7/7/2009 5:04 PM
    • Top 75 Contributor
    • Joined on 6/8/2007
    • Saint-Hyacinthe, Qc
    • Posts 324

    I cannot read your code, as it's heavily misformed, but I can assure you that the fact you're not seeing a Shared variable outside the scope of a class, XtraForm or not, isn't related to DevExpress in any way. This is basic, common .NET coding.

    There certainly is something you're doing wrong, or else you forgot to mention.

More from DevExpress
Live Chat
Have a pre-sales question?
Need assistance with your evaluation?
We are here to help.
Chat is one of the many ways you can contact members of the DevExpress Team. We are available Monday-Friday between 8:30am and 5:00pm Pacific Time.
If you need additional product information, require pre-sales assistance, or want help with your order, write to us at info@devexpress.com or call us at
+1 (818) 844-3383.