Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

how come no file extension?

Posted on 1998-02-15
7
Medium Priority
?
160 Views
Last Modified: 2010-04-04
how come i save my file using the save file dialog and
the filter is *.txt and i save and
there is no extension when i look at the file i save...
is there a way to get the extension and save with the extension?
0
Comment
Question by:superboy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 5

Accepted Solution

by:
inter earned 0 total points
ID: 1359271
Check it upon return my friend,

...
if SaveDialog.Execute then
begin
  if Pos('.txt', SaveDialog.FileName) = 0 then
  begin
    FileName := SaveDialog.FileName+'.txt';
  end;
end;
...

Igor
0
 

Author Comment

by:superboy
ID: 1359272
but i want multiple formats like *.rtf, *.txt etc
the user will select from the save file dialog and
your method only shows to save in *.txt format... - the default filename.
i want to get the filter from the save file dialog and
save in whatever formats the user choose..
0
 
LVL 5

Expert Comment

by:inter
ID: 1359273
Then you should track the array of extentions and check the FilterIndex to find which you append, if the user modifies the filter index in SaveDialog the following procedure appends the correct one:

const
Filters : array[0..1] of string = ('.txt','.rtf');

...
if SaveDialog.Execute then
begin
 // if file have an extention it contains .
 if Pos('.', SaveDialog.FileName) = 0 then
 begin
  FileName := SaveDialog.FileName+
              Filters[SaveDialog.FilterIndex];
 end;
end;
...

Igor
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:superboy
ID: 1359274
i want to save a file as "all files"
that means i want to save as the filename with no extension
whenever the user choose all files (*.*)
how do i do that? with yr code, if i choose (*.*),
the file will be saved as Filename.4D when i choose to save as all files..
the filters i have are *.rtf (lst), *.txt (2nd), *.*(3rd)
0
 
LVL 5

Expert Comment

by:inter
ID: 1359275
// the same order should be given in Filters of SaveDialog
const
  Filters : array[0..1] of string = ('.txt','.rtf','*.*');

if Pos('.', SaveDialog.FileName) = 0 then
begin
  if Filters[SaveDialog.FilterIndex] = '*.*' then
    FileName := SaveDialog.FileName+ '.'
  else
    FileName := SaveDialog.FileName+
    Filters[SaveDialog.FilterIndex];
end

Igor
0
 

Author Comment

by:superboy
ID: 1359276
const
Filters: array[0..3] of string=('', '.rtf','.txt', '*.*');

SaveFileDialog.FileName := Caption;
if SaveFileDialog.Execute then
begin
if Pos('.', SaveFileDialog.FileName) = 0 then
    begin
     if Filters[SaveFileDialog.FilterIndex] ='*.*' then
      begin
       PathName := SaveFileDialog.FileName + '';
       Caption := ExtractFileName(PathName);
      end
     else
       begin
       PathName := SaveFileDialog.FileName + Filters[SaveFileDialog.FilterIndex];
       Caption := ExtractFileName(PathName);
       end;
    end;
     Save1Click(Sender);
   end;

what u mean the order in the filters? can u explain the Filters
array thing?
i use the code above and surprisely it work...but i am not
sure why there is a need for the extra element in the array..
that's the empty string "''"...can u explain?
0
 
LVL 5

Expert Comment

by:inter
ID: 1359277
In the save dialog you specify the extensions that SaveDialog should know. Now there is an order there. For example first one can be '*.txt', second be '*.rtf'. I mean this as an order of the filters. If THIS order do not match the extension order you defined in your program for checking which extension user selects, the program works wrong.

You can safely remove the empty string from array. But this is due to the fact that SaveDialog.FilterIndex's base value is 1. so the decleration should be:
const
  Filters: array[1..3] of string=('.rtf','.txt', '*.*');

BUT, That is not empty string my friend you should append a DOT for filenames with no extentions. If you look closely to the code above(I just wrote before yours) the thing in quote is a DOT, FULLSTOP '.'. Is that ok? so when you tell OS that your file is named as 'TEST.' it realy names is as 'TEST'. So the code you have given as

PathName := SaveFileDialog.FileName + '';

should be

PathName := SaveFileDialog.FileName + '.';

igor
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Suggested Courses

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question