MichaelB082598
asked on
Threads And BDE
Here is my code:
type
TDBQueryThread = class(TThread)
private
FQuery: TQuery;
FDataSource: TDataSource;
FQueryException: Exception;
procedure HookUpUI;
procedure QueryError;
protected
procedure Execute; override;
public
constructor Create(Q: TQuery; D: TDataSource); virtual;
end;
constructor TDBQueryThread.Create(Q: TQuery; D: TDataSource);
begin
inherited Create(True); // create suspended thread
FQuery := Q; // set parameters
FDataSource := D;
FreeOnTerminate := True;
Resume; // thread that puppy!
end;
procedure TDBQueryThread.Execute;
begin
try
FQuery.Open; // open the query
Synchronize(HookUpUI); // update UI from main thread
except
FQueryException := ExceptObject as Exception;
Synchronize(QueryError); // show exception from main thread
end;
end;
procedure NewQuery(QryNum: integer; Qry: TStrings; const Alias, UserName,
Password: string);
begin
{ Create a new Query form to show query results }
with TQueryForm.Create(Applicat ion) do
begin
{ Set a unique session name }
Session.SessionName := Format('Sess%d', [QryNum]);
with Database do
begin
{ set a unique database name }
DatabaseName := Format('DB%d', [QryNum]);
{ set alias parameter }
AliasName := Alias;
{ hook database to session }
SessionName := Session.SessionName;
{ user-defined username and password }
Params.Values['USER NAME'] := UserName;
Params.Values['PASSWORD'] := Password;
end;
with Query do
begin
{ hook query to database and session }
DatabaseName := Database.DatabaseName;
SessionName := Session.SessionName;
{ set up the query strings }
SQL.Assign(Qry);
end;
{ display query strings in SQL Memo }
memSQL.Lines.Assign(Qry);
{ show query form }
Show;
{ open query in its own thread }
TDBQueryThread.Create(Quer y, DataSource);
end;
end;
I get a read address violation of: FFFFFFFFFFFFF when it runs the Query.DatabaseName := Database.DatabaseName
Can someone tell me why?
type
TDBQueryThread = class(TThread)
private
FQuery: TQuery;
FDataSource: TDataSource;
FQueryException: Exception;
procedure HookUpUI;
procedure QueryError;
protected
procedure Execute; override;
public
constructor Create(Q: TQuery; D: TDataSource); virtual;
end;
constructor TDBQueryThread.Create(Q: TQuery; D: TDataSource);
begin
inherited Create(True); // create suspended thread
FQuery := Q; // set parameters
FDataSource := D;
FreeOnTerminate := True;
Resume; // thread that puppy!
end;
procedure TDBQueryThread.Execute;
begin
try
FQuery.Open; // open the query
Synchronize(HookUpUI); // update UI from main thread
except
FQueryException := ExceptObject as Exception;
Synchronize(QueryError); // show exception from main thread
end;
end;
procedure NewQuery(QryNum: integer; Qry: TStrings; const Alias, UserName,
Password: string);
begin
{ Create a new Query form to show query results }
with TQueryForm.Create(Applicat
begin
{ Set a unique session name }
Session.SessionName := Format('Sess%d', [QryNum]);
with Database do
begin
{ set a unique database name }
DatabaseName := Format('DB%d', [QryNum]);
{ set alias parameter }
AliasName := Alias;
{ hook database to session }
SessionName := Session.SessionName;
{ user-defined username and password }
Params.Values['USER NAME'] := UserName;
Params.Values['PASSWORD'] := Password;
end;
with Query do
begin
{ hook query to database and session }
DatabaseName := Database.DatabaseName;
SessionName := Session.SessionName;
{ set up the query strings }
SQL.Assign(Qry);
end;
{ display query strings in SQL Memo }
memSQL.Lines.Assign(Qry);
{ show query form }
Show;
{ open query in its own thread }
TDBQueryThread.Create(Quer
end;
end;
I get a read address violation of: FFFFFFFFFFFFF when it runs the Query.DatabaseName := Database.DatabaseName
Can someone tell me why?
Hey MichaelB, are you still there??
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Don't use a global TSession...