Page 1 of 1

latest version in Delphi and Lazarus issue

Posted: Fri Aug 17, 2018 5:36 pm
by snorkel
Hi,
I ported my old app from Delphi 2009 to Lazarus but I am having a issue with a embedded component that shows a image thumbnail and when the user clicks the thumbnail it uses shellexecute in the embedded control to view the image.
The problem is when I do this it corrupts all the menus in my application.
It also does it in the latest Delphi community edition.
The embedded control is from one of your examples and is called imagebutton.pas

If I remove the shellexecute it does not corrupt the menus.


Capture.PNG
Capture.PNG (38.03 KiB) Viewed 18140 times

Code: Select all

procedure TImgButton.open;
var
   tpath,fpath:string;
   outstream:tmemorystream;
begin
      //Save the file to temp directory and use shell execute to open it.
      tpath:=GetTempPath;
      fpath:= format('%s%s',[tpath,ffile_name]);
      outstream:=tmemorystream.Create;
      try
         try
            fstream.Position:=0;
            ZDecompressStream(fstream,outstream);
            outstream.Position:=0;
            outstream.SaveToFile(fpath);
            ShellExecute(0, nil, pchar(fpath), nil, nil, SW_SHOWNORMAL);
         except
               on e:EZDecompressionError do
                  raise exception.Create('TFileButton.open zlib error:'+e.Message);
               on e:Exception do
                  raise;
         end;
      finally
       outstream.Free;
      end;
end;

Re: latest version in Delphi and Lazarus issue

Posted: Fri Aug 17, 2018 9:22 pm
by Sergey Tkachenko
Sorry, I do not remember an example with imagebutton.pas. Are you sure that it is from our examples?

A memory may be corrupted somehow. What's the code of GetTempPath?

Re: latest version in Delphi and Lazarus issue

Posted: Tue Aug 21, 2018 3:31 pm
by snorkel
Hi Sergey,
I was actually this ( I modified it to embedded a image instead of a wav and called the new one timagebutton :

{*******************************************************}
{ }
{ TWavButton }
{ Button playing WAV file on click }
{ }
{ Copyright (c) Sergey Tkachenko }
{ [email protected] }
{ http://www.trichview.com }
{ }
{*******************************************************}

Re: latest version in Delphi and Lazarus issue

Posted: Tue Aug 21, 2018 3:50 pm
by snorkel
the temp dir function just calls GetTempDir in sysutils.

I found that in Delphi and Lazarus if I enable the DPI aware option in the project manager the menu corruption goes away.
With DPI aware disabled it only does the corruption if shellexecute opens a image file. Anything else like a URL, some other file like a word doc etc and it's fine.
This is on windows 7, I will have to try it on windows 10 and see if it does the same thing. I could be that some common DLL is being used that the windows image viewer also uses and it's a bug in the windows image viewer.

Also thanks for porting it to Lazarus, I have my app completely ported over and it works spectacular.
Capture.PNG
Capture.PNG (228.73 KiB) Viewed 18078 times