Solved

How to alter TSaveDialog Filename after TypeChange?

Posted on 2008-10-22
2
659 Views
Last Modified: 2013-11-23
In Wordpad, for instance, changing the "Save Type as" dropdown (which calls the TypeChange event in Delphi) places the changed filename with the new extension in the FileName field.

I can create the new Filename with the new extension using the following code:

procedure T_form.SaveDialog1TypeChange(Sender: TObject);
var
  filterstr:string;
  offset:integer;
  List:Tstringlist;
  s: string;
begin
  Filterstr:=SaveDialog1.Filter;
  List:=Tstringlist.Create;
  For offset:=0 to length(Filterstr)-1 do
  begin
    if Filterstr[offset]='(' then begin s:=copy(Filterstr,offset+2,4); List.Add(s); end;
  end;
  s:= ChangeFileExt(SaveDialog1.FileName,list[savedialog1.filterindex-1]);
// and just to helo me figure out what is happening:
  ShowMessage(s);                                     // displays properly renamed strring
  SaveDialog1.FileName:=s;                         // my attempt to change it
//Did it work?:  (No)
  ShowMessage(SaveDialog1.FileName);   // but the SaveDialog.Filename doesn't change
  FreeandNil(List);
end;

What is the proper way to do this so that the displayed filename with the new extension is shown and used?

TIA

0
Comment
Question by:DMTrump
  • 2
2 Comments
 

Accepted Solution

by:
DMTrump earned 0 total points
ID: 22838172
Here is the code that I got to work.  I figured I needed to do a SendMessage and kept poking around until I figured it out:

procedure T_form.SaveDialog1TypeChange(Sender: TObject);
var
  filterstr:string;
  offset:integer;
  List:Tstringlist;
  s: string;
begin
  Filterstr:=SaveDialog1.Filter;
  List:=Tstringlist.Create;
  For offset:=0 to length(Filterstr)-1 do
  begin
    if Filterstr[offset]='(' then begin s:=copy(Filterstr,offset+2,4); List.Add(s); end;
  end;
  s:= ChangeFileExt(SaveDialog1.FileName,list[savedialog1.filterindex-1]);

  // requires CommDlg in your uses clause
  SendMessage( GetParent(SaveDialog1.Handle), CDM_SETCONTROLTEXT,
     CB_FILENAME_ID, LongInt(Pchar(s)));
  // you may have to define CB_FILENAME_ID as 1148 yourself

  FreeandNil(List);
end;
0
 

Author Comment

by:DMTrump
ID: 22842869
I forgot - in the code above you should have something like the following operation to remove the full path from the filename before Sending it to the Edit field with the SendMessage command:

  s:=ExtractFileName(s);
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Dev Express grid collapse 2 45
Tidtcpserver listening on multiports? 1 27
Wincontrol not (correctly) drawn 15 38
Delphi: barcode reading on android platform 1 30
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question