Solved

Threads And BDE

Posted on 1998-09-18
3
408 Views
Last Modified: 2013-11-23
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(Application) 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(Query, DataSource);
  end;
end;

I get a read address violation of: FFFFFFFFFFFFF when it runs the Query.DatabaseName := Database.DatabaseName

Can someone tell me why?
0
Comment
Question by:MichaelB082598
  • 3
3 Comments
 
LVL 7

Expert Comment

by:BlackMan
ID: 1340172
When you are using BDE from a thread, you must create a TSession for each thread and point all the DB stuff in that thread to it. I don't know if it will fix your problem, but it will absolutely fix some others, that you haven't expirenced yet :-)
Don't use a global TSession...
0
 
LVL 7

Expert Comment

by:BlackMan
ID: 1340173
Hey MichaelB, are you still there??
0
 
LVL 7

Accepted Solution

by:
BlackMan earned 100 total points
ID: 1340174
When you are using BDE from a thread, you must create a TSession for each thread and point all the DB stuff in that thread to it. I don't know if it will fix your problem, but it will absolutely fix some others, that you haven't expirenced yet :-)
Don't use a global TSession...

0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

791 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question