Articles   Members Online: 3
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to change the file name in a TSaveDialog when the user selects a different f Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
31-Jan-03
Category
Dialogs
Language
Delphi 2.x
Views
189
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: William Gerbert

I have two extensions setup in a TSaveDialog box filter section (.bmp and .gif). 
How do I force an extension change in the filename editbox that is displayed when I 
change the file type dropdown box? Basically if I have picture.bmp in the filename 
edit box and I change the file type to gif, how do I force the edit box to change 
to picture.gif.

Answer:

Solve 1:

You could try this. I'm not sure if the line S := (Sender as TSaveDialog).Filename; 
works in Delphi 5 or earlier but otherwise it should be okay.

1   uses
2     CommDlg;
3   
4   procedure TForm1.SaveDialog1TypeChange(Sender: TObject);
5   var
6     S: string;
7     H: THandle;
8   begin
9     H := GetParent((Sender as TSaveDialog).Handle);
10    S := (Sender as TSaveDialog).Filename;
11    if DirectoryExists(S) then
12      S := '';
13    if S <> '' then
14      with TSaveDialog(Sender) do
15        case FilterIndex of
16          1: S := ChangeFileExt(S, '.rtf');
17          2: S := ChangeFileExt(S, '.txt');
18        else
19          S := '';
20        end;
21    if S <> '' then
22      SendMessage(H, CDM_SETCONTROLTEXT, edt1, longint(PChar(ExtractFileName(S))));
23  end;



Solve 2:

24  uses
25    commdlg, Dlgs;
26  
27  procedure TForm1.SaveDialog1TypeChange(Sender: TObject);
28  var
29    newExt: string;
30    filename: string;
31    filenamebuf: array[0..MAX_PATH] of Char;
32  begin
33    case savedialog1.FilterIndex of
34      1: newExt := '.DB';
35      2: newExt := '.DBF';
36      3: newExt := '.GDB';
37    else
38      exit;
39    end;
40    SendMessage(Windows.GetParent(savedialog1.handle), CDM_GETSPEC, MAX_PATH,
41      lparam(@filenamebuf));
42    filename := ChangeFileExt(filenamebuf, newext);
43    SendMessage(Windows.GetParent(savedialog1.handle), CDM_SETCONTROLTEXT,
44      edt1, integer(Pchar(filename)));
45  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC