Solved

ASP Component

Posted on 1997-12-16
6
238 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 250 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
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!

 

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

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!

Question has a verified solution.

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

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…
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…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

717 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