RTC Forums
November 24, 2024, 06:03:59 PM
Welcome,
Guest
. Please
login
or
register
.
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
Home
Help
Login
Register
RTC Forums
>
Subscription
>
Support
>
TObject & Sessions
Pages: [
1
]
« previous
next »
Print
Author
Topic: TObject & Sessions (Read 4393 times)
hannesgw
RTC Expired
Posts: 11
TObject & Sessions
«
on:
January 08, 2013, 05:52:29 PM »
Hi if I want to use my own class while SessionsLive on ServerSide is there a possibility?
My Class like this:
type
TMyClass = class
FSQL: string;
FError: string;
FID: string;
FQuery: TMyQuery;
FConnection: TMyConnection;
public
function WriteToDB: string;
end;
procedure Tdm.serverModuleSessionOpen(Sender: TRtcConnection);
begin
with TRtcDataServer(Sender) do
begin
Session.asLinkedObject['myClass'] := TMyClass.Create;
//Session.asOID['myClass'] := GetRtcObjectManager.FindOID(TMyClass.Create);
end;
end;
procedure TdmSvrMain.smMainSessionClose(Sender: TRtcConnection);
var
myClass: TMyClass;
begin
with TRtcDataServer(Sender) do
begin
myClass := (Session.asLinkedObject['myClass'] AS TMyClass);
//myClass := (GetRtcObjectManager.FindObject(Session.asOID['myClass']) AS TMyClass);
FreeAndNil(myClass);
end;
end;
Logged
D.Tkalcec (RTC)
Administrator
Posts: 1881
Re: TObject & Sessions
«
Reply #1 on:
January 08, 2013, 06:04:43 PM »
You can use Session.
Obj[]
and Session.
Child[]
(inherited from the TRtcInfo class) to store custom objects inside a Session. You will need to remove your Objects from the Session by setting the same properties to NIL and free the objects when they are no longer needed (for example, when the Session is closing). Objects assigned to "Session.Obj[]" and "Session.Child[]" will NOT be destroyed automatically by the Session, but the Session will be checked if these objects inherit from the "TRtcObject" class, in which case the "Kill" method will be called on the Object when it has to be destroyed (Session clean-up after close).
For example ...
type
TMyClass = class
FSQL: string;
FError: string;
FID: string;
FQuery: TMyQuery;
FConnection: TMyConnection;
public
function WriteToDB: string;
end;
procedure Tdm.serverModuleSessionOpen(Sender: TRtcConnection);
var
myObj: TMyClass;
begin
with TRtcDataServer(Sender) do
begin
myObj := TMyClass.Create;
Session.Obj['myClass'] := myObj;
end;
end;
procedure TdmSvrMain.smMainSessionClose(Sender: TRtcConnection);
var
myObj: TMyClass;
begin
with TRtcDataServer(Sender) do
begin
if Session.Obj['myClass'] is TMyClass then
begin
myObj := TMyClass(Session.Obj['myClass'])
// use your object
Session.Obj['myClass']:=nil; // remove your object from the Session
FreeAndNil(myObj); // destroy your object
end;
end;
end;
Best Regards,
Danijel Tkalcec
Logged
hannesgw
RTC Expired
Posts: 11
Re: TObject & Sessions
«
Reply #2 on:
January 08, 2013, 07:47:02 PM »
Thanks, Danijel.
Logged
Pages: [
1
]
Print
« previous
next »
Jump to:
Please select a destination:
-----------------------------
Dashboard
-----------------------------
=> General
=> 3rd-Party
=> Quick Start
-----------------------------
Subscription
-----------------------------
=> Support
Loading...