Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

ASP Component

Posted on 1997-12-16
6
Medium Priority
?
241 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

618 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