Solved

How to alter TSaveDialog Filename after TypeChange?

Posted on 2008-10-22
2
661 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

839 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