?
Solved

IBX component in thread

Posted on 2004-04-30
15
Medium Priority
?
193 Views
Last Modified: 2010-04-05
Hi,

I'm new to using threads and am looking for an example of how to do the following:

I want a blank form with a button. When I press the button I want to start a thread that creates a tibdatabase component, opens the connection, and then shows a message saying successful.


0
Comment
Question by:jamesr123456
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 5
15 Comments
 
LVL 7

Expert Comment

by:sftweng
ID: 10963957
So just go to File -> New -> Other -> Thread Object and put the application code into the Execute procedure, being certain that you use Synchronize to make ANY references to GUI components.
0
 
LVL 7

Expert Comment

by:sftweng
ID: 10963965
Oh, and yes, within your button's OnClick event, you could do the creation (dynamically).
0
 

Author Comment

by:jamesr123456
ID: 10964051
I've tried doing that, but it just does nothing. I get no error messages either.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 7

Expert Comment

by:sftweng
ID: 10964100
Would you mind posting your code?
0
 

Author Comment

by:jamesr123456
ID: 10964168
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, DB, IBDatabase;


type  TForm1 = class(TForm)
    Label1: TLabel;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end; { of class declaration }

type
  mythread = class(TThread)
  private
    { Private declarations }
  procedure opendatabase;
  protected
    procedure Execute; override;
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
begin
mythread.Create(false);
end; { of procedure }

procedure mythread.Execute;
begin
  { Place thread code here }
synchronize(opendatabase);
  end;

procedure mythread.opendatabase;
var db:tibdatabase;
begin
db:=tibdatabase.Create(db);
db.DatabaseName:='z:\track.gdb';
db.Params.add('user_name=sysdba');
db.params.add('password=masterkey');
db.Open;
if db.connected then form1.label1.caption:='connected';
end;

end.

0
 
LVL 7

Expert Comment

by:sftweng
ID: 10964228
The problem is in the ButtonClick.

procedure TForm1.Button1Click(Sender: TObject);
var
  this MyThread : mythread;
begin
  thismythread := mythread.Create(false);
end; { of procedure }
0
 

Author Comment

by:jamesr123456
ID: 10964269
still dosnt work. the label changes to 'starting' and stays like that

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, DB, IBDatabase;


type  TForm1 = class(TForm)
    Label1: TLabel;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end; { of class declaration }

type
  mythread = class(TThread)
  private
    { Private declarations }
  procedure opendatabase;
  protected
    procedure Execute; override;
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var f:mythread;
begin
f:=mythread.Create(false);
end; { of procedure }

procedure mythread.Execute;
begin
  { Place thread code here }
synchronize(opendatabase);
  end;

procedure mythread.opendatabase;
var db:tibdatabase;
begin
form1.label1.caption:='starting';
db:=tibdatabase.Create(db);
db.DatabaseName:='z:\track\protrack.gdb';
db.Params.add('user_name=sysdba');
db.params.add('password=masterkey');
form1.label1.caption:='about to open';
db.Open;
if db.connected then form1.label1.caption:='connected' else form1.Label1.caption:='disconnected';

end;

end.

0
 
LVL 7

Expert Comment

by:sftweng
ID: 10964297
Does the same code work successfully in a non-thread procedure?
0
 

Author Comment

by:jamesr123456
ID: 10964352
yes. works fine if its not in a thread
0
 
LVL 7

Expert Comment

by:sftweng
ID: 10964523
Hmm. This will take some experimenting. But not today I'm afraid.
0
 

Author Comment

by:jamesr123456
ID: 10968123
Okay not to worry, i've sorted it out.
I've upgraded to the latest IBX, and also found an example of how to use IBconnectionbroker in a thread.
0
 
LVL 7

Expert Comment

by:sftweng
ID: 10968576
As the only responder, I have no objection, so don't bother waiting on my behalf.
0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 10968811
PAQ-ing the question and refunding 50  points

Thanks sftweng !

modulo

Community Support Moderator
Experts Exchange
0
 
LVL 7

Expert Comment

by:sftweng
ID: 10968855
My pleasure. But I would appreciate some attention being given to http://www.experts-exchange.com/Community_Support/Q_20912205.html
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month8 days, 5 hours left to enroll

765 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