DonationCoder.com forum
 
Read-only archive. This is a static copy of the DonationCoder.com forum. Reading and searching work as before; logging in, posting and private messages do not.
Archive of 2026-10-21 · About this archive · Main site

Author Topic: My Application...  (Read 21,611 times)

Codebyte

  • "Premature Optimization is the root of all evil."
  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 160
    • Participated in NANY Challenge Once
    • Coding Snacks
    • Plugin Coding Medal
My Application...
« on: January 08, 2008, 04:25 AM »
Im using BCB 2007 to code my application for windows vista... My app connects to a declared ftp server just fine, but when it begins to download files it locks the application up until the download is done... Is there some kind of coding that I can add to allow my program to run fine?

Any help is greatly appreciated... thnx :)
CodeByter.com - http://www.codebyter.com

jazper

  • Coding Snacks Author
  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 92
    • Coding Snacks
Re: My Application...
« Reply #1 on: January 08, 2008, 04:32 AM »
Are you using Indy's FTP client component to achieve this?  You could run all your FTP work in a background thread thus freeing up the UI processing.


Codebyte

  • "Premature Optimization is the root of all evil."
  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 160
    • Participated in NANY Challenge Once
    • Coding Snacks
    • Plugin Coding Medal
Re: My Application...
« Reply #2 on: January 08, 2008, 01:50 PM »
Yes, Im using Indy's FTP client and thats a wonderful idea... I have no idea how to go about doing this though, anyway you could write a quick example or have a tutorial I could check out? Any time would greatly be appreciated alot :)
CodeByter.com - http://www.codebyter.com

jazper

  • Coding Snacks Author
  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 92
    • Coding Snacks
Re: My Application...
« Reply #3 on: January 08, 2008, 02:44 PM »
Unfortunately, I'm not a BCB programmer. I asked about Indy because I am a Delphi programmer. I don't think a Delphi example would be of much help to you.  Maybe another BCB programmer on the forums can provide a small example on threading in BCB.





f0dder

  • [Well, THAT escalated quickly!]
  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 9,153
    • Participated in NANY Challenge Once
Re: My Application...
« Reply #4 on: January 08, 2008, 03:01 PM »
Unfortunately, I'm not a BCB programmer. I asked about Indy because I am a Delphi programmer. I don't think a Delphi example would be of much help to you.  Maybe another BCB programmer on the forums can provide a small example on threading in BCB.
Will probably help more than you think - Delphi/ObjectPascal and C++ aren't that different, syntax-wise, and afaik BCB and Deplhi use the exact same VCL (in fact, I recall BCB shipping with a command-line Delphi compiler, probably to facilitate compiling the VCL or third-party components).
- carpe noctem

Codebyte

  • "Premature Optimization is the root of all evil."
  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 160
    • Participated in NANY Challenge Once
    • Coding Snacks
    • Plugin Coding Medal
Re: My Application...
« Reply #5 on: January 08, 2008, 03:12 PM »
BCB does come with a command-line Delphi compiler for 3rd party components and such... If you have a delphi example, I might be able to make out the idea of how to do this, or at least I can try. ty again guys! this is helping a great deal! :)
CodeByter.com - http://www.codebyter.com

f0dder

  • [Well, THAT escalated quickly!]
  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 9,153
    • Participated in NANY Challenge Once
Re: My Application...
« Reply #6 on: January 08, 2008, 03:18 PM »
Threading is simple, anyway.

Right until you need to synchronize access to global data. Then it becomes potentially hellish.
- carpe noctem

Codebyte

  • "Premature Optimization is the root of all evil."
  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 160
    • Participated in NANY Challenge Once
    • Coding Snacks
    • Plugin Coding Medal
Re: My Application...
« Reply #7 on: January 08, 2008, 03:24 PM »
lol, i have no idea how to sychronize access to global data... :( is running FTP in a background thread classified as access to global data? this is entirely new to me
CodeByter.com - http://www.codebyter.com

f0dder

  • [Well, THAT escalated quickly!]
  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 9,153
    • Participated in NANY Challenge Once
Re: My Application...
« Reply #8 on: January 08, 2008, 03:38 PM »
lol, i have no idea how to sychronize access to global data... :( is running FTP in a background thread classified as access to global data? this is entirely new to me
Not necessarily... but if, for instance, your GUI can add a filename to a queue, and the FTP thread grabs filenames from the queue, you will need to synchronize access... check out EnterCriticalSection + LeaveCriticalSection API calls.
- carpe noctem

jazper

  • Coding Snacks Author
  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 92
    • Coding Snacks
Re: My Application...
« Reply #9 on: January 08, 2008, 03:56 PM »
Here you go, this is Delphi.


Form1
  - 3 Edit boxes, named: edServer, edUsername, edPassword
  - 1 Memo box named: edOutput

Code: (delphi)
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Unit2;

type
  TForm1 = class(TForm)
    btnDisconnect: TButton;
    btnConnect: TButton;
    edUsername: TEdit;
    edPassword: TEdit;
    edServer: TEdit;
    edOutput: TMemo;
    procedure btnConnectClick(Sender: TObject);
  private
    { Private declarations }
    ThreadFTP: TidFTPThread;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.btnConnectClick(Sender: TObject);
begin
  ThreadFTP := TidFTPThread.Create(true);
  ThreadFTP.LoginInfo(edUsername.Text, edPassword.Text, edServer.Text);
  ThreadFTP.Resume;

end;

end.


here is the thread class
Code: (delphi)
unit Unit2;

interface

uses
  Classes, SysUtils,IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
  IdExplicitTLSClientServerBase, IdFTP;

type
  TidFTPThread = class(TThread)
  private
    { Private declarations }
    Fftp: TidFTP;
    FUser: string;
    FPass: string;
    FServer: string;
    FMemoMessage: string;
  public
    procedure LoginInfo(User, Pass, Server: string);
  protected
    procedure Execute; override;
    procedure UpdateMemo;
  end;

implementation

uses Unit1;

{ TidFTPThread }

procedure TidFTPThread.LoginInfo(User, Pass, Server: string);
begin
  FUser := User;
  FPass := Pass;
  FServer := Server;



end;

procedure TidFTPThread.UpdateMemo;
begin
  Form1.edOutput.Lines.Add(FMemoMessage);
end;

procedure TidFTPThread.Execute;
begin
  FMemoMessage := 'Connecting to ' + FServer;
  Synchronize(UpdateMemo);
  Fftp := TidFTP.Create(nil);
  Fftp.Username := FUser;
  Fftp.Password := FPass;
  Fftp.Host := FServer;
  try
    try
      Fftp.Connect;

      FMemoMessage := 'Connected to ' + FServer + #13#10 + 'Changing directory';
      Synchronize(UpdateMemo);

      Fftp.ChangeDir('<CHANGE TO DIR WHERE YOU NEED FILE>');

      FMemoMessage := 'Getting file...';
      Synchronize(UpdateMemo);

      Fftp.Get('<SOURCE FILENAME>','<DEST FILENAME>', true, false);

      Fftp.Disconnect;

      FMemoMessage := 'Disconnecting from ' + FServer;
      Synchronize(UpdateMemo);

    except on E:Exception do
      begin
        FMemoMessage := E.Message;
        Synchronize(UpdateMemo);
      end;
    end;
  finally
    Fftp.Free;

  end;
end;

end.




Hopefully this helps.

Codebyte

  • "Premature Optimization is the root of all evil."
  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 160
    • Participated in NANY Challenge Once
    • Coding Snacks
    • Plugin Coding Medal
Re: My Application...
« Reply #10 on: January 08, 2008, 03:59 PM »
wow, tyvm! this is awesome and im understanding this for the most part! way cool, ty again!
CodeByter.com - http://www.codebyter.com

Codebyte

  • "Premature Optimization is the root of all evil."
  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 160
    • Participated in NANY Challenge Once
    • Coding Snacks
    • Plugin Coding Medal
Re: My Application...
« Reply #11 on: January 08, 2008, 09:43 PM »
Alright, so status update... I wrote my first threaded program that uses 2 threads, 1 thread that accesses global variables and another thread that downloads files from a list of "Files to be downloaded" lol... This coding helped alot! I do have a question however, what did you use to drop in that coding for me to see? I wanted to upload a sample for people to see how it works in Borland C++ builder...
CodeByter.com - http://www.codebyter.com

jgpaiva

  • Artificial Idiocy
  • Global Moderator
  • Joined in 2006
  • *****
  • Posts: 4,727
    • Cody Award
    • Participated in NANY Challenge Once
    • Coding Snacks
    • Portugal Inhabitant
    • Linux User
Re: My Application...
« Reply #12 on: January 08, 2008, 10:02 PM »
It's simple, CodeByte!
Just copy the code from your editor, then paste it on the reply box. Then select all the code, and press the # button, which will enclose the code in [code] tags.

PS: if you'd like to have syntax highlighting, press the # button, and then add =cpp to the [code], so that is looks like this:

[code=cpp]
int main void(){
whatever
}
[/code]

Codebyte

  • "Premature Optimization is the root of all evil."
  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 160
    • Participated in NANY Challenge Once
    • Coding Snacks
    • Plugin Coding Medal
Re: My Application...
« Reply #13 on: January 09, 2008, 01:09 AM »
thats way cool! ill upload the coding once I finish a basic template for multithreading in BCB 2007. ty for all the help guys!
CodeByter.com - http://www.codebyter.com

Codebyte

  • "Premature Optimization is the root of all evil."
  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 160
    • Participated in NANY Challenge Once
    • Coding Snacks
    • Plugin Coding Medal
Re: My Application...
« Reply #14 on: January 09, 2008, 01:39 PM »
Here is a general idea of Threading for someone new to the concept...

Create a new project and add 2 Buttons, named Suspend and Resume... These will control the Thread using the OnClick() function.

Here is the coding I used along with BCB RAD Studio 2007:
(Keep in mind this is a sample template I wrote...)

Code: (cpp)
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "IdExplicitTLSClientServerBase"
#pragma resource "*.dfm"
TForm1 *Form1;
HANDLE Thread; //THIS IS FOR THE THREAD
//---------------------------------------------------------------------------
DWORD WINAPI ThreadFunc(LPVOID Param)
{
	//Tell the Thread what to do here
}
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
	: TForm(Owner)
{
	DWORD Id;
	Thread = CreateThread(0, 0, ThreadFunc, Form1->Handle, CREATE_SUSPENDED, &Id);
	if(!Thread)
	{
		ShowMessage("Cannot Create Thread!");
		Application->Terminate();
	}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ResumeClick(TObject *Sender)
{
   ResumeThread(Thread);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::SuspendClick(TObject *Sender)
{
   SuspendThread(Thread);	
}
//---------------------------------------------------------------------------

Ill have a sample of how to set priorities between threads soon, once I fully embrace the concept.
CodeByter.com - http://www.codebyter.com
« Last Edit: January 09, 2008, 01:42 PM by Codebyte »

f0dder

  • [Well, THAT escalated quickly!]
  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 9,153
    • Participated in NANY Challenge Once
Re: My Application...
« Reply #15 on: January 09, 2008, 02:22 PM »
Notice that if your thread function exits, the thread is destroyed - generally, a thread will keep looping, often doing "wait for event; process; repeat;".

BCB doesn't have it's own support functions for threading? If it does, it might be best to use those (there can be some "advanced issues" involved that requires per-thread data and other nastiness).

Also, again I must state that if you need to access global variables in read/write fashion, you need synchronization; synchronization bugs can be very hard to spot, and many of them will not show unless you have a dualcore (or quadcore or...) machine, but will blow up at the least expected time :)
- carpe noctem

jazper

  • Coding Snacks Author
  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 92
    • Coding Snacks
Re: My Application...
« Reply #16 on: January 09, 2008, 02:27 PM »
I wanted to share this link as well, it's VERY useful for Delphi developers and it might be useful to BCB developers as well.

"Multithreading - The Delphi Way"
http://codecentral.borland.com/Item.aspx?id=14809





Codebyte

  • "Premature Optimization is the root of all evil."
  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 160
    • Participated in NANY Challenge Once
    • Coding Snacks
    • Plugin Coding Medal
Re: My Application...
« Reply #17 on: January 09, 2008, 04:35 PM »
f0dder, i think you're right, although Im still learning more and more about threads between my college classes lol... I think I remember reading about it though...

btwn: Great Tutorial, Jazper! I really liked it! Everywhere I look, I cant seem to find any useful information and both of the things you have showed me helped alot... I might possibly do a full write-up/tutorial on multithreading from my point of view, someone who is new to the entire concept lol...
CodeByter.com - http://www.codebyter.com

Codebyte

  • "Premature Optimization is the root of all evil."
  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 160
    • Participated in NANY Challenge Once
    • Coding Snacks
    • Plugin Coding Medal
Re: My Application...
« Reply #18 on: January 10, 2008, 09:02 PM »
Bad news: I am getting this error now:
------------------------------------------------
Project F:\Borland Programs\Project1\Debug\VSU.exe faulted with message: 'application-define exception (code 0x0eedfade) at 0x75ecb09e.' Process Stopped. Use Step or Run to continue.

[OK Button]
------------------------------------------------
This is the error I get right after I compile the program. If I goto run the program It gets to the part right before it downloads at says, "VSU.exe has stopped working..." I have no idea what this is, but if anyone could help that would be awesome... Also, if you need anything further, let me know.
CodeByter.com - http://www.codebyter.com

jazper

  • Coding Snacks Author
  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 92
    • Coding Snacks
Re: My Application...
« Reply #19 on: January 10, 2008, 10:17 PM »
Show us some code.  Particularly the code that starts the download, and the code that actually does the downloading.  You may have 2 threads stepping on one another.

Codebyte

  • "Premature Optimization is the root of all evil."
  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 160
    • Participated in NANY Challenge Once
    • Coding Snacks
    • Plugin Coding Medal
Re: My Application...
« Reply #20 on: January 11, 2008, 02:26 AM »
Alright, so to be completely honest... I dont know how this coding will look but please dont kill me... Im a novice... lol! Here is the complete coding... Also, keep in mind that it's no where near finished... I also tried to learn the coding for the threading so bear with me...

Code: (cpp)
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
#include "registry.hpp"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "IdExplicitTLSClientServerBase"
#pragma resource "*.dfm"
TForm1 *Form1;
HANDLE Thread;
int CurrentVersion, counter = 0, ServerVersionOnWeb;
int downloadrate = 0, currentdownloadtotal = 0, previousdownloadtotal = 0, downloadtime = 0, totalrate = 0;
int totaldownloadtotal = 0;
String filename;
bool required = false;
bool start_install = false;
//---------------------------------------------------------------------------
DWORD WINAPI ThreadFunction(LPVOID Param)
{
   //if Memo2 has anything in it, start downloading
   do
   {
	   try
	   {
		   filename = Form1->Memo2->Lines->Strings[0];
		   //get size and update progressbar
		   Form1->ProgressBar2->Max = Form1->FTP1->Size(filename);
		   Form1->ProgressBar2->Position = 0;
		   Form1->FTP1->Get(filename, filename, true, false);
	   }
	   catch(...)
	   {
		   Form1->FTP1->Abort();
		   Form1->FTP1->Disconnect();
		   Application->Terminate();
	   };
   }
   while(Form1->Memo2->Lines->Strings[0] != "");
   if(Form1->Memo2->Lines->Strings[0] == "")
   {
	   required = false;
	   Form1->Label1->Caption = "Overall Progress: Download Complete!";
	   Form1->ProgressBar1->Position += 1;
	   Form1->Timer1->Enabled = false;
	   Form1->Label2->Caption = "File Progress: ";
	   //start next process
       start_install = true;
	   SuspendThread(Thread);
   }
}
//---------------------------------------------------------------------------
void ExitApp(void)
{
	try
	{
	   //Free all open resources, then exit the app
	   Form1->FTP1->Abort();
	   Form1->FTP1->Disconnect();
	   Application->Terminate();
	}
	catch(...){};
}
//---------------------------------------------------------------------------
void FilterMemo12(void)
{
	//filter Memo1
	int x = 0;
	do
	{
		if(Form1->Memo1->Lines->Strings[x] == "")
		{
			Form1->Memo1->Lines->Delete(x);
		}
		else
		{
            x++;
		}
	}
	while(x < Form1->Memo1->Lines->Count);
	//repeat the process for Memo2
	x = 0;
	do
	{
		if(Form1->Memo2->Lines->Strings[x] == "")
		{
			Form1->Memo2->Lines->Delete(x);
		}
		else
		{
            x++;
		}
	}
	while(x < Form1->Memo2->Lines->Count);
	//now allow Threading Process to begin
	Form1->Label1->Caption = "Overall Progress: Downloading Updates...";
	Form1->ProgressBar1->Position += 1;
	Form1->Timer1->Enabled = true;
	Form1->ProgressBar1->Max += Form1->Memo2->Lines->Count;
	required = true;
	//Set Cursor to beginning of Memo1, so user can see top of Memo
	ResumeThread(Thread);
}
//---------------------------------------------------------------------------
void CompareVersions(void)
{
	//Compare CurrentVersion and ServerVersionOnWeb
	if(CurrentVersion >= ServerVersionOnWeb)
	{
		//close program and launch vsu
		ExitApp();
		ShellExecute(GetDesktopWindow(), "open", "VSU.exe", NULL, NULL, SW_SHOWNORMAL);
	}
	else if(CurrentVersion < ServerVersionOnWeb)
	{
		//VSU needs to be updated, download nufls.vor, swn.vor
		//after these files are downloaded, then begin to download the files
		//contained in "nufls.vor"
		try
		{
			Form1->Label1->Caption = "Overall Progress: Preparing Information...";
			Form1->ProgressBar1->Position += 1;
			Form1->ProgressBar2->Max = Form1->FTP1->Size("nufls.vor");
			required = false;
			Form1->FTP1->Get("nufls.vor", "nufls.vor", true, false);
			Form1->ProgressBar2->Max = Form1->FTP1->Size("swn.vor");
			Form1->FTP1->Get("swn.vor", "swn.vor", true, false);
			//done downloading important updates, now begin showing them and
			//preparing data for final update process
			Form1->Memo2->Clear();
			Form1->Memo2->Lines->LoadFromFile("nufls.vor");
			Form1->Memo1->Clear();
			Form1->Memo1->Lines->LoadFromFile("swn.vor");
			//done displaying content, now filter spaces in memo1, memo2
			FilterMemo12();
		}
		catch(...)
		{
            ExitApp();
        }
    }
}
//---------------------------------------------------------------------------
void FTPConnect(void)
{
	//Connect to FTP
	try
	{
		Form1->FTP1->Connect();
	}
	catch(...)
	{
        ExitApp();
    }	
}
//---------------------------------------------------------------------------
void CheckRegistry(void)
{
   //Check the registry for the current server version installed on the
   //system, so we can come back and check to see if the current version is
   //more recent than the latest update or not.
   Form1->Label1->Caption = "Overall Progress: Checking Registry...";
   Form1->ProgressBar1->Position += 1;
   TRegistry *Reg = new TRegistry();
   Reg->RootKey = HKEY_LOCAL_MACHINE;
   AnsiString temp;
   char gSerial[40];
   if(Reg->KeyExists("SOFTWARE\\VSU"))
   {
	   //try to open the key and read from it
	   try
	   {
		   //
		   if(Reg->OpenKey("SOFTWARE\\VSU", FALSE))
		   {
			   //key has been opened now begin reading
			   temp = Reg->ReadString("ServerVersion");
			   strcpy(gSerial, temp.c_str());
			   Reg->CloseKey();
			   CurrentVersion = StrToInt(gSerial);
			   //RETRIEVED THE KEY, NOW CONTINUE WITH PROCESS
			   Form1->Show();
			   Form1->FTPConnectTimer->Enabled = true;
		   }
		   else
		   {
			   //could not open the key for 2 reasons
			   //1) Vista needs to run the program with administrative rights
			   //2) no idea lol
			   /*                     close or no??                       */
			   ExitApp();
		   }
	   }
	   catch(...)
	   {
		   //could not open the key and read from it, close the program
		   ExitApp();
	   };
   }
   else
   {
	   //could not open the key, because it probably does not exist
	   CurrentVersion = 0;
	   Form1->Show();
	   Form1->FTPConnectTimer->Enabled = true;
   }
}
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
	: TForm(Owner)
{
   DWORD Id;
   Thread = CreateThread(0, 0, ThreadFunction, Form1->Handle, CREATE_SUSPENDED, &Id);
   if(!Thread)
   {
		//ADD CODING FOR WHAT TO DO WHEN THREAD CANNOT BE CREATED
		Application->Terminate();
   }
   else
   {
		//BEGIN PROCESSING
		CheckRegistry();
   }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FTP1AfterClientLogin(TObject *Sender)
{
   Form1->Label1->Caption = "Overall Progress: Connected to the VSU Network!";
   ProgressBar1->Position += 1;
   //Client has connected, begin the process of file downloads
   try
   {
	   //try to get the csv.vor file
	   ProgressBar2->Max = FTP1->Size("csv.vor");
	   //tell the FTP component that this is not a required file
	   required = false;
	   Form1->Show();
	   FTP1->Get("csv.vor", "csv.vor", true, false);
	   Memo3->Clear();
	   Memo3->Lines->LoadFromFile("csv.vor");
	   ServerVersionOnWeb = StrToInt(Memo3->Lines->Strings[0]);
	   CompareVersions();
   }
   catch(...)
   {
       ExitApp();
   };
}
//---------------------------------------------------------------------------

void __fastcall TForm1::FTP1WorkEnd(TObject *ASender, TWorkMode AWorkMode)
{
   //check to see if the file that was downloaded was a required file for the updater
   if(required == true)
   {
	   Memo2->Lines->Delete(0);
	   totaldownloadtotal += ProgressBar2->Max;
	   ProgressBar1->Position += 1;
   }
}
//---------------------------------------------------------------------------

void __fastcall TForm1::FTP1Work(TObject *ASender, TWorkMode AWorkMode,
      int AWorkCount)
{
   ProgressBar2->Position = AWorkCount;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FTPConnectTimerTimer(TObject *Sender)
{
   FTPConnectTimer->Enabled = false;
   FTPConnect();
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
  try
  {
	downloadtime += 1;
	currentdownloadtotal = ProgressBar2->Position;
	totalrate += (totaldownloadtotal + currentdownloadtotal) - previousdownloadtotal;
	previousdownloadtotal = totaldownloadtotal + currentdownloadtotal;
	downloadrate = totalrate / downloadtime;
	Form1->Label2->Caption = "File Progress: "+filename+"... "+IntToStr(downloadrate/1024)+" KB/Second...";
  }
  catch(...){};
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Timer2Timer(TObject *Sender)
{
	if(start_install == true)
	{
		//
		Timer2->Enabled = false;
		Label1->Caption = "Overall Progress: Installing Files...";
		//begin the installation process by calling 'sinsall.bat'
		ShellExecute(GetDesktopWindow(), "open", "sinstall.bat", NULL, NULL, SW_HIDE);
		//begin timer
		Timer3->Enabled = true;
    }	
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Timer3Timer(TObject *Sender)
{
   Timer3->Enabled = false;
   //installation done, now close and restart 'VSU.exe'
   Label1->Caption = "Overall Progress: Installation Complete! Launching VSU Server...";
   ExitApp();
}
//---------------------------------------------------------------------------
CodeByter.com - http://www.codebyter.com

Codebyte

  • "Premature Optimization is the root of all evil."
  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 160
    • Participated in NANY Challenge Once
    • Coding Snacks
    • Plugin Coding Medal
Re: My Application...
« Reply #21 on: January 11, 2008, 06:16 PM »
lol, any ideas as to why that error occurs?
CodeByter.com - http://www.codebyter.com

jazper

  • Coding Snacks Author
  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 92
    • Coding Snacks
Re: My Application...
« Reply #22 on: January 12, 2008, 05:39 PM »
You need to do some research on thread synchronization now.  In my example above I used Synchronize() to safely set values in the Main thread from my background thread.  Synchronize is basically a wrapper around Critical sections.  You'll need to use Critical Sections to access objects/variables in the Main thread. 



Codebyte

  • "Premature Optimization is the root of all evil."
  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 160
    • Participated in NANY Challenge Once
    • Coding Snacks
    • Plugin Coding Medal
Re: My Application...
« Reply #23 on: January 22, 2008, 05:06 PM »
ok, looking into that now. Thank you for all the time spent and sorry for the late response. Things got crazy with college.
CodeByter.com - http://www.codebyter.com

Original address: https://www.donationcoder.com/forum/index.php?topic=11735.0