Solved

How to alter TSaveDialog Filename after TypeChange?

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Use tracing facilities in your browser steps 2 110
Run video youtube webbrowse 10 57
Reconfigure Delphi Install? 2 46
eclipse formatting 6 72
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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: …
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

910 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

22 Experts available now in Live!

Get 1:1 Help Now