Recent

Author Topic: [SOLVED] something is funny between 1.2 and 1.4 Lazarus  (Read 15821 times)

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9874
  • Debugger - SynEdit - and more
    • wiki
Re: something is funny between 1.2 and 1.4 Lazarus
« Reply #15 on: April 25, 2015, 05:19:12 pm »
Maybe I found it.
I looked for you debug screen grab, and that imagefile is the empty string.

From your code I see that in this case , you want the current dir "SetCurrentDir()"

Then I tested (on win)
  SetCurrentDir('C:\');
  FindAllFiles('', '*', false));

with 1.2: returns the content of c:\
with 1.4: empty

I do not know, if the 1.2 behaviour was documented, and intended behaviour. So I do not know if 1.2 or 1.4 is right.

Try reporting it as a bug, and see what the answer is.

-------
In the meantime, with this info you can work around the issue by changing your code and passing the full dir to FillImageList




Bart

  • Hero Member
  • *****
  • Posts: 5290
    • Bart en Mariska's Webstek
Re: something is funny between 1.2 and 1.4 Lazarus
« Reply #16 on: April 25, 2015, 05:53:17 pm »
I encounterd another problem.
When I do not succeed in selecting a directory within the secified interval from the timer, I get another showmessage and another selectdirectorydialog and this goes on and on and on.

I think you should supply Form1.CurrentDir to FindAllFiles as the path to search.
I do not really see the point actually changing the current directory.

Better refactor that.

Bart

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9874
  • Debugger - SynEdit - and more
    • wiki
Re: something is funny between 1.2 and 1.4 Lazarus
« Reply #17 on: April 25, 2015, 06:08:51 pm »
this looks to me that it makes it only look in C:\ and not in any subdirectories therefore if you do not have any files just Directories on C:\ then it will not pick up any files because all you have are directories. therefore it too would return an empty List -- does that make sense to you? the "false" tells it no subdirectories where true is the opposite look in the subdirectories

I have files in C:\ and 1.2 did find them

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: something is funny between 1.2 and 1.4 Lazarus
« Reply #18 on: April 25, 2015, 06:19:28 pm »
this looks to me that it makes it only look in C:\ and not in any subdirectories therefore if you do not have any files just Directories on C:\ then it will not pick up any files because all you have are directories. therefore it too would return an empty List -- does that make sense to you? the "false" tells it no subdirectories where true is the opposite look in the subdirectories

I have files in C:\ and 1.2 did find them

did you take a look at me prior post with images -- 1.4.0 is not letting me get past the " whereas 1.2.6 is they are both showing the same data on the initial loading of the list. where 1.2.6 gets past it without the out of bounds error then load the image file next when I move the middle wheel button on the mouse to cycle the images

1.4.0 throws an error instead
Yes there was a bug in 1.2.x which is now corrected. Work around it and keep coding.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

Bart

  • Hero Member
  • *****
  • Posts: 5290
    • Bart en Mariska's Webstek
Re: something is funny between 1.2 and 1.4 Lazarus
« Reply #19 on: April 25, 2015, 06:48:51 pm »
Hi,

I attached new versions of main1.pas and functions1.pas.
It sort of works now.

I created an instance of ImageList at programstart and kept it alive, only destroying it at prorams end.
I used the overloaded version of FindAllFiles that accepts a TStrings parameter, this way it's much easier to keep track of what is created and where.
Don't call ExtractFilePath on the result of SelectDirectory(), because it will remove the final directory (c:\foo\bar becomes c:\foo) and you'll end up searching the wrong directory.
I exit the CycleImages method if no files are found, you'll need to do the same in CycleBack.
I refactored the functions in functions1.pas to accept parameters (for directory and imagelist), so that the unit does not depend on the main unit of the program.

There are still several issues.
If SetBackGround fails, then a dialog pops up, but the timer is not stopped, so this can lead to several dialogs put over each other, not very nice.

Clicking Set Time in seconds from the popup menu gives me an instant crash.

Bart
« Last Edit: April 25, 2015, 07:04:50 pm by Bart »

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9874
  • Debugger - SynEdit - and more
    • wiki
Re: something is funny between 1.2 and 1.4 Lazarus
« Reply #20 on: April 25, 2015, 06:59:55 pm »
did you take a look at me prior post with images -- 1.4.0 is not letting me get past the " whereas 1.2.6 is they are both showing the same data on the initial loading of the list. where 1.2.6 gets past it without the out of bounds error then load the image file next when I move the middle wheel button on the mouse to cycle the images

1.4.0 throws an error instead

The Image "just after loading list - 1.4.0 - Screenshot - 04252015 - 10:49:59 AM.png" ?

I downloaded your sample, then choose "Set Dir" in popup menu, selected a dir with images.
Then on mouse wheel I get an exception on the line, as in the image.

Add to your watches: ImageList.fcount 
It is zero. So accessing element 0 is not possible.

That is because FindAllFiles does no longer use CurrentDir. Exactly what I wrote before

The below works around the issue.
Code: [Select]
procedure FillImageList;
var
  s: String;
begin                                                                          //no sub directory -
  s := ExtractFilePath(Form1.ImageFile);
  if s = '' then s := Form1.CurrentDir;
  Form1.ImageList := FindAllFiles(s, '*.jpg; *.png', false);
  Form1.ImageList.Sort;
end;


As suggested, feel free to open a bug report.

Bart

  • Hero Member
  • *****
  • Posts: 5290
    • Bart en Mariska's Webstek
Re: something is funny between 1.2 and 1.4 Lazarus
« Reply #21 on: April 25, 2015, 07:35:28 pm »
... thanks but still with my debugging the 1.4.0 is not adding files to the ImageList whereas 1.2.6 is -- something is not right with that

As was pointed out to you this is because you supply an empty path to FindAllFiles.
See my fix, I supply CurrentDir as the path.

It is debatable wether the old (1.2.x) behaviour was better.
One could argue that supplying an empty string or the path should mean to search in the current directory, much like FindFirst does.
I don't have 1.2 around anymore so I cannot test how it behaved (what I gather from the posts here it used to search the root directory if the path was an empty string, that would be strange behaviour).

So,maybe you can test this for us in a test program:
Code: [Select]
  AList := FindAllFiles('','*',false);

Run it from a console (so you know waht the current directory is, and please do not start it from root directory) and report back.

Bart

munair

  • Hero Member
  • *****
  • Posts: 798
  • compiler developer @SharpBASIC
    • SharpBASIC
Re: something is funny between 1.2 and 1.4 Lazarus
« Reply #22 on: April 25, 2015, 07:46:15 pm »

As suggested, feel free to open a bug report.

reading Lazarus http://wiki.freepascal.org/How_do_I_create_a_bug_report now what do you suggest it goes under? and how do I know it has not been reported already as their page suggests one looks up first -- their is a lot of reports to look at to try and figure that out

http://bugs.freepascal.org/view_all_bug_page.php

I am still a virgin on bug reporting  %) this will be my first time  :-\

There is a first time for everything. :)
keep it simple

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: something is funny between 1.2 and 1.4 Lazarus
« Reply #23 on: April 25, 2015, 08:05:40 pm »
Code: [Select]
procedure TForm1.Button1Click(Sender: TObject);
begin
    try
       if (SelectDirectory(Form1.CurrentDir, [sdPrompt], 0 ) = true)
        then
           begin
            SetCurrentDir(Form1.CurrentDir);
            FileList := FindAllFiles(ExtractFilePath(SomeFile), '*.jpg;*.png', false);
            FileList.Sort;
            Label1.Caption:=IntToStr(FileList.Count);
            Label1.Caption:=SomeFile;
           end;
       except
             on E: Exception do
             ShowMessage('Exception! '+E.Message);
       end;
end; 
Is this demo supposed to work? I don't think so: "SomeFile" is not initialized, i.e. it is empty. And ExtractFilePath returns an absolute path, i.e. the selection of the CurrentDir is ignored.

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: something is funny between 1.2 and 1.4 Lazarus
« Reply #24 on: April 25, 2015, 08:30:24 pm »
Because you did not initialize SomeFile, it is empty, and ExtractFilePath(SomeFile) is empty as well.
Therefore, you are calling "FindAllFiles('', '*.jgp;*.png', false)". The first parameter, the empty string, is the directory which is search for the jpg and png files. Since it is an empty string it does not exist and no files can be found. Therefore the result of Laz 1.4 is correct.

I can confirm that the FindAllFiles of Laz 1.2 does report files in the folder with the empty file name. Probably it inserts the current directory for the empty folder name. This is clearly a bug.

In total, the problem is that your program logic contains a bug (not initializing "SomeFile") which did not show up in Laz 1.2 because of a bug in Laz 1.2. After fixing this bug in Laz 1.4 you are faced with the old hidden bug in your program logics.

Bart

  • Hero Member
  • *****
  • Posts: 5290
    • Bart en Mariska's Webstek
Re: something is funny between 1.2 and 1.4 Lazarus
« Reply #25 on: April 25, 2015, 08:33:55 pm »
I implemented searching current directory in FindAllFiles if searchpath is an empty string in r48854 and asked for it to be merged to 1.4.2.

Mind you: wp is right. Supplying an initialized path to FindAllFiles is the proper way to go.

Bart

Bart

  • Hero Member
  • *****
  • Posts: 5290
    • Bart en Mariska's Webstek
Re: something is funny between 1.2 and 1.4 Lazarus
« Reply #26 on: April 25, 2015, 08:42:04 pm »
You keep making the same mistakes:
Do not call ExtractFilePath here.
If user selects /foo/bar, you will search /foo !

You should not call SetCurrentDirectory to make the code work whilst supplying an empty searchpath. It's just sloppy programming (and not guaranteed to work on all platforms). You already asked the user or the directory, so just supply that to FindAllFiles. It makes sense, and it makes the code better readable (at least or others).

Please try to learn something from us.

Bart

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: something is funny between 1.2 and 1.4 Lazarus
« Reply #27 on: April 25, 2015, 09:03:39 pm »
Quote
calling that function sets it so that FindAllFiles knows where to look
No - FindAllFiles looks in the folder which is specified as the first parameter, and this is an empty string in your case

Bart

  • Hero Member
  • *****
  • Posts: 5290
    • Bart en Mariska's Webstek
Re: something is funny between 1.2 and 1.4 Lazarus
« Reply #28 on: April 25, 2015, 09:04:43 pm »
I give up.
Obviously you are unable to learn from more experienced programmers (not just me).

The behaviour of FindAllFiles that used to work in 1.2.6 was not documented as such.
Therefore the behaviour of that function is undefined if you supply an empty path.

I would strongly encourage you to move to C, because it is so much easier to shoot yourself in the foot with that language, which seems to be something that you like to do.

Bye.

Bart

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: something is funny between 1.2 and 1.4 Lazarus
« Reply #29 on: April 25, 2015, 09:16:53 pm »
You seem to like writing more than reading. I follow Bart.

 

TinyPortal © 2005-2018