TOpenPictureDialog does not take the path to the Images folder

0

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

  • How do I need: ' C: \ Users \ User-03 \ Pictures \ File.jpg
  • How it is coming: ' Images \ LOGO CMR.Jpg
  • '

I've tried to see all the options in Vcl.Dialogs.TOpenOptions and < and I did not find anything ... How can I do this? p>

Image of how it's coming

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;
    
asked by anonymous 05.10.2018 / 21:23

2 answers

1

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

- Home -

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 -

If it does not work, please let me know 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 is not to be changed.

    
05.10.2018 / 22:22
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;
    
06.10.2018 / 19:42