Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TSaveDialog and filename

Status
Not open for further replies.

michaenh

Programmer
Aug 7, 2002
205
NO
Hi Delphi Experts.

Ok. Here is the question...
I want to change the filename in the SaveDialogbox when users choose different.. filter.
f.ex. filter as txt, xml, csv etc. and the filename will appears as MyFile.txt, MyFile.xml, etc.

I manage to change the filename before SaveDialog is executed but not while it is executing(when the dialog is open fo the user).

I could create my own dialogsbox but it would be easier to use TSaveDialog..

cheers and many thanks
mha
 
hi whosrdaddy.

ex.
procedure TForm1.Button1Click(Sender: TObject);
begin
if savedialog1.execute then
showmessage(savedialog1.filename);
end;

procedure TForm1.SaveDialog1TypeChange(Sender: TObject);
begin
case savedialog1.FilterIndex of
1 : savedialog1.DefaultExt := 'xml';
2 : savedialog1.DefaultExt := 'dat';
3 : savedialog1.DefaultExt := 'txt';
else
savedialog1.DefaultExt := '';
end;
end;

but the onTypeChange-event is only triggered, when the select is the first filter-entry

why? buggy TSaveDialog?

cheers,
mha
 
well I got something working... :)

Ex.
procedure TForm1.Button1Click(Sender: TObject);
begin
savedialog1.Filter:='html|*.html|txt|*.txt|dat|*.dat|pdf|*.pdf|csv|*.csv';
SaveDialog1.DefaultExt:='';
if savedialog1.execute then
begin
SaveDialog1TypeChange(self);
showmessage( SaveDialog1.FileName + '.' + SaveDialog1.DefaultExt);
// Here you can saveTofile...
end;
end;

procedure TForm1.SaveDialog1TypeChange(Sender: TObject);
begin
case savedialog1.FilterIndex of
1 : savedialog1.DefaultExt := 'html';
2 : savedialog1.DefaultExt := 'txt';
3 : savedialog1.DefaultExt := 'dat';
4 : savedialog1.DefaultExt := 'pdf';
5 : savedialog1.DefaultExt := 'csv';
else
//savedialog1.DefaultExt := '';
end;
end;

I only miss that TSaveDialog should be more as f.ex save as in MS Word.
The extension is added to filename when ever i choose a spefic filter.. thanks for all your help.

Thanks for all your help guys..

cheers,
mha
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top