Link to home
Start Free TrialLog in
Avatar of DMTrump
DMTrumpFlag for United States of America

asked on

How to alter TSaveDialog Filename after TypeChange?

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

ASKER CERTIFIED SOLUTION
Avatar of DMTrump
DMTrump
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of DMTrump

ASKER

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);