Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

Why sometimes in the Open dialog I cannot load the same file extension on the Open dialog filters, so I had to refresh the first to find the file.

E.g.: Filter = *.jpg

I can not find the file *.jpg in Explorer Open dialog, but there are a lot of images with extension *.jpg .

This happens on Win 7 OS [x86 & x64]. The compiler version I am using is Delphi 7.

procedure TForm1.Button1Click(Sender: TObject);
  JpgIF: TJpegImage;
  BmpIF: TBitmap;
begin
  JpgIF := TJpegImage.Create;
  BmpIF := TBitmap.Create;
  OD.FileName := '';
  OD.DefaultExt := '*.jpg;*.jpeg;*.psd;*.tga*.png;*.gif;*.bmp';
  OD.Filter := 'JPG|*.jpg|Jpeg|*.jpeg|PSD|*.psd|TGA|*.tga|PNG|*.png|GIF|*.gif|Bmp|*.bmp';
  if not OD.Execute then
  else if LowerCase(ExtractFileExt(OD.FileName)) = '.jpg' then
  begin
    JpgIF.LoadFromFile(OD.FileName);
    Img1.Picture.Bitmap.Assign(JpgIF);
  begin
    if LowerCase(ExtractFileExt(OD.FileName)) = '.bmp' then
    begin
      BmpIF.LoadFromFile(OD.FileName);
      Img1.Picture.Bitmap.Assign(BmpIF);
    //etc...
  JpgIF.Free;
  BmpIF.Free;
                Instead of creating all possible kinds of graphic classes, just use Img1.Picture.LoadFromFile(OD.FileName) which determines the appropriate graphic class automatically.
– NGLN
                May 12, 2013 at 17:38
                I am not familiar with your sentence structure. Could you please describe the problem in a more readable manner? I.e. What is your question?
– NGLN
                May 12, 2013 at 17:39
                I added support for *. psd so TImage can not do that it. This I do not know what the file on your PC through the same thing. MH : Media Fire FS : 573KB Scanned with Avira 205.196.123.160/058dmsd4dctg/tu7y6jcbdh32obt/ZN+SAM.zip
– X-88
                May 12, 2013 at 19:56

You need to add Jpeg, GIFImg, PngImage to uses that allows reading and writing these file types.
I have forgotten if GIFImg and PngImage is distributed with Delphi 7 so if these units are not available you need to obtain other units that provide support for the file types you want to open such as GraphicsEx.

The OpenDialog.DefaultExt contains the default extension to add to the filename if the user omits the extension when a file is saved. Only use one extension for the defaultext property. Only add file types to the filter that have a corresponding unit in uses unless there is a third-party unit that provides additional TGraphic filetype support in uses (GraphicEx or ImageEn for example).

Uses Jpeg, GIFImg, PngImage;
OD.DefaultExt := 'jpg';
// or
OD.DefaultExt := GraphicExtension(TJpegImage);
OD.Filter := 'JPG|*.jpg|Jpeg|*.jpeg|PNG|*.png|GIF|*.gif|Bmp|*.bmp';

If a third-party unit is used such as GraphicsEx, then you can add the units supported file types to the filter. You can download GraphicEx here: http://www.soft-gems.net/index.php/all-downloads.

Uses GraphicEx;

If you use ImageEn then add ImageEnIO to uses and then register the file formats provided by ImageEnIO in OnFormCreate and unregister the file formats in OnFormDestroy:

Uses ImageEnIO;
procedure TForm1.FormCreate(Sender: TObject);
begin
  { Register ImageEnIO file types to TGraphic }
  ImageEnIO.IERegisterFormats;
  OD.Filter := GraphicFilter(TGraphic);
procedure TForm1.FormDestroy(Sender: TObject);
begin
  { UnRegister ImageENIO file types }
  IEUnRegisterFormats;
                if I add the code like this, whether it will work well? <pre> var     I: Integer; begin     OD.Filter: = 'jpg | . Jpg | BMP | *. Bmp'; for I: = 0 to OD.FilterIndex - 1 do begin case I of     0:     OD.DefaultExt: = '. Jpg';     1:     OD.DefaultExt: = '*. Bmp'; end;  end; <code>   soft-gems.net/index.php/all-downloads is this free?
– X-88
                May 12, 2013 at 17:43
                yes I know, it's just part of who I missed, when I type it, sorry about my english, because I use the Google translator Translator
– X-88
                May 12, 2013 at 18:05
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.