WINDEV 17 - Correct use of HAlias

Startbeitrag von Steven Sitas am 09.05.2013 16:33

I have an application where my Analysis has Classic HF tables.
At the beginning of the application a user can choose to work with HF Classic files OR change to an HFCS database.
If the user chooses HF Classic files I change the my connection accordingly AND then I use HChangeDir to POINT to the Directory where the files are.
Everything works as expected ...

At various point of my app, I use ALIAS files, with the following code:

////////////////////////////////////////////////
GLAccount_alias is Data Source
HAlias(GLAccount,GLAccount_alias)
HChangeConnection(GLAccount_alias ,myconnect)
HChangeName(GLAccount_alias, "GLAccount")
//////////////////////////////////////////////

Now here are the "funny" things.
1. It works OK when the user chooses C/S mode
2. It works OK when the user RUNS the app in Classic mode and the EXE is under my development folder
3. It runs OK when I RUN the app in Classic mode and TEST mode (IDE)

4. It HAS PROBLEMS when the app is in Classic mode and I Run it from the C:\Program Files\exedirectory.
In step (4) it tries to find and create the INDEX files of the alias file, in the EXEs directory.
Ofcourse Windows7 does not allow this so it gives an error ...
What is really strange is that in (2) or (3) this index is NEVER really created !!!!!

There is a "note" in the Online help that says the following:
//If HChangeDir or HConnect has been used with the source file, these changes are ignored by the file. //

But how am I supposed to deal with this situation ?

Antworten:

Hi Steven,

please note that the \Program Files folder of Win7+ is read only! You cannot write into any subfolder there. Therefore, a HF Classic File in this folder will not work. You can change the rights to this folder to different than standard (e.g. PC Soft does it for their Reports and HF C/S database). However, I recommend to use \Program Data\ProgramName or \Program Data\YourCompanyName\ProgramName instead.

Kind regards,
Guenter

von GuenterP - am 09.05.2013 16:44
Hi Guenter,
I know that I cannot use this directory ....
All my data files use a directory like c:\mydata
I do this with HChangeDir()

The problem is that HAlias on a file, does not "respect" the HChangeDir() that was used on the original file.

HAlias files (in Classic MODE) always uses the Directory that was "harcoded" during the generation of the EXE.

von Steven Sitas - am 09.05.2013 17:02
Hi Steven,

Have you tried to call HChangeDir() on the new alias file after HChangeConnection()? (HChangeConnection() should not be required because an alias normaly an exact copy of the original.)

Now the question that comes to my mind: what is the actual connexion..source path that you use with HChangeConnection()? HChangeDir() has effect on the file, but the connexion can have a different path. Then the path would change for the alias because you call HChangeConnection(), etc.

Best regards,
Alexandre Leclerc

von Alexandre Leclerc - am 09.05.2013 17:17
Hi Steven,

Just an additionnal note. You say: "If the user chooses HF Classic files I change the my connection accordingly AND then I use HChangeDir to POINT to the Directory where the files are."

This is not best practice. Let the connection handle everything. In a HF Classic connection, simply set the ..Source property to the good path. Then assign the connection to the files. In HFCS mode, this is the same.

We have an application that offers the same choice to the user. The only thing we do is configure the connection, make sure the path exists (in Classic mode), open the connection, assign the connection to all the files, then create / open the files.

Best regards,
Alexandre Leclerc

von Alexandre Leclerc - am 09.05.2013 17:21
Hello Steven

I use HAlias() quite a lot in HF Classic mode. In Classic mode, there is no HChangeConnection() requirement so maybe you could test for the mode you are running in and skip over that statement. The other thought may be to changethe order of the statements so that the alias is fully created and the name changed before HChangeConnection() or HChangeDir() as I think this is what the help inidicates - the creation of an alias means that you have to tell Windev where it is located after it has been created

GLAccount_alias is Data Source
HAlias(GLAccount,GLAccount_alias)
HChangeName(GLAccount_alias, "GLAccount")
//after the HChangeName
HChangeConnection(GLAccount_alias ,myconnect)

Regards
Al

von Al - am 09.05.2013 17:32
Using HChangeDir() on the Alias file - as Alexandre suggested - solved my problem.
Also the suggestion from Al also solves the problem !!!!

As of Alexandres other suggestion to let the connection point to the directory - instead of using HChangeDir - I have a played a little with this idea in the past.
But since I have some temporary tables in another directory, called c:\temp, it looks very difficult to handle it with the connection..source property.
Should I have 2 connections to handle this or am I missing something?

Thanks for all the help

von Steven Sitas - am 09.05.2013 18:29
Hi Steven,

This depends of your needs. We have a software that uses two connections. Each connection is used by many files. At any moment we change the second connection to point to another data directory to use different files while the main connection always stays the same.

It really depends of the needs. Using two connections has been very handy and simple to use for us instead of manipulating all the files paths. We can create a connexion, test it, and if all is ok, change the desired files' connection and voilà!

Best regards,
Alexandre Leclerc

von Alexandre Leclerc - am 09.05.2013 19:52
Zur Information:
MySnip.de hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.