Paurths
asked on
DLL - pass objects
hi,
i have a working DLL, to which i pass listboxes and msflexgrid's to be filled with data from a database.
This all works excellent,
but now i would like to be able to pass a TreeView to the DLL to be filled.
This is giving me errors b/c the properties and methods of a treeview are not known inside the DLL.
(Dim mNode As Node <-- error
Set mNode = Treeview.Nodes.Add(1, tvwChild) <-- tvwChild errors out also)
If i add the 'Microsoft Windows Common Controls 6.0' to the project-components it works just fine.
my question is; is it OK to do this?
Or is there another way to do this?
cheers
Ricky
i have a working DLL, to which i pass listboxes and msflexgrid's to be filled with data from a database.
This all works excellent,
but now i would like to be able to pass a TreeView to the DLL to be filled.
This is giving me errors b/c the properties and methods of a treeview are not known inside the DLL.
(Dim mNode As Node <-- error
Set mNode = Treeview.Nodes.Add(1, tvwChild) <-- tvwChild errors out also)
If i add the 'Microsoft Windows Common Controls 6.0' to the project-components it works just fine.
my question is; is it OK to do this?
Or is there another way to do this?
cheers
Ricky
It is OK to do so. You don`t have much alternatives.
ASKER
hi emoreau,
if i distribute the dll to another pc, will it also hold the components' properties and methods in it? (i can't test this right now... only have one pc at my disposal)
cheers
Ricky
if i distribute the dll to another pc, will it also hold the components' properties and methods in it? (i can't test this right now... only have one pc at my disposal)
cheers
Ricky
ASKER
seems it is solved emoreau,
i undid the selection of the component 'Microsoft Windows Common Controls 6.0' and used this instead:
Dim mNode As Object
and replaced tvwChild by 4 (seems that is its value...)
works so far...
will test more however.
cheers
Ricky
i undid the selection of the component 'Microsoft Windows Common Controls 6.0' and used this instead:
Dim mNode As Object
and replaced tvwChild by 4 (seems that is its value...)
works so far...
will test more however.
cheers
Ricky
>i undid the selection of the component
You will be using late binding which is many times slower than early binding (where every call is resolved during compile time).
I must admit that I use "As Object" sometimes, but not if performance is important.
You will be using late binding which is many times slower than early binding (where every call is resolved during compile time).
I must admit that I use "As Object" sometimes, but not if performance is important.
ASKER
hi ameba,
but if i keep the component in my DLL, will it be available if i install my dll on another system (if the user can pass a treeview, it will most likely be on the pc, but links get broken once in a while :-( )
cheers
Ricky
but if i keep the component in my DLL, will it be available if i install my dll on another system (if the user can pass a treeview, it will most likely be on the pc, but links get broken once in a while :-( )
cheers
Ricky
Your DLL will not work without installed dependencies, i.e. without the right version of mscomctl32.ocx
If there is newer version installed on PC, or if your exe uses newer version, it should work, if everybody is respecting COM rules.
If there is newer version installed on PC, or if your exe uses newer version, it should work, if everybody is respecting COM rules.
ASKER
ok,
i will add the 'Microsoft Windows Common Controls 6.0' to the project-components again then.
(i just thought it was pretty strange to do this with a DLL)
so in my package and deploy i will need to add the component for installation also on the remote pc. (correct)
and so i can use the proper components' methods and properties (their names...)
cheers
Ricky
i will add the 'Microsoft Windows Common Controls 6.0' to the project-components again then.
(i just thought it was pretty strange to do this with a DLL)
so in my package and deploy i will need to add the component for installation also on the remote pc. (correct)
and so i can use the proper components' methods and properties (their names...)
cheers
Ricky
>so in my package and deploy i will need to add the component
Are you installing that DLL without any EXE ?
If you pack them together, only one mscomctl32.ocx will be in your package.
If you are installing them separately, you can have mscomctl32.ocx in both packages, if you want to respect COM rules strictly, but one should be enough.
If you do not install some component, because you know you have it on PC already, one thing can happen:
A app - installs DLL or OCX.
B app uses OCX, but doesn't install it
C app uses OCX, but doesn't install it
and now you uninstall A - uninstall program will look into registry to see if any other app uses OCX, it finds count_of_OCX_users = 0, and removes OCX.
B and C do not work anymore
Are you installing that DLL without any EXE ?
If you pack them together, only one mscomctl32.ocx will be in your package.
If you are installing them separately, you can have mscomctl32.ocx in both packages, if you want to respect COM rules strictly, but one should be enough.
If you do not install some component, because you know you have it on PC already, one thing can happen:
A app - installs DLL or OCX.
B app uses OCX, but doesn't install it
C app uses OCX, but doesn't install it
and now you uninstall A - uninstall program will look into registry to see if any other app uses OCX, it finds count_of_OCX_users = 0, and removes OCX.
B and C do not work anymore
We normally do not install DLLs used by app. When we install app (EXE), all references and components will be included together with their dependencies.
ASKER
i will be installing the exe and dll together, but the dll should be distributable without my app.
So any other developer can use it in its own program.
cheers
Ricky
So any other developer can use it in its own program.
cheers
Ricky
For developers, to make things simpler, I would use one DLL file only.
With VB, component doesn't have to be installed - adding reference to VB project via References dialog will register DLL.
You can also drag&drop unregistered OCX file onto toolbox in VB IDE - this will register component.
With VB, component doesn't have to be installed - adding reference to VB project via References dialog will register DLL.
You can also drag&drop unregistered OCX file onto toolbox in VB IDE - this will register component.
ASKER
hmm,
i re-added the 'microsoft Windows Common Controls 6.0' , but
seems i can not use this:
Public Function ShowRecsAllTables(Database Name As String, Treeview As Treeview)
when i compile it says:
"Compile error:
Private object modules cannot be used in public object modules as parameters or return types for public procedures, as public data members, or as fields of public user defined types"
so i guess i do have to use :
Public Function ShowRecsAllTables(Database Name As String, Treeview As Object)
cheers
Ricky
i re-added the 'microsoft Windows Common Controls 6.0' , but
seems i can not use this:
Public Function ShowRecsAllTables(Database
when i compile it says:
"Compile error:
Private object modules cannot be used in public object modules as parameters or return types for public procedures, as public data members, or as fields of public user defined types"
so i guess i do have to use :
Public Function ShowRecsAllTables(Database
cheers
Ricky
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
excellent ameba,
thanx,
one of my tables has over 100 000 recs,
makes a difference now,
cheers
Ricky
thanx,
one of my tables has over 100 000 recs,
makes a difference now,
cheers
Ricky
ASKER
btw,
u, or anyone else for that matter, any good at recursive functions?
https://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=visualbasic&qid=20274138
drives me kinda nuts...
Thanks.
To load a tree, I suggest Chris Eastwood's code, which first adds all nodes to root, and later reparents them. .Tag property is used to cache ParentID.
Private Sub FillTree()
Dim lCount As Long
Dim rsSections As Recordset
Dim sParent As String
Dim sKey As String
Dim sText As String
Dim bBookMark As Boolean
Dim nNode As Node
On Error GoTo vbErrorHandler
'
' Populate our TreeView Control with the Data from our database
'
Set rsSections = mDB.OpenRecordset("select * from codeitems order by parentid")
Set tvCodeItems.ImageList = Nothing
Set tvCodeItems.ImageList = ImageList1
If rsSections.BOF And rsSections.EOF Then
tvCodeItems.Nodes.Add , , "ROOT", "Code Library", "VIEWBOOKMARKS"
BoldTreeNode tvCodeItems.Nodes("ROOT")
Exit Sub
End If
TreeRedraw tvCodeItems.hwnd, False
rsSections.MoveFirst
Set tvCodeItems.ImageList = Nothing
Set tvCodeItems.ImageList = ImageList1
'
' Populate the TreeView Nodes
'
With tvCodeItems.Nodes
.Clear
.Add , , "ROOT", "Code Library", "VIEWBOOKMARKS"
'
' Make our Root Item BOLD
'
BoldTreeNode tvCodeItems.Nodes("ROOT")
'
' Now add all nodes into TreeView, but under the root item.
' We reparent the nodes in the next step
'
Do Until rsSections.EOF
sParent = rsSections("ParentID").Val ue
sKey = rsSections("ID").Value
sText = rsSections("Description"). Value
Set nNode = .Add("ROOT", tvwChild, "C" & sKey, sText, "FOLDER")
'
' Record parent ID
'
nNode.Tag = "C" & sParent
rsSections.MoveNext
Loop
End With
'
' Here's where we rebuild the structure of the nodes
'
For Each nNode In tvCodeItems.Nodes
sParent = nNode.Tag
If Len(sParent) > 0 Then ' Don't try and reparent the ROOT !
If sParent = "C0" Then
sParent = "ROOT"
End If
Set nNode.Parent = tvCodeItems.Nodes(sParent)
End If
Next
'
' Now setup the images for each node in the treeview & set each node to
' be sorted if it has children
'
For Each nNode In tvCodeItems.Nodes
If nNode.Children = 0 Then
nNode.Image = "CHILD"
Else
nNode.Sorted = True
End If
Next
Set rsSections = Nothing
'
' Expand the Root Node
'
tvCodeItems.Nodes("ROOT"). Sorted = True
tvCodeItems.Nodes("ROOT"). Expanded = True
TreeRedraw tvCodeItems.hwnd, True
Exit Sub
vbErrorHandler:
TreeRedraw tvCodeItems.hwnd, True
MsgBox Err.Number & " " & Err.Description & " " & Err.Source
End Sub
Private Sub TreeRedraw(ByVal lHwnd As Long, ByVal bRedraw As Boolean)
SendMessageLong lHwnd, WM_SETREDRAW, bRedraw, 0
End Sub
To load a tree, I suggest Chris Eastwood's code, which first adds all nodes to root, and later reparents them. .Tag property is used to cache ParentID.
Private Sub FillTree()
Dim lCount As Long
Dim rsSections As Recordset
Dim sParent As String
Dim sKey As String
Dim sText As String
Dim bBookMark As Boolean
Dim nNode As Node
On Error GoTo vbErrorHandler
'
' Populate our TreeView Control with the Data from our database
'
Set rsSections = mDB.OpenRecordset("select * from codeitems order by parentid")
Set tvCodeItems.ImageList = Nothing
Set tvCodeItems.ImageList = ImageList1
If rsSections.BOF And rsSections.EOF Then
tvCodeItems.Nodes.Add , , "ROOT", "Code Library", "VIEWBOOKMARKS"
BoldTreeNode tvCodeItems.Nodes("ROOT")
Exit Sub
End If
TreeRedraw tvCodeItems.hwnd, False
rsSections.MoveFirst
Set tvCodeItems.ImageList = Nothing
Set tvCodeItems.ImageList = ImageList1
'
' Populate the TreeView Nodes
'
With tvCodeItems.Nodes
.Clear
.Add , , "ROOT", "Code Library", "VIEWBOOKMARKS"
'
' Make our Root Item BOLD
'
BoldTreeNode tvCodeItems.Nodes("ROOT")
'
' Now add all nodes into TreeView, but under the root item.
' We reparent the nodes in the next step
'
Do Until rsSections.EOF
sParent = rsSections("ParentID").Val
sKey = rsSections("ID").Value
sText = rsSections("Description").
Set nNode = .Add("ROOT", tvwChild, "C" & sKey, sText, "FOLDER")
'
' Record parent ID
'
nNode.Tag = "C" & sParent
rsSections.MoveNext
Loop
End With
'
' Here's where we rebuild the structure of the nodes
'
For Each nNode In tvCodeItems.Nodes
sParent = nNode.Tag
If Len(sParent) > 0 Then ' Don't try and reparent the ROOT !
If sParent = "C0" Then
sParent = "ROOT"
End If
Set nNode.Parent = tvCodeItems.Nodes(sParent)
End If
Next
'
' Now setup the images for each node in the treeview & set each node to
' be sorted if it has children
'
For Each nNode In tvCodeItems.Nodes
If nNode.Children = 0 Then
nNode.Image = "CHILD"
Else
nNode.Sorted = True
End If
Next
Set rsSections = Nothing
'
' Expand the Root Node
'
tvCodeItems.Nodes("ROOT").
tvCodeItems.Nodes("ROOT").
TreeRedraw tvCodeItems.hwnd, True
Exit Sub
vbErrorHandler:
TreeRedraw tvCodeItems.hwnd, True
MsgBox Err.Number & " " & Err.Description & " " & Err.Source
End Sub
Private Sub TreeRedraw(ByVal lHwnd As Long, ByVal bRedraw As Boolean)
SendMessageLong lHwnd, WM_SETREDRAW, bRedraw, 0
End Sub
ASKER
could it be there is something missing ameba?
some sub: BoldTreeNode
and 'SendMessageLong' (is this an API?)
cheers
Ricky
some sub: BoldTreeNode
and 'SendMessageLong' (is this an API?)
cheers
Ricky
Well, yes, that is not working code, but only concept.
Public Declare Function SendMessageLong Lib "user32" Alias "SendMessageA" (ByVal hwnd _
As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
BoldTreeNode - Chris Eastwood's code (on Codeguru site) was for VB5. In VB6, .Bold property of the node is supported, e.g.:
tvCodeItems.Nodes("ROOT"). Bold = True
Public Declare Function SendMessageLong Lib "user32" Alias "SendMessageA" (ByVal hwnd _
As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
BoldTreeNode - Chris Eastwood's code (on Codeguru site) was for VB5. In VB6, .Bold property of the node is supported, e.g.:
tvCodeItems.Nodes("ROOT").
Recursive function will have more visits to database - if you want to fill the tree completely, that will be slow.
ASKER
works excellent ameba,
except for :
TreeRedraw tvCodeItems.hwnd, True
that gives me an IPF
but, if i leave it out, it works...
and the pictures could not be found (only folder, none of the others)
i posted a 'points for ameba': https://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=visualbasic&qid=20274655
cheers
Ricky
u sure know your stuff :-)
except for :
TreeRedraw tvCodeItems.hwnd, True
that gives me an IPF
but, if i leave it out, it works...
and the pictures could not be found (only folder, none of the others)
i posted a 'points for ameba': https://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=visualbasic&qid=20274655
cheers
Ricky
u sure know your stuff :-)
Thanks, and sorry for IPF ;-)