User defined Form property

  • Thread starter Thread starter Harry Strybos
  • Start date Start date
H

Harry Strybos

Hi Guys

Am I just dumb or is there some new way to get a form property? eg

In frmClient I have:

Private _ClientID As Integer

Public Property ClientID() As Integer
Get
Return _ClientID
End Get
Set (ByVal Value As Integer)
_ClientID = Value
End Set
End Property

In frmMain I do something like this:

Dim frm As Form = New frmClient

With frm
.ShowDiaglogue()
'PROBLEM frm does not expose its property ClientID
If .ClientID > 0 Then 'error here
'do something
End if
End With

What am I doing wrong????? Thanx
 
Hi Guys

Am I just dumb or is there some new way to get a form property? eg

In frmClient I have:

Private _ClientID As Integer

Public Property ClientID() As Integer
Get
Return _ClientID
End Get
Set (ByVal Value As Integer)
_ClientID = Value
End Set
End Property

In frmMain I do something like this:

Dim frm As Form = New frmClient

Dim frm As New frmClient
With frm
.ShowDiaglogue()
'PROBLEM frm does not expose its property ClientID
If .ClientID > 0 Then 'error here
'do something
End if
End With

What am I doing wrong????? Thanx

You are assigning the inheriting type to it's base type. Form doesn't
expose a ClientID property :)
 
Dim frm As Form = New frmClient
'PROBLEM frm does not expose its property ClientID

The variable is declared using Form. The Form class doesn't have a ClientID property, the frmClient class does. Declare your variable using frmClient instead of Form:

Dim frm As frmClient = New frmClient

Or

Dim frm As New frmClient
 
Dim frm As New frmClient


You are assigning the inheriting type to it's base type. Form doesn't
expose a ClientID property :)

But then this begs the question: what is frm variable set to?
He used:

Dim frm As Form = New frmClient

In the above frm is specifically set to a new instance of the frmClient.
Are you telling me that frm.ClientID doesn't exist?!
Then the above declaration/instantiation should not be allowed
and should cause an error.

Well, how about this:

Dim obj As Object = New frmClient

What is obj in the above statement?
Does it have the ClientID property?
 
But then this begs the question: what is frm variable set to?

frm is set to a new instance of frmClient. But since its declared "As Form" you will only see the properties and methods exposed by the Form class.
Are you telling me that frm.ClientID doesn't exist?!

It exists, but is not accesible because frm is declared as Form, and is not a property of Form.
Then the above declaration/instantiation should not be allowed
and should cause an error.

Why? If frmClient inherits from Form that construction is valid.
Dim obj As Object = New frmClient

What is obj in the above statement?

A new frmClient instance.
Does it have the ClientID property?

It does, and you can call it if "Option Strict" is set to "Off". Otherwise you will have cast it to frmClient to call it.
 
frm is set to a new instance of frmClient. But since its declared "As Form" you will only see the properties and methods exposed by the Form class.

This makes no sense.
It is a "new instance" of frmClient but its property can't be accessed??
What does a "new instance" mean?
 
Back
Top