Ask a filename without using Microsoft Common Dialog Control

krikikriki Member, Moderator Posts: 9,112
edited 2008-11-17 in NAV Tips & Tricks
I invented this function in the pre-Codeunit 412:"Common Dialog Management" era.
AskFile(VAR PtexFileName : Text[1024];pblnImport : Boolean) : Boolean
// AskFile
// IMPORTANT : you can also use Codeunit 412:"Common Dialog Management"
// Asks the user for a filename
// PARAMETERS :
//   VAR PtexFileName : INPUT : Default filename 
//                              (a defaultname, default path or default extension can be given)
//                      OUTPUT : Selected filename
//   pblnImport : TRUE : select filename for import/reading
//                FALSE : select filename for export/writing

ltexHelp := PtexFileName;
IF pblnImport THEN BEGIN
  ltexHelp := lrecObject."BLOB Reference".IMPORT(ltexHelp,TRUE);
END
ELSE BEGIN
  lrecObject.SETRANGE(Type,lrecObject.Type::Table);
  lrecObject.FIND('-');
  lrecObject.CALCFIELDS("BLOB Reference");
  ltexHelp := lrecObject."BLOB Reference".EXPORT(ltexHelp,TRUE);
END;
IF ltexHelp <> '' THEN
  PtexFileName := ltexHelp;
EXIT(ltexHelp <> '');

Use it like this:
LtxtHelp := txtTheFileName;
IF AskFile(LtxtHelp,TRUE / FALSE) THEN
  txtTheFileName := LtxtHelp;
The IF THEN is needed to avoid that the value in "txtTheFileName" is removed if the function is called but then cancelled.
Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


Comments

  • ta5ta5 Member Posts: 1,164
    Great, thanks to all of you!
    Very good help, saved me some headaches.
    thomas
Sign In or Register to comment.