home *** CD-ROM | disk | FTP | other *** search
- unit svrCOMmain;
-
- interface
-
- uses
- ComObj, DBTables, ActiveX, SML_Handler_TLB;
-
- type
- TSMLHandler = class(TAutoObject, ISMLHandler)
- protected
- Database: TDatabase;
- function GetContent(const aVariables: WideString): WideString; safecall;
- public
- destructor Destroy; override;
- procedure Initialize; override;
- end;
-
- implementation
-
- uses
- ComServ, svrSubmitHandler, svrPageHandler, mleCommon, Classes, SysUtils;
-
- destructor TSMLHandler.Destroy;
- begin
- Database.Free;
- inherited;
- end;
-
- function TSMLHandler.GetContent(const aVariables: WideString): WideString;
- { aVariables is a comma-separated list of URL and/or content parameters
- passed through with the request. }
- var
- I: Integer;
- Errors: TStringList;
- Packet: TInfoPacket;
- begin
- Result := '';
- try
- Packet := TInfoPacket.Create;
- try
- Packet.Database := Database;
- Packet.Variables.CommaText := aVariables;
-
- { Check for processing instructions. Handle the posting of submitted
- pages first, then any requests to generate new pages }
-
- with Packet.Variables do
- for I := 0 to Count - 1 do
- if (CompareText(Strings[I], 'PI:LOGIN') = 0) or
- (CompareText(Names[I], 'PI:UPDATE') = 0) then
- with TSubmitHandler.Create(nil, Packet) do
- try
- Result := GetContent;
- finally
- Free;
- end;
-
- if Packet.Variables.IndexOfName('PI:PAGE') <> -1 then
- if Packet.Variables.Values['PI:PAGE'] <> '' then
- with TPageHandler.Create(nil, Packet) do
- try
- Result := GetContent;
- finally
- Free;
- end;
- finally
- Packet.Free;
- end;
-
- if Result = '' then
- raise Exception.Create('Invalid page request');
- except
- on E:Exception do
- begin
- Errors := TStringList.Create;
- try
- Errors.Text := E.Message;
- for I := 0 to Errors.Count - 1 do
- Errors[I] := '*** ' + Errors[I];
- Errors.Insert(0, '<PRE>');
- Errors.Insert(1, '*** Error');
- Errors.Add('</PRE>');
- Result := Errors.Text;
- finally
- Errors.Free;
- end;
- end;
- end;
- end;
-
- procedure TSMLHandler.Initialize;
- begin
- inherited;
- Database := TDatabase.Create(nil);
- { The database connection would most likely be configurable.
- Certainly the login username and password would be. }
- Database.AliasName := 'DBDEMOS';
- Database.DatabaseName := 'SampleDB';
- Database.Open;
- end;
-
- initialization
- TAutoObjectFactory.Create(ComServer, TSMLHandler, Class_SMLHandler,
- ciMultiInstance, tmApartment);
- end.
-