?
Solved

ASP Component

Posted on 1997-12-16
6
Medium Priority
?
240 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
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!

 

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

Technology Partners: 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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses
Course of the Month9 days, 1 hour left to enroll

764 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