DMTrump
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.SaveDialog1TypeChan ge(Sender: TObject);
var
filterstr:string;
offset:integer;
List:Tstringlist;
s: string;
begin
Filterstr:=SaveDialog1.Fil ter;
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,l ist[savedi alog1.filt erindex-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.Fi leName); // 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
I can create the new Filename with the new extension using the following code:
procedure T_form.SaveDialog1TypeChan
var
filterstr:string;
offset:integer;
List:Tstringlist;
s: string;
begin
Filterstr:=SaveDialog1.Fil
List:=Tstringlist.Create;
For offset:=0 to length(Filterstr)-1 do
begin
if Filterstr[offset]='(' then begin s:=copy(Filterstr,offset+2
end;
s:= ChangeFileExt(SaveDialog1.
// 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.Fi
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
s:=ExtractFileName(s);