Page 1 of 1

Question about AfterConnect event

Posted: Fri 04 Sep 2015 10:22
by pcz
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?)

Re: Question about AfterConnect event

Posted: Fri 04 Sep 2015 12:08
by AlexP
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.

Re: Question about AfterConnect event

Posted: Sun 06 Sep 2015 23:05
by pcz
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?

Re: Question about AfterConnect event

Posted: Mon 07 Sep 2015 07:04
by AlexP
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.

Re: Question about AfterConnect event

Posted: Mon 07 Sep 2015 17:38
by pcz
Mhm...

Thanks for explanation! :)

Re: Question about AfterConnect event

Posted: Tue 08 Sep 2015 05:41
by AlexP
If you have any other questions, feel free to contact us.