Hi all
I really need help here, I have spent over 25 hours trying to get this to
work
and can't. I'm sorry if this is long winded but I need to explain all
I am using Delphi 6, I have a main form with some variables
on it, and I have created a thread unit with 2 threads in it.
The thread unit also has a record type of (im****tant later)
type
TLoginInformation = record
Host: string;
****t: Cardinal;
User: string;
Password: string;
Database: string;
UnitId:string;
end;
Thread 1
=======
TGetSetup = class(TThread)
private
{ private }
FLoginInformation: TLoginInformation;
FOnFinished: TNotifyEvent ;
protected
procedure Execute; override;
procedure SetVars;
public
constructor Create;
procedure Connect(li: TLoginInformation);
property OnFinish: TNotifyEvent read FOnFinished write FOnFinished;
end;
Builds a instance of the database and query
db := TmySQLDatabase.Create(nil);
Query := TmySQLQuery.Create(nil);
Reads some data from a MySQL table and needs to set about 20 variables
that the MainUnit will use.
procedure TGetSetup.Execute;
var ID:string;
db: TmySQLDatabase ;
Query: TmySQLQuery ;
begin
FreeOnTerminate := True;
try
if not Terminated then
begin
db := TmySQLDatabase.Create(nil);
Query := TmySQLQuery.Create(nil);
SET VARIABLES HERE
............
end;
finally //freeing resources
Query.Free;
db.Free;
end;
end;
Thread 2
=======
TMakeAdvertBank = class(TThread)
private
{ private }
FLoginInformation: TLoginInformation;
tUnitId:string;
TBankNumber:string;
TshowLable:string;
Tprofilename:string;
Tdescription:string;
protected
procedure Execute; override;
procedure ShowBankLoading;
public
constructor Create;
procedure Connect(li: TLoginInformation;bank:string);
end;
Builds a instance of the database and query
db := TmySQLDatabase.Create(nil);
Query := TmySQLQuery.Create(nil);
Reads some more data from a MySQL table, now some of the info to
build up the MySQL statements are variables that were set in the 1st
thread
but also need to be seen by both the MainForm and the ThreadUnit.
procedure TMakeAdvertBank.Execute;
var db : TmySQLDatabase;
Query : TmySQLQuery;
begin
FreeOnTerminate := True;
try
if not Terminated then
begin
db := TmySQLDatabase.Create(nil);
Query := TmySQLQuery.Create(nil);
USE VARIABLES HERE
............
end;
finally //freeing resources
Query.Free;
db.Free;
end;
end;
Now heres the problems
=================
On the main form I have declared my variables as
threadvar
Var1 : string;
Var2 : string;
Var3 : string;
implementation
.....
Should the "threadvar" be before or after the "implementation" , I have
tried both ways
and the ThreadUnit will not see the Threadvar.
But if I add "uses MainUnit; " to the "ThreadUnit" it works, but this then
causes another
problem
Below is a function the idea is that it will run the this function, test
if
it was Assigned if not
run the threat, if so wait till the threat is finished.
But because is had to add "uses MainUnit; " in the "ThreadUnit" the
"GetBank" is
always true as it can see the TLoginInformation
If I put the TLoginInformation on the "MainUnit" then the "ThreadUnit"
complains!
function RunMasterBankLists():boolean;
var k:integer;
LoginInformation: TLoginInformation ;
GetBank: TMakeAdvertBank ;
begin
k:=1;
GetBank := nil;
While (k < 24) do
begin
if Assigned(GetBank) then
else begin
with LoginInformation do
begin
Host := dbHost;
****t := db****t;
User := dbUser;
Password := dbPassword;
Database := dbDatabase;
UnitId := UnitID;
end;
GetBank := TMakeAdvertBank.Create;
GetBank.Connect(LoginInformation,IntToStr(k));
inc(k);
end;
end;
end;
It seems to make no odds if I run the GetBank := nil;
So as you can see I can't seem to win either way, if I don't use the
MainUnit in the
ThreatForm then the Threadvar don't seem to work, and if I do the my
second
threat
test it is always true?
So now after 25 hours (and I'm not joke) I am at a lost, please help,
anybody?!?!?
Thanks
Brian


|