Late binding problems when upgrading from VB6

G

Guest

In my VB6 code I have added properties to several forms to change the form's
behaviour depending from where it is called and often modified these
properties in a generic function like this example:
Private Sub InsertForm(frmInsert As Form, nLabelSpace As Integer)
frmInsert.SpecialLabelSpace = nLabelSpace
End Sub
When I convert this to .NET I get this code:
Private Sub InsertForm(ByRef frmInsert As System.Windows.Forms.Form, ByRef
nLabelSpace As Short)
frmInsert.SpecialLabelSpace = nLabelSpace
End Sub
This creates an error because my added property is not a member of
System.Windows.Forms.Form.
How do I best fix this in .NET?

Thanks in advance!
Gungmas
 
L

Larry Serflaten

Gungmas said:
In my VB6 code I have added properties to several forms to change the form's
behaviour depending from where it is called and often modified these
properties in a generic function like this example:
Private Sub InsertForm(frmInsert As Form, nLabelSpace As Integer)
frmInsert.SpecialLabelSpace = nLabelSpace
End Sub
When I convert this to .NET I get this code:
Private Sub InsertForm(ByRef frmInsert As System.Windows.Forms.Form, ByRef
nLabelSpace As Short)
frmInsert.SpecialLabelSpace = nLabelSpace
End Sub
This creates an error because my added property is not a member of
System.Windows.Forms.Form.
How do I best fix this in .NET?

For this particular case, what is the purpose of calling the sub? The
calling code knows the form and the value to pass in, so why bother
calling out to a sub for one line of code?

For a more generic situation (where there may be more lines of code),
you might consider moving your form properties to a separate interface.
Then any form that supports that interface would be gaurenteed to have
the needed routines available, and your subs would all expect to be
passed an object that supports your interface:
Private Sub InsertForm(frmInsert As IFormProperties, nLabelSpace As Integer)
frmInsert.SpecialLabelSpace = nLabelSpace
End Sub


HTH
LFS
 
G

Guest

Larry, thanks for your reply.
This was just meant as a short example, of course there are several more
lines of code in the sub.
I am not familiar with how to create/use interfaces, can you give me a short
hint how to do that?

Gungmas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top