Question about AfterConnect event

Discussion of open issues, suggestions and bugs regarding ODAC (Oracle Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
pcz
Posts: 81
Joined: Tue 04 Aug 2015 12:53

Question about AfterConnect event

Post by pcz » Fri 04 Sep 2015 10:22

Hello

I'm testing ODAC demo (9.5.18 / Delphi XE7) and i've got stupid question about TOraSession.Assign method and events

Code: Select all

unit Unit1;
interface
uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Data.DB, MemDS, DBAccess, Ora, OraCall, Vcl.StdCtrls;
type
  TForm1 = class(TForm)
    OraSession1: TOraSession;
    TestStoredProc: TOraStoredProc;
    Button1: TButton;
    OraSession2: TOraSession;
    Button2: TButton;
    procedure OraSession1AfterConnect(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  end;
var
  Form1: TForm1;
implementation
{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  OraSession1.Connect;
  TestStoredProc.Session := OraSession2;
  OraSession2.AssignConnect(OraSession1);
  TestStoredProc.Execute;   // this line works as i expected
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  OraSession1.Connect;
  TestStoredProc.Session := OraSession2;
  OraSession2.Assign(OraSession1);
  TestStoredProc.Execute;   // WHY DOES THIS LINE FIRES AfterConnect EVENT?...
end;

end.
I just wanted to create universal TDataModule descendant with TOraStoredProc + TOraSession (session for testing purposes and for assigning it to the TOraStoredProc inside IDE) with posibility to attach this TDataModule to existing and connected session (because I just don't want to assign TOraStoredProc.Session dynamically for every instance of this component)

Maybe any better idea?

Why there is such a difference in events between AssignConnect and Assign methods?...
(I just wanted to use similar idea as in OdacDemo => DemoFrame.pas)

I'd be grateful for any explanation / help :D


After checking...
calling Assign again causes BeforeDisconnest+AfterDisconnect events
Then calling TOraStoredProc.Execute causes BeforeConnect+AfterConnect event pair...

Is this a bug or an intentional behaviour? (What is the purpose of that mechanism?)

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: Question about AfterConnect event

Post by AlexP » Fri 04 Sep 2015 12:08

Hello,

The Assign method "copies" only properties, methods and events of the TOraSession object; and the AssignConnect method "copies" only the main (required for connection) properties of the TOraSession object, creates and copies properties of the "internal" OCIConnection object.
Therefore, when using the Assign method, the events of the original object will be called.

pcz
Posts: 81
Joined: Tue 04 Aug 2015 12:53

Re: Question about AfterConnect event

Post by pcz » Sun 06 Sep 2015 23:05

AlexP wrote:Therefore, when using the Assign method, the events of the original object will be called.
Sure - it calls original events :)
But why does last line of this code piece (calling Execute method) causes reconnection of yet connected TOraSession?

Code: Select all

OraSession1.Connect;
TestStoredProc.Session := OraSession2;
OraSession2.Assign(OraSession1);
TestStoredProc.Execute;   // STRANGE BEHAVIOUR HERE...?
=> Executing TOraStoerdProc binded to TOraSession that had been Assigned() to another previously connected TOraSession executes:
- BeforeDisconnest event
- AfterDisconnect event
- BeforeConnect event
- AfterConnect event

What is the cause / purpose?

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: Question about AfterConnect event

Post by AlexP » Mon 07 Sep 2015 07:04

As I wrote earlier, the Assign method copies values of properties and event, and independently on whether connection was or wasn't established, connection will be established for the second OraSession object. And these will be 2 different sessions on the server.

pcz
Posts: 81
Joined: Tue 04 Aug 2015 12:53

Re: Question about AfterConnect event

Post by pcz » Mon 07 Sep 2015 17:38

Mhm...

Thanks for explanation! :)

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: Question about AfterConnect event

Post by AlexP » Tue 08 Sep 2015 05:41

If you have any other questions, feel free to contact us.

Post Reply