?
Solved

ASP Component

Posted on 1997-12-16
6
Medium Priority
?
242 Views
Last Modified: 2012-05-04
Hi,

Has somebody translated the IScriptingContect object from C to Delphi (3.0). I try to write asp components in Delphi and use the OnStartPage to get the object, so have somebody translated the header.

Best Regards
 Christian Bøhn
0
Comment
Question by:chrb
  • 2
  • 2
  • 2
6 Comments
 
LVL 4

Accepted Solution

by:
d003303 earned 1000 total points
ID: 1353980
Hi chrb,

it is not neccessary to translate the header files. Just declare the OnStartPage like
function OnStartPage(AScriptingContext: OleVariant): Integer;
in your type library. Also declare the variables you get from the scripting context object as Variant and just use them !
I created an ASP extension in Delphi 2 and it worked this way.

Hope this helps,
Slash/d003303
0
 

Author Comment

by:chrb
ID: 1353981
Hi,

Thanks you for your answear, but...
The OleVariant dosn't exist in Delphi 2 (or I can't find it), it exist in Delphi 3. I will be very happy if you could give me an example which use the Server.MapPath or Response.Write object.
Thanks!

Chr
0
 
LVL 4

Expert Comment

by:d003303
ID: 1353982
Yo,

I adjusted the interface declaration to Delphi 3. If you can use Delphi 2 for your ASP development, here is a working code. You could also use it in Delphi 3, but I do not want to post a bunch of code that the Delphi 3-Wizards are creating automaticaly. The basic adjustments are the declarations in the dispatch interface and private members of TASPTest, set them to OleVariant accordingly.

1. Project file

// to be aspcomp.dpr
library aspcomp;

uses
  SysUtils,
  Classes,
  OLEAuto,
  asptest in 'asptest.pas';

exports
  DllGetClassObject, DllCanUnloadNow, DllRegisterServer, DllUnregisterServer;
begin
end.

------------------------------

2. Core-object unit

// to be asptest.pas
unit asptest;

interface

uses
  OleAuto;

type
  TASPTest = class(TAutoObject)
  private
    { Private declarations }
    Application,
    Request,
    Response,
    Server,
    Session     : Variant;
  automated
    { Automated declarations }
    function TestComponent: LongInt;
    { ASP page event methods }
    function OnStartPage(AScriptingContext : Variant): LongInt;
    function OnEndPage: LongInt;
  end;

implementation

uses Windows, SysUtils;

procedure RegisterTASPTest;
const
  AutoClassInfo: TAutoClassInfo = (
    AutoClass: TASPTest;
    ProgID: 'aspcomp.TASPTest';
    ClassID: '{6879D0B0-785F-11D1-A022-0000E8A3B5E6}';
    Description: 'ASP test component in Delphi 2';
    Instancing: acMultiInstance);
begin
  Automation.RegisterClass(AutoClassInfo);
end;

function TASPTest.TestComponent: LongInt;
var FncResult : Variant;
begin
  Result := S_OK;
  try
    FncResult := Server.URLEncode('<This: is encoded !>');
    Response.write('URL Encoding : ' + FncResult + '<BR>');
    FncResult := Session.TimeOut;
    Response.write('Session timeout set to : ' + IntToStr(VarAsType(FncResult, varInteger)) + '<BR>');
  except
    // any additional error handling (e.g. detailed message)
    // can be done here
    Result := E_FAIL;
    raise;
  end;
end;

function TASPTest.OnStartPage(AScriptingContext : Variant): LongInt;
begin
  Result := S_OK;
  try
    Application := AScriptingContext.Application;
    Request := AScriptingContext.Request;
    Response := AScriptingContext.Response;
    Server := AScriptingContext.Server;
    Session := AScriptingContext.Session;
    Response.write('Loaded<BR>');
  except
    Result := E_FAIL;
  end;
end;

function TASPTest.OnEndPage: LongInt;
begin
  Result := S_OK;
end;

initialization
  RegisterTASPTest;
end.

------------------------------

3. ASP test file

<!-- to be asptest.asp in a web-server executeable directory-->
<HTML>
<HEAD>
<TITLE>aspcomp.TASPTest component test page</TITLE>
</HEAD>
<%
Set TestObject = Server.CreateObject("aspcomp.TASPTest")

response.write("Begin Test<BR>")
response.write("aspcomp.TASPTest.TestComponent returns : " & TestObject.TestComponent & "<BR>")
response.write("End Test<BR>")

Set TestObject = nothing

%>
</HTML>

------------------------------

Build the dll, register it with regsvr32, browse to the asptest.asp page and have fun !

Slash/d003303
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:chrb
ID: 1353983
Thank you very much! :) It worked perfect :)
0
 

Expert Comment

by:yuwang
ID: 4753962
0
 

Expert Comment

by:yuwang
ID: 4753988
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses
Course of the Month14 days, 17 hours left to enroll

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question