Project App.path from inside UC in OCX? [Solved]
Hi guys! Im trying to find the real app.path where a project is run from inside the code of a usercontrol compiled as OCX.
Instead of what I expect I get:
IN IDE: The App.Path is OCX project folder.
COMPILED OCX: Where the OCX reside. (wich if its installed on the project using it its fine, but it can be installed on system32 or other folder)
In other words, I got a project in folder A and the ocx in folder B .... In project A I put the usercontrol and try to load and image using the name of the image concatenated with the app.path (filename = app.path & "\IMG\xxx.png") and whats happening is instead of A\IMG\xxx.png it try to load B\IMG\xxx.png.
So the question is: How to get the current executable/project path where the usercontrol inside the OCX is being used ?
Re: Project App.path from inside UC in OCX?
I'm not sure controls should be breaking encapsulation that way.
This sounds like a serious design problem, but there is a cheap fix: Rewrite the UserControl with a writeable property like ClientAppPath and assign a value to it at runtime within the client code.
If you must break encapsulation you will probably need to make API calls to go module spelunking. If this was a normal thing to do there would already be easy to use support, at least a single API call.
Re: Project App.path from inside UC in OCX?
Quote:
Originally Posted by
dilettante
I'm not sure controls should be breaking encapsulation that way.
This sounds like a serious design problem, but there is a cheap fix: Rewrite the UserControl with a writeable property like ClientAppPath and assign a value to it at runtime within the client code.
If you must break encapsulation you will probably need to make API calls to go module spelunking. If this was a normal thing to do there would already be easy to use support, at least a single API call.
The problem is in a class I use to load images wich is part of the ocx (with the usercontrols that use it) . I already fixed it setting at project load a global BasePath for all operations wich (if set) supercede the app.path .... this fixes the EXE but not inside the IDE.
You're right, following encapsulation rules the ocx should not be aware where it is used but must be some way to get the path (seems like very basic info)
Re: Project App.path from inside UC in OCX?
You can get the path of the process, not the path of the control or COM object.
you can put code in ocx project:
Code:
Dim AppPath2 As String
Sub SetAppPathFromExe(AppPath As String)
AppPath2 = AppPath
End Sub
'use AppPath2 replace app.path
run from exe:
SetAppPathFromExe app.path
Re: Project App.path from inside UC in OCX?
Quote:
Originally Posted by
xiaoyao
You can get the path of the process, not the path of the control or COM object.
you can put code in ocx project:
Code:
Dim AppPath2 As String
Sub SetAppPathFromExe(AppPath As String)
AppPath2 = AppPath
End Sub
'use AppPath2 replace app.path
run from exe:
SetAppPathFromExe app.path
Hi xiaoyao! My problem is to fix it from the IDE in Design mode. I found a workarround when running (exe or ide)
Re: Project App.path from inside UC in OCX?
1 Attachment(s)
Re: Project App.path from inside UC in OCX?
This is some approach using a hack.
The caveat is that when in IDE you need to open the form containing the UserControl at least once to save the client app path (and every time the app path changes), because it only can get it at design time and not at run time when in IDE.
Re: Project App.path from inside UC in OCX?
Quote:
Originally Posted by
Eduardo-
This is some approach using
a hack.
The caveat is that when in IDE you need to open the form containing the UserControl at least once to save the client app path (and every time the app path changes), because it only can get it at design time and not at run time when in IDE.
Just Perfect!!!! I mixed it to my other solution and now I can get the desired path always from the dll.
Big thanks Javi! :thumb::thumb::thumb: