Topenpicturedialog does not take the path from the Images folder

Asked

Viewed 330 times

0

I have in my form a component TOpenPictureDialog to open the Images on a system, only instead of it taking the full path of the image file it only takes the alias.
Ex

  • How I need : 'C: Users User-03 Pictures.jpg file'
  • As he is coming: 'Images LOGO CMR.Jpg'

I’ve tried to see all the options in Vcl.Dialogs.Topenoptions and Vcl.Dialogs.Topenoptionsex and found nothing... How can I do it?

Picture of how it’s coming inserir a descrição da imagem aqui

procedure TfrmManutencaoParametros.opdParametrosSelectionChange(Sender: TObject);
begin
  // Muda a imagem no Quadro de imagens
  if opdParametros.FileName <> '' then
  begin
    inherited;
      ...
      ...
      ...
      ImgLogo.Picture.LoadFromFile(opdParametros.FileName);
  end;
end;
  • Are you trying to extract the path with which property? Using OpenPictureDialog1.FileName in Delphi 7 (version I have), returns the whole path as you need + the file name... If it works on your version, just extract the file name...

  • Enter your code for more details.

  • @Melissa, I’m using Openpicturedialog1.Filename

  • Edu, put in the full code

  • @Robertodecampos here the complete code...

  • Have you ever tried to build a simple project to see if it gives the same problem? Because only with this code request you can’t verify where the error is. And putting more code will only leave your question polluted.

  • Yes, and I’ve also checked the forums to see if I can find an answer and nothing. http://www.activedelphi.com.br/forum/viewtopic.php?t=85939&sid=ff049e947038cab60a0cab989c285b4a

Show 2 more comments

2 answers

1

Here’s an example of how I use this component. Dir is a variable I create to play the name of the directory.

-- Beginning --

if Dir = '' then
begin
  Dir := 'C:\';
end else
begin
  OpenPictureDialog1.InitialDir := DIR;
end;

OpenPictureDialog1.Execute;
Edit1.Text := ExtractFileName(OpenPictureDialog1.FileName);
Dir := ExtractFilePath(OpenPictureDialog1.FileName) + Edit1.text;
Edit1.Text := Dir;

-- End --

In case it doesn’t work, please report the error here so I can help. The component also has a property called InitialDir, try to put the default directory path there in case it will not change.

  • That I already know and I’m already doing is just not bringing the right way.

  • 1

    Sorry for the "silly" question (I’m without pc at the moment so I can’t test this right now and I never thought to test what I’m going to ask), but have you ever tried to choose the "C:/user/images/..." path or are you going straight to folder images by library? I’ve never tested to see if they behave differently in these two ways.

  • I’m going straight to the folder because it doesn’t make sense for the user to go doing the full route.

1

Try this:

uses ...
  System.Types, System.IOUtils;

...
...

procedure TForm1.Button1Click(Sender: TObject);
Var
  Dlg: TOpenPictureDialog;
begin
  Dlg := TOpenPictureDialog.Create(Self);
  try
    with Dlg do
      begin
        InitialDir:= TPath.GetPicturesPath;
        if Execute then
          Image1.Picture.LoadFromFile(FileName);
      end;
  finally
    Dlg.Free;
  end;
end;
  • I really don’t know what’s going on, I don’t know if it’s Delphi CE or my pc I don’t know... it’s back to error... ...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.