Subject Re: TIB_Session management
Author kgdonn
The documentation seems correct. I'll paste my test code below, but
basically I created a couple TIBOTables and TIBODatabases in
different threads and then traced down to see where they're getting
their session. The code will use TlsGetValue and TlsSetValue (Win32
API) to store a unique TIB_Session object for each thread. The code
seemed prepared for the fact that none of my objects had owners. I
think I'm good to go now. You definitely don't want to let the
second thread throw up a login dialog however. That will crash the
VCL.

-------------
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics,
Controls, Forms,
Dialogs, StdCtrls, DB, IBODataset, IB_Components, IB_Session,
Grids,
DBGrids;

type
TForm1 = class(TForm)
Button1: TButton;
DataSource1: TDataSource;
DBGrid1: TDBGrid;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

type

TTestThread = class(TThread)
protected
procedure Execute; override;
end;

var
Username: string;
Password: string;

procedure TForm1.Button1Click(Sender: TObject);
var
IBODatabase1: TIBODatabase;
IBOTable1: TIBOTable;
begin
IBODatabase1:=TIBODatabase.Create(nil);
IBOTable1:=TIBOTable.Create(nil);

IBOTable1.IB_Connection:=IBODatabase1;
IBODatabase1.Protocol:=cpTCP_IP;
IBODatabase1.Server:='localhost';
IBODatabase1.Path:='C:\DBs\ESL_AR\ESL_AR.GDB';
IBODatabase1.LoginPrompt:=true;
IBODatabase1.Connected:=true;
IBOTable1.TableName:='LEA';
IBOTable1.Open;
DataSource1.DataSet:=IBOTable1;
Username:=IBODatabase1.Username;
Password:=IBODatabase1.Password
end;

procedure TTestThread.Execute;
var
IBODatabase1: TIBODatabase;
IBOTable1: TIBOTable;
begin
IBODatabase1:=TIBODatabase.Create(nil);
IBOTable1:=TIBOTable.Create(nil);
IBOTable1.IB_Connection:=IBODatabase1;
IBODatabase1.Protocol:=cpTCP_IP;
IBODatabase1.Server:='localhost';
IBODatabase1.Path:='C:\DBs\ESL_AR\ESL_AR.GDB';
IBODatabase1.LoginPrompt:=false;
IBODatabase1.Username:=Username;
IBODatabase1.Password:=Password;
IBODatabase1.Connected:=true;
IBOTable1.TableName:='LEA';
IBOTable1.Open
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
TTestThread.Create(true).Resume
end;

end.