#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    12
    Rep Power
    0

    Problem when canceling OpenPictureDialog


    Hello,

    I have this problem.
    When I open "OpenPictureDialog" and click Cancel Button i get this message UNKNOWN PICTURE FILE EXTENSION (.)
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2008
    Posts
    355
    Rep Power
    7
    Without posting the code that causes the error, at best we can only guess as to what is happening.

    Given that, my guess is that you are not "Executing" the dialog correctly.

    Code:
    if OpenPictureDialog.Execute then
    begin
       //the file selected will be in
       //OpenPictureDialgo.FileName
       //only do the "loadfromfile" if the dialog is executed
       //otherwise the user clicked cancel
    end;
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    12
    Rep Power
    0
    Originally Posted by majlumbo
    Without posting the code that causes the error, at best we can only guess as to what is happening.

    Given that, my guess is that you are not "Executing" the dialog correctly.

    Code:
    if OpenPictureDialog.Execute then
    begin
       //the file selected will be in
       //OpenPictureDialgo.FileName
       //only do the "loadfromfile" if the dialog is executed
       //otherwise the user clicked cancel
    end;

    Sorry about code.
    here it is
    procedure TFMain.ChooseClick(Sender: TObject);
    var
    sDir : string;
    begin
    DBImage1.Height:= 200;
    dbImage1.Width:= 175;
    OpenPictureDialog1.Filter:= '*.bmp|*.bmp|*.jpg|*.jpg';
    OpenPictureDialog1.Execute;
    sDir := OpenPictureDialog1.FileName;
    DBImage1.Picture.LoadFromFile(sDir);
    end;
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2008
    Posts
    355
    Rep Power
    7
    You need to test to see if the user actually executed the dialog box (hits the ok button, vs. the cancel button.
    Code:
    procedure TFMain.ChooseClick(Sender: TObject);
    var
      sDir : string;
    begin
      DBImage1.Height:= 200;
      dbImage1.Width:= 175;
      OpenPictureDialog1.Filter:= '*.bmp|*.bmp|*.jpg|*.jpg';
      if OpenPictureDialog1.Execute then
      begin
        sDir := OpenPictureDialog1.FileName;
        DBImage1.Picture.LoadFromFile(sDir);
      end;
    end;
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    12
    Rep Power
    0
    Thank you.

    It's Working.

IMN logo majestic logo threadwatch logo seochat tools logo