Solved

ASP Component

Posted on 1997-12-16
6
231 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 250 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:chrb
Comment Utility
Thank you very much! :) It worked perfect :)
0
 

Expert Comment

by:yuwang
Comment Utility
0
 

Expert Comment

by:yuwang
Comment Utility
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

743 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now