Solved

ASP components.

Posted on 1997-12-10
3
202 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 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Reading complex type element repeats first one found several times 3 38
loading dll from external path 1 209
Delphi selector screen 2 69
SUM 2 INTEGER ARRAYS INTO 1 10 93
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…

929 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

17 Experts available now in Live!

Get 1:1 Help Now