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 ?
Last edited by shagratt; Jul 31st, 2021 at 02:24 PM.
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.
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)
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.
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!