Browse Source

* Applied patch from Luiz Americo

git-svn-id: trunk@15853 -
michael 15 years ago
parent
commit
482c00a876
1 changed files with 24 additions and 25 deletions
  1. 24 25
      packages/fcl-web/src/base/fpweb.pp

+ 24 - 25
packages/fcl-web/src/base/fpweb.pp

@@ -29,9 +29,7 @@ Type
     FOnrequest: TWebActionEvent;
     FOnrequest: TWebActionEvent;
     FContents : TStrings;
     FContents : TStrings;
     FTemplate : TFPTemplate;
     FTemplate : TFPTemplate;
-    function  GetStringContent: String;
     function  GetContents: TStrings;
     function  GetContents: TStrings;
-    procedure SetContent(const AValue: String);
     procedure SetContents(const AValue: TStrings);
     procedure SetContents(const AValue: TStrings);
     Procedure SetTemplate(const AValue : TFPTemplate);
     Procedure SetTemplate(const AValue : TFPTemplate);
   Protected  
   Protected  
@@ -43,7 +41,6 @@ Type
     Destructor destroy; override;
     Destructor destroy; override;
     Procedure Assign(Source : TPersistent); override;
     Procedure Assign(Source : TPersistent); override;
   published
   published
-    Property Content : String Read GetStringContent Write SetContent;
     Property Contents : TStrings Read GetContents Write SetContents;
     Property Contents : TStrings Read GetContents Write SetContents;
     Property OnRequest: TWebActionEvent Read FOnrequest Write FOnrequest;
     Property OnRequest: TWebActionEvent Read FOnrequest Write FOnrequest;
     Property Template : TFPTemplate Read FTemplate Write SetTemplate;
     Property Template : TFPTemplate Read FTemplate Write SetTemplate;
@@ -174,7 +171,7 @@ uses dbugintf;
 procedure TFPWebAction.GetContent(ARequest: TRequest; Content: TStream; Var Handled : Boolean);
 procedure TFPWebAction.GetContent(ARequest: TRequest; Content: TStream; Var Handled : Boolean);
 
 
 begin
 begin
-
+  DoGetContent(ARequest, Content, Handled);
 end;
 end;
 
 
 procedure TFPWebAction.Assign(Source: TPersistent);
 procedure TFPWebAction.Assign(Source: TPersistent);
@@ -185,12 +182,12 @@ Var
 begin
 begin
   If (Source is TFPWebAction) then
   If (Source is TFPWebAction) then
     begin
     begin
-    A:=Source as TFPWebAction;
+    A:=TFPWebAction(Source);
     Name:=A.Name;
     Name:=A.Name;
-    Content:=A.Content;
     AfterResponse:=A.AfterResponse;
     AfterResponse:=A.AfterResponse;
     BeforeRequest:=A.BeforeRequest;
     BeforeRequest:=A.BeforeRequest;
     Default:=A.default;
     Default:=A.default;
+    Contents:=A.FContents;
     ContentProducer:=A.ContentProducer;
     ContentProducer:=A.ContentProducer;
     OnRequest:=A.OnRequest;
     OnRequest:=A.OnRequest;
     FTemplate.Assign(A.Template);
     FTemplate.Assign(A.Template);
@@ -211,11 +208,6 @@ begin
   inherited destroy;
   inherited destroy;
 end;
 end;
 
 
-function TFPWebAction.GetStringContent: String;
-begin
-  Result:=Contents.Text;
-end;
-
 function TFPWebAction.GetContents: TStrings;
 function TFPWebAction.GetContents: TStrings;
 begin
 begin
   If Not Assigned(FContents) then
   If Not Assigned(FContents) then
@@ -223,23 +215,17 @@ begin
   Result:=FContents;
   Result:=FContents;
 end;
 end;
 
 
-procedure TFPWebAction.SetContent(const AValue: String);
+procedure TFPWebAction.SetContents(const AValue: TStrings);
 begin
 begin
-  If (AValue='') then
+  if AValue = nil then
     FreeAndNil(FContents)
     FreeAndNil(FContents)
   else
   else
-    Contents.Text:=AValue;
-end;
-
-procedure TFPWebAction.SetContents(const AValue: TStrings);
-begin
-  Contents.Assign(AValue);
+    Contents.Assign(AValue);
 end;
 end;
 
 
 procedure TFPWebAction.SetTemplate(const AValue: TFPTemplate);
 procedure TFPWebAction.SetTemplate(const AValue: TFPTemplate);
 begin
 begin
-  If Assigned(AValue) then
-    FTemplate.Assign(AValue);
+  FTemplate.Assign(AValue);
 end;
 end;
 
 
 
 
@@ -268,8 +254,9 @@ begin
     Inherited DoHandleRequest(ARequest,AResponse,Handled);
     Inherited DoHandleRequest(ARequest,AResponse,Handled);
     If not Handled then
     If not Handled then
       begin
       begin
-      AResponse.Contents.AddStrings(Self.Contents);
-      Handled:=(AResponse.Content<>'');
+      Handled := (FContents <> nil) and (FContents.Count > 0);
+      if Handled then
+        AResponse.Contents.AddStrings(FContents);
       end;
       end;
     end;
     end;
 {$ifdef cgidebug}
 {$ifdef cgidebug}
@@ -279,12 +266,24 @@ end;
 
 
 procedure TFPWebAction.DoGetContent(ARequest: TRequest; Content: TStream; Var Handled : Boolean);
 procedure TFPWebAction.DoGetContent(ARequest: TRequest; Content: TStream; Var Handled : Boolean);
 
 
+  //isolate string references in a subprocedure to avoid implicit exceptions in main procedure
+  procedure CopyContent;
+  var
+    ContentStr: String;
+  begin
+    if FContents <> nil then
+    begin
+      ContentStr := FContents.Text;
+      If ContentStr<>'' then
+        Content.Write(ContentStr[1],Length(ContentStr));
+    end;
+  end;
+
 begin
 begin
   If Assigned(ContentProducer) then
   If Assigned(ContentProducer) then
     ContentProducer.GetContent(ARequest,Content,Handled)
     ContentProducer.GetContent(ARequest,Content,Handled)
   else
   else
-    If (Self.Content<>'') then
-      Content.Write(Self.Content[1],Length(Self.Content));
+    CopyContent;
 end;
 end;