This article demonstrates how to use COM to access ASP objects such as Session.
1. Create a MTS object (look under the Multitier page in File->New...)
2. Name it whatever you like (I called mine TTest)
3. Add a procedure call Tellme (just a test)
4. Register it with MTS (yup .. you guessed it .. look in the menu)
5. Import the "Microsoft Active Server Pages" type library
Here is how you get access to the application, session, response, request objects:
unit Unit1;
interface
uses
MtsObj, Mtx, ComObj, dasp_TLB, ASPTypeLibrary_TLB, sysutils;
type
TTTest = class(TMtsAutoObject, ITTest)
protected
procedure Tellme; safecall;
end;
implementation
uses ComServ;
const IID_IGetContextProperties : TGUID = '{51372AF4-CAE7-11CF-BE81-00AA00A2FA25}';
procedure TTTest.Tellme;
var
vtd : IDispatch;
resp : Response;
req : Request;
ses : ISessionObject;
cp : IGetContextProperties;
srv : Server;
app : IApplicationObject;
begin
ObjectContext.QueryInterface(IID_IGetContextProperties,cp);
IDispatch(cp.GetProperty('Response')).QueryInterface(IID_IResponse,resp);
IDispatch(cp.GetProperty('Request')).QueryInterface(IID_IRequest,req);
IDispatch(cp.GetProperty('Session')).QueryInterface(IID_ISessionObject,ses);
IDispatch(cp.GetProperty('Server')).QueryInterface(IID_IServer,srv);
IDispatch(cp.GetProperty('Application')).QueryInterface(IID_IApplicationObject,App);
if assigned(resp) and assigned(req) and assigned(ses) and assigned(srv)
and assigned(app) then
begin
resp.Write('Yahoo .. this works .. ');
end;
end;
initialization
TAutoObjectFactory.Create(ComServer, TTTest, Class_TTest,
ciMultiInstance, tmApartment);
end.