?
Solved

ASP components.

Posted on 1997-12-10
3
Medium Priority
?
213 Views
Last Modified: 2010-04-04
Hi,

I need help creating an ASP ( Active Server Page ) component in Delphi 3.0, specficlly I need help creating the shell of the program.
0
Comment
Question by:latenight
  • 2
3 Comments
 

Accepted Solution

by:
mshaer earned 1200 total points
ID: 1353349
OK,

This is actually much easier than one might think.

What you have to create to make ASP truly happy is an OCX file.
(This is a DLL that is also a OLE Automation Server). The reason that you want to make it a DLL is that the default setting is
not to allow out of process Automation Servers for ASP.

So if this is the goal, how do you actually do it.

Step 1) Create an OCX project
File : New : ActiveX  : ActiveX Library

this creates a file that looks like this (without the comments) :

library Project1;

uses
  ComServ;   // OLE Automation  Unit

exports
  DllGetClassObject,
  DllCanUnloadNow,
  DllRegisterServer,     // this is called to register the server                          // on the machine (need later)
  DllUnregisterServer;   // this is called to un register the                             // server on the machine (need later)

{$R *.RES}

begin
end.

Step 2) Make the automation stuff
File : New : ActiveX : Automation Object
Automation Object wizard pops up.
Enter the class name  (whatever you want it to be)
DLL's must be Multiple instance
Type library Editer pops up

Step 3) The type library
A type library will be generated with a project an Interface and a CoClass.

Add the methods, properties and enumerations that you require to the Interface. Modify the declarations under the attributes so that they are as required.

REMEMBER : WideString not string

Press refresh when finished.

Step 4) Fill in the code.

In the unit fill in the code in the methods generated. And bobs your uncle.

Step 5) Compile

OK, you have a DLL, now what to do with it

Step 5) Installation on another machine

Remember those two functions,
  DllRegisterServer and
  DllUnregisterServer
That I said would be need later, well now they are needed.

after putting the DLL on the new machine run a program that looks something like this (new form edit box and two buttons)

(notice the uses clause OLECtl)

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, OLECtl;

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Label1: TLabel;
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var
  OCXHand : THandle;
  RegFunc : TDllRegisterServer;
begin
  OCXHand := LoadLibrary(Pchar(edit1.text));
  RegFunc := GetProcAddress(OCXHand, 'DllRegisterServer');
  RegFunc;
  if RegFunc <> 0 then ShowMessage('error');
  FreeLibrary(OCXHand);
end;

procedure TForm1.Button2Click(Sender: TObject);
var
  OCXHand : THandle;
  RegFunc : TDllRegisterServer;
begin
  OCXHand := LoadLibrary(Pchar(edit1.text));
  RegFunc := GetProcAddress(OCXHand, 'DllUnregisterServer');
  RegFunc;
  if RegFunc <> 0 then ShowMessage('error');
  FreeLibrary(OCXHand);
end;

end.

This is a program which registers or unregisters active X servers

OK, thats it try it out.

Any problems, just ask
0
 

Author Comment

by:latenight
ID: 1353350
Thanks for the great example, can you show me how to access the Response and Request objects of the scripting context?

Thanks.
0
 

Expert Comment

by:mshaer
ID: 1353351
I am not sure that I understand,
do you mean, how do you access the Request and Response objects
from your delphi DLL ?

If so ...

There is a basic problem, these objects are internal ASP objects
with no advertisement of how they work underneath. In fact they
may not be passable at all.

ASP deals with these objects as it wants.

At any rate, the easiest way to duplicate the effect is to write
a bunch of procedures in the DLL which allow the data to be passed.

This is a relatively ugly solution, but it works fine.

ie

Have a couple of procedures

procedure clearValues
procedure AddPair(area, name, value)

and then in an ASP loop
<%YourObject.clearValues%>
<%For Each Item in Request.ServerVariables %>
 <%YourObject.AddPair('ServerVariables', Item, Request.ServerVariables(Item)%>
<%Next%>

If this makes your blood run cold then say and if I have time
I will try and work it out.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

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…
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…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses
Course of the Month15 days, 22 hours left to enroll

850 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