Sub New () is not available in this context because it is "Friend",

So what does this mean and how can I fix it?

This message occurs if I put the New keyword in the lines (lines) below. If I delete it, at runtime I get the error "I need to use New." What am I doing wrong?

Dim oPS As AeccPointStyle = New AeccPointStyle
ops = oDescKey.PointStyle 

Debug.Print(oPS.Name)
Debug.Print(oPS.MarkerSymbolName)

Also tried

Dim oPS As New AeccPointStyle
ops = oDescKey.PointStyle

Debug.Print(oPS.Name)
Debug.Print(oPS.MarkerSymbolName)

Thanks!

Update 1 - Based on a Comment from Meta-Knight

1 -

Dim oPS As AeccPointStyle = Nothing
oPS = oDescKey.PointStyle

2 -

Dim oPS As AeccPointStyle = oDescKey.PointStyle

Both versions throw NullReferenceExceptions.

+3
source share
5 answers

The empty AeccPointStyle constructor is marked as friend, which means that only its classes can call it.

, , , New. "". , :

Dim oPS As AeccPointStyle = oDescKey.PointStyle

NullReferenceException:

, , Nothing. , oDescKey Nothing, .

oDescKey Nothing, , - , PointStyle. , PointStyle NullReferenceException. oDescKey.PointStyle , , .

+4

AeccPointStyle "Friend", .. :

Friend Class AeccPointStyle

"Friend", :

Friend Sub New()

, , , . , , AeccPointStyle. , :

+2

: AeccPointStyle , . (Sub New) AeccPointStyle Friend, , .

.

  • Sub New , Public
  • Shared Public Sub Create, AeccPointStyle
0

AeccPointStyle . , , .

, :

Dim oPointStyle As AeccPointStyle 
Set oPointStyle = g_oAeccDoc.PointStyles.Add(strName) 

PointStyles (, - PointStylesColleciton) g_oAeccDoc AeccPointStyle .

0

When using FRIEND as an access modifier for your class, you need to make sure that both the class and the class in which you use it are in the same NAMESPACE, otherwise you will receive this error message.

0
source

Source: https://habr.com/ru/post/1713275/


All Articles