INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

How To

Get the extension of the filename to change when the filetype is changed in a save dialog box by tayloredwarez
Posted: 1 Dec 05

Many products have this feature on their save dialogs, e.g. in Excel if the filename in the Save dialog is showing as "Book1.xls" and you change the File Type to ".txt" then filename is automatically changed to "Book1.txt"

This example uses an standard  FileSaveAs Action with an embedded dialog.

First add a reference to CommDlg.

CODE

Uses
 CommDlg;
This code is attached to the change file type event which fires when the user changes the extension combobox.

Then extract the new extension from the filter list, change the filename and send it back to the dialog box.

CODE

procedure TForm1.FileSaveAs1SaveDialogTypeChange(Sender: TObject);
var
   I : Integer;
   Fn, Ext : String;
   ExtList : TStringList;
const
     CB_FILENAME_ID = 1148;
begin
     ExtList:=TStringList.Create;
     try
        ExtList.Delimiter:='|';
        ExtList.DelimitedText:=FileSaveAs1.Dialog.Filter;
        Ext:=ExtList.Strings[FileSaveAs1.Dialog.FilterIndex*2-1];
     finally
        ExtList.Free;
     end;
     I:=Pos(Ext,';');
     if I>0 then Ext:=Copy(Ext,1,I-1);
     Ext:=StringReplace(Ext,'*','',[rfReplaceAll]);
     Fn:=ChangeFileExt(ExtractFilename(FileSaveAs1.Dialog.FileName),Ext);
     SendMessage( GetParent(FileSaveAs1.Dialog.Handle), CDM_SETCONTROLTEXT, CB_FILENAME_ID, LongInt(Pchar(Fn)));
end;

Back to Embarcadero: Delphi FAQ Index
Back to Embarcadero: Delphi Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close