Re-load class module after change

I created a user library. I created a class module in it.
When a class module is changed, its behavior does not change, as if it were compiled once.
LoadLibrary doesn’t help
Thank you Dyakuyu

Please, show your code. I can’t reproduce your problem in my system.

Version: 7.6.4.1 (X86_64) / LibreOffice Community
Build ID: 60(Build:1)
CPU threads: 16; OS: Linux 6.6; UI render: default; VCL: gtk3
Locale: es-MX (en_US.UTF-8); UI: en-US
7.6.4-1
Calc: threaded

module “dataRecord” in user library “data”

Option Explicit
Option Compatible
Option ClassModule

private const delimField="|", delim="="

property get SomeProp() as variant
    SomeProp=322223
end property

Public Function Field(byref sData as string,sKey as string) as Variant
	dim sDataPair as string
	for each sDataPair in Split(sData,delimField)
		if UCase(Trim( split(sDataPair,delim,2)(0) )) = UCase(sKey) then
			on local error resume next
			Field=split(sDataPair,delim,2)(1)
			on local error goto 0
			exit function
		EndIf
	next
End Function
  

in other (inside document) module:

	Globalscope.BasicLibraries.loadLibrary("data")
' dataRecord is visible as object without props and public methods
	const sample="ID=1|value=Some value|alter=Some other"
	dim r

	r=dataRecord.Field(sample, "ID") ' ERROR, property or method not found

In your example, an instance of the class is not created.
Add a regular module to the data library:

Function New_dataRecord()
  New_dataRecord=New DataRecord
End Function

Now call from another library:

Sub Test
  const sample="ID=1|value=Some value|alter=Some other"
  Dim dRecord, r 
  Globalscope.BasicLibraries.loadLibrary("data")  
  dRecord=New_dataRecord()
  r=dRecord.Field(sample, "ID") '  no ERROR
End Sub  
1 Like

they already gave you the solution to the problem.

1 Like

But how does this happen, for example, in the SF_Array module?
Is there some module/sub in the library with a reserved name?
After LoadLibrary(“ScriptForge”) we can simply use SF_Array.NecessaryFunction() .

I tried to smoke sources from ScriptForge, but Enlightenment did not come

Well, let’s take it in order.

Smoke this again, just pay attention to the details.
For example, start with SF_Utils. As the name suggests, this thing is very close to the root of the entire SF-tree. Yes, this is where we can see the New operator in the form Set _SF_ = New SF_Root
A nuance that explains a lot - there is no Option ClassModule string in this module.
And this is not in the SF_UI module. And in the SF_Array, and in the SF_Exception… In other words, exactly the mechanism that @sokol92 wrote about is used - next to the class modules there are ordinary modules, which actually create objects of the required classes.
This is not Enlightenment yet, this is only the first step towards it.
Take the next step, explain to us (and at the same time to yourself) - why do you need object-oriented programming if you just need to select a key-value pair from a text string? Why doesn’t a regular function do the job easily and quickly?

Option Explicit

Sub testPair
Const sample="ID=1|value=Some value|alter=Some other"
Dim sKey As String 
Dim vValue As Variant 
	For Each sKey In Array("ID", "wrong ID")
		vValue = getSingleField(sample, sKey)
		If IsEmpty(vValue) Then
			MsgBox "No Key '" & sKey &"' in string '" & sample & "'!", MB_ICONSTOP, "Wrong data"
		Else 
			MsgBox "Value for Key='" & sKey &"' is '" & vValue & "'", MB_ICONINFORMATION, "Result"
		EndIf 
	Next sKey
End Sub 

Function getSingleField(sData As String, sKey As String, Optional FieldDelimiter As String, Optional PairDelimiter As String) As Variant
Dim aTemp As Variant, aSTemp As Variant 
Dim i As Long 
Dim sDataPair As String
Dim sDataKey As String
	getSingleField = Empty
	If IsMissing(FieldDelimiter) Then FieldDelimiter = "|"
	If IsMissing(PairDelimiter) Then PairDelimiter = "="
Rem If the text Key does not appear in the sData line, then there is no point in continuing:
	If InStr(sData, sKey) = 0 Then Exit Function 
Rem There are different types of errors in data.
Rem For example, there may be no key-value separator 
	If InStr(sData, PairDelimiter) = 0 Then Exit Function 

	aTemp = Split(sData,FieldDelimiter)
	For i = LBound(aTemp) To UBound(aTemp)
		sDataPair = aTemp(i)
		If (InStr(sDataPair, sKey) > 0) And (InStr(sDataPair, PairDelimiter) > 0) Then
			aSTemp = Split(sDataPair, PairDelimiter, 2)
			If UCase(Trim(aSTemp(0))) = UCase(sKey) Then 
				getSingleField=aSTemp(1)
				Exit Function 
			EndIf 
		EndIf 
	Next 
End Function

Or do you expect that someone will also parse your code line by line in anticipation of Enlightenment?

1 Like