Difference between revisions of "Miscellaneous TD tips"

From Team Developer SqlWindows Wiki
Jump to: navigation, search
(Added tip to check if template is valid)
Line 29: Line 29:
 
That function returns the current folder which may change during runtime (eg when changing it programatically or a SalDlgFile function is used.<br>
 
That function returns the current folder which may change during runtime (eg when changing it programatically or a SalDlgFile function is used.<br>
 
The <b>GetRuntimeDirectory</b> described here will allways return the folder where the executable was initially started from.
 
The <b>GetRuntimeDirectory</b> described here will allways return the folder where the executable was initially started from.
 +
 +
 +
<!------------------------------------------------------------------------------------------------------------------------------>
 +
{{TipHeader|How to check at runtime, if a given string is a valid window template}}
 +
To check if a string representing a window template is valid, you can use SalCompileAndEvaluate.<br>
 +
Pass the template name to this function and check the return value (type).<br>
 +
<br>
 +
For instance, if you want to check if "frmMain" is a valid template (when you pass that template to SalCreateWindowEx).<br>
 +
<br>
 +
<pre>
 +
  Set sTemplate = "frmMain"
 +
  Set nType = SalCompileAndEvaluate( sTemplate, nError, nErrorPos, nReturn, sReturn, dtReturn, hWndReturn, TRUE, SalContextCurrent( ) )
 +
</pre>
 +
If nType > 0 the template is valid. If it is 0 (zero) it is invalid.<br>
 +
<br>
 +
Here you can download a sample:
 +
*[http://samples.tdcommunity.net/index.php?dir=&file=WIKI_CheckTemplateIsValid.zip WIKI_CheckTemplateIsValid.zip]<br>
 +
<br>

Revision as of 21:05, 21 October 2008

This page covers miscellaneous TeamDeveloper tips.

Contents


Pointer2.png How to get the application runtime folder Pointer.png

To determine from where the application was started, use the following function :

Function: GetRuntimeDirectory
   Returns
      String:
   Local variables
      String: sDir
      String: sDummy
      String: sDrive
      String: sFolder
   Actions
      ! The next Vis function is from vtdos.apl
      Call VisDosSplitPath( strArgArray[0], sDrive, sDir, sDummy, sDummy )
      Set sFolder = sDrive || sDir
      ! This function will allways return the folder with an ending backslash
      If SalStrRightX( sFolder, 1 ) != "\\"
         Set sFolder = sFolder || "\\"
      Return sFolder


The function SalFileGetCurrentDirectory is not the same !
That function returns the current folder which may change during runtime (eg when changing it programatically or a SalDlgFile function is used.
The GetRuntimeDirectory described here will allways return the folder where the executable was initially started from.


Pointer2.png How to check at runtime, if a given string is a valid window template Pointer.png

To check if a string representing a window template is valid, you can use SalCompileAndEvaluate.
Pass the template name to this function and check the return value (type).

For instance, if you want to check if "frmMain" is a valid template (when you pass that template to SalCreateWindowEx).

   Set sTemplate = "frmMain"
   Set nType = SalCompileAndEvaluate( sTemplate, nError, nErrorPos, nReturn, sReturn, dtReturn, hWndReturn, TRUE, SalContextCurrent( ) )

If nType > 0 the template is valid. If it is 0 (zero) it is invalid.

Here you can download a sample: