Le but de ce didactitiel est de vous faire découvrir pas à pas,
la construction d'une application pour le web avec Delphi 5/6. Il ne sera pas
question ici, de faire le tour des technologies et possibilités
offertes par la dernière version de l'outil de programmation,
mais simplement de vous donner la marche à suivre pour créer une application portable.
|
unit uCustomIsapi;
interface
Uses Windows, Messages, SysUtils, Classes, uCustomDllObject,
isapiapp,
HTTPApp;
Type
// TBaseObject est défini dans uCustomDllObject.pas
TCustomISAPI = Class(TBaseObject)
fslRequest : TStrings; // paramètres de la requÊte
fRequest : TWebRequest; // RequÊte
fIniFileName : String;
Function GetCurrentPath : String;
Public
Constructor Create (aRequest: TWebRequest); Virtual;
Destructor Destroy; Override;
function GetRootUrl(Url:String):String;
Function VerifUrl(aUrl : String):String;
function SetStrValueToInt(Param : String;DefaultValue : Integer) : Integer;
function SetStrValueToDouble(Param : String;DefaultValue : Double) : Double;
function SetStrValueToStr(Param : String;DefaultValue : String) : String;
function SetStrValueToDate(Param : String ;DefaultValue:TDateTime) : TDateTime;
function SetStrValueToBool(Param : String;DefaultValue : Boolean) : Boolean;
Property Request : TWebRequest Read fRequest;
property RequestContent : TStrings Read fslRequest;
property IniFileName : String Read fInifileName Write fInifileName;
property CurrentPath : String read GetCurrentPath;
End;
implementation
Constructor TCustomISAPI.Create(aRequest: TWebRequest) ;
begin
inherited Create;
// Lecture des paramètres de la requÊte
Try
fRequest:=aRequest;
if fRequest.MethodType in [mtPost] then
fslRequest:=fRequest.ContentFields
else
fslRequest:=fRequest.QueryFields;
fInifileName:=ChangeFileExt(ModuleName,'.INI');
Except
On e:Exception do AddError('ReadRequest '+e.Message);
end;
end;
Destructor TCustomISAPI.Destroy;
begin
inherited Destroy;
end;
function TCustomISAPI.GetRootUrl(Url:String):String;
// Renvoi la racine de l'url web passée en paramètre
Var I : Integer;
begin
Result:='';
if Url='' then exit;
i:=Succ(Pos('//',Url)); // Existence de Http:// ?
if i>0 then Inc(i) else i:=1;
While (Url[i]<>'/') and (i<Length(Url)) do inc(i);
Result:=System.Copy(Url,1,i);
end;
Function TCustomISAPI.GetCurrentPath : String;
Var i: integer;
begin
// renvoi le chemin courant sans la Dll
Result:=Request.ScriptName;
For i:=Length(Result) downto 1 do
if Result[i]='/' then Break;
if i>1 then
Result:=Copy(Result,1,i)
else
Result:='/';
end;
function TCustomISAPI.VerifUrl(aUrl: String): String;
begin
// si l'url ne comporte pas de chemin, on ajoute le chemin courant
Result:=aUrl;
if Trim(Result)='' then exit;
Result:=UnixPathToDosPath(aUrl);
if Pos('/',Result)=0 then
Result:=GetCurrentPath+aUrl;
end;
function TCustomISAPI.SetStrValueToInt(Param : String ;DefaultValue : Integer):Integer;
begin
Result:=DefaultValue;
if Param<>'' then Result:=StrToInt(Param);
end;
function TCustomISAPI.SetStrValueToDouble(Param: String;
DefaultValue: Double): Double;
begin
Result:=DefaultValue;
if Param<>'' then Result:=StrToFloat(Param);
end;
function TCustomISAPI.SetStrValueToStr(Param : String;DefaultValue : String) : String;
begin
Result:=DefaultValue;
if Param<>'' then Result:=Param;
end;
function TCustomISAPI.SetStrValueToDate(Param : String; DefaultValue : TDateTime) : TDateTime;
begin
Result:=DefaultValue;
if Param<>'' then Result:=StrToDate(Param);
end;
function TCustomISAPI.SetStrValueToBool(Param: String;DefaultValue: Boolean): Boolean;
begin
Result:=DefaultValue;
if Param<>'' then Result:=Trim(Param)>='1';
end;
end.
|
|