home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / Runimage / Delphi50 / Source / Internet / COMPPROD.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1999-08-11  |  2.6 KB  |  93 lines

  1. {*******************************************************}
  2. {                                                       }
  3. {       Borland Delphi Visual Component Library         }
  4. {                                                       }
  5. {       Copyright (c) 1995,99 Inprise Corporation       }
  6. {                                                       }
  7. {*******************************************************}
  8.  
  9. unit CompProd;
  10.  
  11. interface
  12.  
  13. uses Classes, HTTPApp, WebComp;
  14.  
  15. type
  16.   TComponentsPageProducer = class(TPageProducer)
  17.   protected
  18.     function FindComponent(TagParams: TStrings): TComponent; virtual;
  19.     function FindComponentName(TagParams: TStrings): string;
  20.     function GetComponentContent(TagParams: TStrings): string; virtual;
  21.     procedure DoTagEvent(Tag: TTag; const TagString: string; TagParams: TStrings;
  22.       var ReplaceText: string); override;
  23.     function GetContentOptions(var Owned: Boolean): TWebContentOptions; virtual;
  24.   published
  25.     property OnHTMLTag;
  26.   end;
  27.  
  28. implementation
  29.  
  30. uses SysUtils;
  31.  
  32. procedure TComponentsPageProducer.DoTagEvent(Tag: TTag; const TagString: string;
  33.   TagParams: TStrings; var ReplaceText: string);
  34. begin
  35.   if Tag = tgCustom then
  36.   begin
  37.     if CompareText(TagString, 'COMPONENT') = 0 then
  38.     begin
  39.       ReplaceText := GetComponentContent(TagParams);
  40.       Exit;
  41.     end;
  42.   end;
  43.   inherited DoTagEvent(Tag, TagString, TagParams, ReplaceText);
  44. end;
  45.  
  46. function TComponentsPageProducer.FindComponentName(TagParams: TStrings): string;
  47. begin
  48.   Result := TagParams.Values['Name'];
  49. end;
  50.  
  51. function TComponentsPageProducer.FindComponent(TagParams: TStrings): TComponent;
  52. var
  53.   ComponentName: string;
  54. begin
  55.   ComponentName := FindComponentName(TagParams);
  56.   if ComponentName <> '' then
  57.     if Owner <> nil then
  58.     begin
  59.       Result := Owner.FindComponent(ComponentName);
  60.       Exit;
  61.     end;
  62.   Result := nil;
  63. end;
  64.  
  65. function TComponentsPageProducer.GetComponentContent(TagParams: TStrings): string;
  66. var
  67.   Component: TComponent;
  68.   ContentIntf: IWebContent;
  69.   Options: TWebContentOptions;
  70.   Owned: Boolean;
  71. begin
  72.   Component := FindComponent(TagParams);
  73.   if Assigned(Component) then
  74.     if Component.GetInterface(IWebContent, ContentIntf) then
  75.     begin
  76.       Options := GetContentOptions(Owned);
  77.       try
  78.         Result := ContentIntf.Content(Options, nil);
  79.       finally
  80.         if Owned then
  81.           Options.Free;
  82.       end;
  83.     end;
  84. end;
  85.  
  86. function TComponentsPageProducer.GetContentOptions(var Owned: Boolean): TWebContentOptions;
  87. begin
  88.   Owned := True;
  89.   Result := TWebContentOptions.Create([]);
  90. end;
  91.  
  92. end.
  93.