Solved

How to alter TSaveDialog Filename after TypeChange?

Posted on 2008-10-22
2
642 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
Comment Utility
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
Comment Utility
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In our object-oriented world the class is a minimal unit, a brick for constructing our applications. It is an abstraction and we know well how to use it. In well-designed software we are not usually interested in knowing how objects look in memory. …
Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
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…

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now