Solved

ASP components.

Posted on 1997-12-10
3
201 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

771 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

14 Experts available now in Live!

Get 1:1 Help Now