AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Sprachen und Entwicklungsumgebungen Object-Pascal / Delphi-Language Prism Application non responsive with Progress Bar
Thema durchsuchen
Ansicht
Themen-Optionen

Application non responsive with Progress Bar

Ein Thema von FaNIX · begonnen am 1. Feb 2008 · letzter Beitrag vom 1. Feb 2008
Antwort Antwort
FaNIX

Registriert seit: 8. Okt 2007
36 Beiträge
 
#1

Application non responsive with Progress Bar

  Alt 1. Feb 2008, 06:25
Hi guys!

Hope you all doing well. I have a question, hope someone can guide me in the right direction.

I have a VCL.Net form, with a progress bar on it, nothing out of the ordinary... I then have a another class, lets call it updatelibrary.pas, which is a normal TObject class. What the UpdateLibrary.pas class does is:

It opens a FTP connection, get a list of all files,and then download them from the ftp site to the application folder, now this works just fine, but the problem is, when the ftp transfer begins, the main application becomes unresponsive, like most application that doesn't use threads. I added some code to the UpdateLibrary class so that it updates a progress bar on the main form, but because the main form is unresponsive, the progress bar doesn't move at all.

Any advice on what I can do? Please note that i don't have to use the FTP onProgress/onTransfer(whatever it is) event to indicate the transfer progress, I will control the progress bar with my own code, i just want the progress to reflect on the main form.

If threads is the answer, please give me an example of how my class can be converted of including in a thread, as I've thread to work with threads, but for some reason my application still remains unresponsive, so im not doing it correctly, lol...

Thanks, hope to get some feedback on this.
  Mit Zitat antworten Zitat
Benutzerbild von sniper_w
sniper_w

Registriert seit: 11. Dez 2004
Ort: Wien, Österriech
893 Beiträge
 
Delphi 6 Enterprise
 
#2

Re: Application non responsive with Progress Bar

  Alt 1. Feb 2008, 06:34
Hi
I am pretty much sure that threads are the answer to your problem. It would be very helpfull if you could show some of your code so that one could give you more specific answer.
Katura Haris
Es (ein gutes Wort) ist wie ein guter Baum, dessen Wurzel fest ist und dessen Zweige in den Himmel reichen.
  Mit Zitat antworten Zitat
FaNIX

Registriert seit: 8. Okt 2007
36 Beiträge
 
#3

Re: Application non responsive with Progress Bar

  Alt 1. Feb 2008, 06:53
Sure...

Button code that creates an instance of the class, and calls the Update_Appl_Libraries method that connects to the ftp, transfers the files, and updates the progress bar on the main form.


Delphi-Quellcode:
type
  TForm3 = class(TForm)
    Button1: TButton;
    MainProgress: TProgressBar;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    { Private declarations }
      fo_Conn : TADOConnection;
  public
    { Public declarations }
  end;

var
  Form3: TForm3;

Button code that creates the instance of the class
Delphi-Quellcode:
procedure TForm3.Button1Click(Sender: TObject);
var
  oUpdateLib : Tdte_Update_Library_DB;
begin

   oUpdateLib := Tdte_Update_Library_DB.Create(Fo_Conn);

   //Set the Progress Bar on the main form to a class reference
   oUpdateLib.Set_Progress_Bar := MainProgress;

   if oUpdateLib.Update_Appl_Libraries then
   begin
      ShowMessage('Updates was installed, application will now restart.');
   end;

end;
Delphi-Quellcode:


Class Method:


  private
    Fo_ProgressBar : TProgressBar;

  public
    property Set_Progress_Bar : TProgressBar READ Fo_ProgressBar WRITE Fo_ProgressBar;


{==============================================================================}
function Tdte_Update_Library_DB.Update_Appl_Libraries : Boolean;
var
  oQry : TADOQuery;
  sResult : String;
  oFile_Version : Assembly;
  oDBFile_Version : System.Version;
  iPosInc : Integer;
  iPos : Integer;
begin

  if Flst_Libraries.Count = 0 then
  begin
    //Calculate the Directory structure of the source Directory.
    CalcDirStructure(Flst_Libraries,sExePath,'*.dll');
    CalcDirStructure(Flst_Libraries,sExePath,'*.exe');
  end;

  try

    oQry := TADOQuery.Create(nil);
    oQry.Connection := Fo_Connection;
    oQry.SQL.Add('select * from lvr_Lib_Version_Ref');
    oQry.Open;

    Fo_ProgressBar.Position := 0;
    iPosInc := Round(100 / oQry.RecordCount);
    iPos := iPosInc;

    while not oQry.Eof do
    begin
      Fo_ProgressBar.Position := iPos;

      if FileExists(sExePath + oQry.FieldByName('lvr_Library').AsString) then
      begin

        oDBFile_Version := System.Version.Create(oQry.FieldByName('lvr_Version').AsString);
        oFile_Version := Assembly.LoadFrom(sExePath + oQry.FieldByName('lvr_Library').AsString);

        if oDBFile_Version.CompareTo(oFile_Version.GetName.Version) > 0 then
        begin
          Move_Old_Lib(oQry.FieldByName('lvr_Library').AsString);

          f_fdn_b_FTP_File(Fs_FTP_Host,
                           Fs_FTP_User,
                           Fs_FTP_Pass,
                           Fs_FTP_Folder_Get + oQry.FieldByName('lvr_Library').AsString,
                           sExePath + oQry.FieldByName('lvr_Library').AsString,
                           sResult,21,'GET');
          Result := True;
        end;

      end
      else
      begin //File does not exist on local machine,so just copy it.

        f_fdn_b_FTP_File(Fs_FTP_Host,
                         Fs_FTP_User,
                         Fs_FTP_Pass,
                         Fs_FTP_Folder_Get + oQry.FieldByName('lvr_Library').AsString,
                         sExePath + oQry.FieldByName('lvr_Library').AsString,
                         sResult,21,'GET');
        Result := True;

      end;

      FreeAndNil(oDBFile_Version);
      FreeAndNil(oFile_Version);

      oQry.Next;
      iPos := iPos + iPosInc;
    end;
    
  finally
    FreeAndNil(oQry);
    Fo_ProgressBar.Position := 0;
  end;

end;
  Mit Zitat antworten Zitat
Nuclear-Ping
(Gast)

n/a Beiträge
 
#4

Re: Application non responsive with Progress Bar

  Alt 1. Feb 2008, 09:56
1) Thats no .NET code
2) Tryed Application.ProcessMessages?
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 11:30 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz