Solved

ASP components.

Posted on 1997-12-10
3
210 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
[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
3 Comments
 

Accepted Solution

by:
mshaer earned 300 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

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…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

705 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