I reuse existing code as much as possible. I will store portions of code in static methods in a global class, so I can reuse them as the need arises.
Basically, I don't believe in re-inventing the wheel. When something has been done and it has been done good, why try duplicating it?
That's why I would like to draw your attention to some lesser known code in Ax, the browseforFolderDialog method from the WinAPI class. It's easy, flexible and powerful. (That's what I look for in good quality code.)
The code will provide the user the opportunity to supply a folder name from the file system, a common request in software.
Format:
client public static str browseForFolderDialog(
[str _description,
str _selectedPath,
boolean _showNewFolderButton])
So you can give a description to your dialog. Set a default path. And give the user the possibility to create a new folder.
Example:
str filelocation;
;
filelocation=WinApi::browseForFolderDialog('Your_Description_here',@'C:\Temp',true);
Of course, you can validate the user input (did the user press cancel?) with
WinApi::folderExists(filelocation);
WinApi::folderExists(filelocation);
This one line of code sure beats writing your custom dialog or a complete form with the necessary controls.
No comments:
Post a Comment