Articles   Members Online:
-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 folder in Open/Save dialogs 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
23-Sep-03
Category
Dialogs
Language
Delphi 3.x
Views
132
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Eugene Mayevski

It is possible to specify initial folder in Open/Save dialogs. However sometimes it 
is necessary to change current folder, for example, in responce to change of 
filter. 

Answer:

Windows doesn't offer a way to change current dialog. However there is a very handy 
approach to this problem - imitate user actions. Below is the sample code of how 
the folder is changed when filter is changed. 

procedure SaveDialogTypeChange is a handler for OnTypeChange event. 
Depending on the type different folders are selected. This piece of code saves the 
value of file name edit box, puts a new folder name there, then imitates click of 
OK button and then restores contents of the edit box. 
Add Dlgs to "uses" clause of your unit.
1   
2   procedure TMainForm.SaveDialogTypeChange(Sender: TObject);
3   var
4     S, S1: string;
5     EditHandle: THandle;
6     startp,
7       endp: DWORD;
8   begin
9     s := '';
10    if SaveDialog.FilterIndex = 2 then
11    begin
12      s := 'c:\program files';
13    end
14    else if SaveDialog.FilterIndex = 3 then
15    begin
16      s := 'd:\program files';
17    end;
18    if s <> '' then
19    begin
20      EditHandle := GetDlgItem(GetParent(SaveDialog.Handle), edt1);
21      if EditHandle <> 0 then
22      begin
23        SetLength(S1, GetWindowTextLength(EditHandle) + 1);
24        GetWindowText(EditHandle, PChar(S1), Length(S1));
25        SetLength(S1, StrLen(PChar(S1)));
26        SendMessage(EditHandle, EM_GETSEL, Integer(@StartP), Integer(@EndP));
27        SetWindowText(EditHandle, PChar(S));
28        SendMessage(GetParent(SaveDialog.Handle), WM_COMMAND, 1,
29          GetDlgItem(GetParent(SaveDialog.Handle), IDOK));
30        if Length(S1) > 0 then
31          if S1[Length(S1)] = #10 then
32            Delete(S1, Length(S1), 1);
33        SetWindowText(EditHandle, PChar(S1));
34        SendMessage(EditHandle, EM_SETSEL, StartP, EndP);
35      end;
36    end;
37  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