Solved

Threads And BDE

Posted on 1998-09-18
3
402 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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

707 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now