FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

textBox and Labels are not being updated in a foreach loop

 
Post new topic   Reply to topic     Forum Index -> DFL
View previous topic :: View next topic  
Author Message
jicman



Joined: 22 Dec 2004
Posts: 298
Location: Rochester, NY

PostPosted: Mon Dec 24, 2007 12:43 pm    Post subject: textBox and Labels are not being updated in a foreach loop Reply with quote

Greetings.

Now that I have the ProgressBar to work, Smile, I want to say which files are being worked with. I have this code,
Code:
      char[][] allfiles = std.file.listdir(fromDir,"*");
      pBar.minimum = 0;
      pBar.maximum = allfiles.length - 1;
      pBar.step = 1;
      foreach(char[] f; allfiles)
      {
        info.text = "moving " ~ f;
        txtNotes.text = "moving " ~ f;
        //msgBox(f);  // with this one uncommented, it works...
        std.c.time.msleep(50);
        if (f == "Thumbs.db:encryptable")
        {
          OpenWindowsExplorer(fromDir);
          msgBox("Please search from within the directories for a file name\n\n" ~
                 "'Thumbs.db:encryptable'\n\n and delete it.  After deleting it, click OK.");
          pBar.performStep();
          continue;
        }
        char[] fn = GetFileName(f);  // To file
        if (fn == "Thumbs.db")
        {
          try
          {
            info.text = "deleting " ~ f;
            std.c.time.msleep(50);
            std.file.remove(f);
          }
          catch (FileException e)
          {
            error.text = "Error deleting file: " ~ e.toString();
            std.c.time.msleep(50);
          }
          pBar.performStep();
          continue;
        }
        char[] ffile = toDir[0 .. 1] ~ f[1 .. $];
        char[] fdir = std.path.getDirName(f);
        char[] tdir = std.path.getDirName(ffile);
        CreateDirectory(tdir);
        try
        {
          std.file.rename(f,ffile);
        }
        catch (FileException e)
        {
          error.text = "Error moving file: " ~ e.toString();
          std.c.time.msleep(50);
        }
        pBar.performStep();
      }
      pBar.value = 0;

which works fine, with the exception that the setting of the info.text and txtNotes.text do not get displayed with the values I am assigning. Apparently, it may be too fast for the values to be placed there, but I have placed big files in the directories, so that it takes a while to move, but the values of info.text, error.text (which are labels) and txtNotes.text do not get updated with the info. The progress bar is working like a charm, now I need the info, error and txtNotes to update. Oh, if I uncomment the msgBox after the assignment, it displays the values, which makes me think that there is some kind of speed problem with displaying them. I also tried setting some small wait time, but that does not work either... These three (error, info and txtNotes were created by entice.)

Any help would be greatly appreciated.

thanks,

jose
Back to top
View user's profile Send private message
Chris Miller



Joined: 27 Mar 2004
Posts: 514
Location: The Internet

PostPosted: Thu Dec 27, 2007 10:51 pm    Post subject: Re: textBox and Labels are not being updated... Reply with quote

You can use Application.doEvents(); to allow other events (like paint) to be processed.
Back to top
View user's profile Send private message
jicman



Joined: 22 Dec 2004
Posts: 298
Location: Rochester, NY

PostPosted: Fri Dec 28, 2007 3:24 pm    Post subject: Reply with quote

Thanks, Chris.

New working code...
Code:
      char[][] allfiles = std.file.listdir(fromDir,"*");
      pBar.minimum = 0;
      pBar.maximum = allfiles.length - 1;
      pBar.step = 1;
      foreach(char[] f; allfiles)
      {
        Application.doEvents(); // Don't lock up the window.
        info.text = "moving " ~ f;
        txtNotes.text = "moving " ~ f;
        //msgBox(f);  // with this one uncommented, it works...
        std.c.time.msleep(50);
        if (f == "Thumbs.db:encryptable")
        {
          OpenWindowsExplorer(fromDir);
          msgBox("Please search from within the directories for a file name\n\n" ~
                 "'Thumbs.db:encryptable'\n\n and delete it.  After deleting it, click OK.");
          pBar.performStep();
          continue;
        }
        char[] fn = GetFileName(f);  // To file
        if (fn == "Thumbs.db")
        {
          try
          {
            info.text = "deleting " ~ f;
            std.c.time.msleep(50);
            std.file.remove(f);
          }
          catch (FileException e)
          {
            error.text = "Error deleting file: " ~ e.toString();
            std.c.time.msleep(50);
          }
          pBar.performStep();
          continue;
        }
        char[] ffile = toDir[0 .. 1] ~ f[1 .. $];
        char[] fdir = std.path.getDirName(f);
        char[] tdir = std.path.getDirName(ffile);
        CreateDirectory(tdir);
        try
        {
          std.file.rename(f,ffile);
        }
        catch (FileException e)
        {
          error.text = "Error moving file: " ~ e.toString();
          std.c.time.msleep(50);
        }
        pBar.performStep();
      }
      pBar.value = 0;


thanks again.

jic
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> DFL All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group