home *** CD-ROM | disk | FTP | other *** search
/ Delphi Anthology / aDELPHI.iso / Runimage / Delphi50 / Demos / Midas / InternetExpress / InetXCustom / rowsetstatus.pas < prev    next >
Pascal/Delphi Source File  |  1999-08-11  |  3KB  |  95 lines

  1. unit RowSetStatus;
  2.  
  3. interface
  4.  
  5. uses Classes, HTTPApp, Db, DbClient, Midas,
  6.   XMLBrokr, WebComp, PagItems, MidItems;
  7.  
  8. type
  9.   TRowSetStatus = class(TWebDataDisplay, IScriptComponent)
  10.   protected
  11.     function ControlContent(Options: TWebContentOptions): string; override;
  12.     { IScriptComponent }
  13.     procedure AddElements(AddIntf: IAddScriptElements); virtual;
  14.     function GetSubComponents: TObject;
  15.   public
  16.     constructor Create(AOwner: TComponent); override;
  17.   end;
  18.  
  19. implementation
  20.  
  21. uses sysutils;
  22.  
  23. const 
  24.   sXmlDisplayStatusFunctionName = 'xmlDisplayStatus';
  25.   sXmlDisplayStatusFunction =
  26. 'function %0:s(src, fld)' + #13#10  +
  27. '{' + #13#10   +
  28. 'this.src = src;' + #13#10  +
  29. 'this.fld = fld;' + #13#10   +
  30. 'src.regobj(this);' + #13#10   +
  31. 'this.refr=%1:s;' + #13#10   +
  32. '}' + #13#10;
  33.  
  34.   sStatusRefrFunctionName = 'StatusRefr';
  35.   sStatusRefrFunction =
  36. 'function %0:s(reason)' + #13#10  +
  37. '{' + #13#10 +
  38. 'var p=this.src.pos+1,c=this.src.RowCnt;' + #13#10 +
  39. 'this.fld.value = ''Row '' + p + '' of '' + c;' + #13#10 +
  40. '}' + #13#10;
  41.  
  42.   sStatusVar =
  43. 'var %0:s=new %1:s(%2:s, %3:s);' + #13#10 +
  44. '%0:s.refr(0);' + #13#10;
  45.  
  46.  
  47. { TRowSetStatus }
  48.  
  49. procedure TRowSetStatus.AddElements(AddIntf: IAddScriptElements);
  50. var
  51.   VarName, RowSetName: string;
  52.   HTMLForm: IHTMLForm;
  53.   HTMLControl: string;
  54. begin
  55.   inherited;
  56.   if AddIntf.AddFunction(sXMLDisplayStatusFunctionName, Format(sXmlDisplayStatusFunction,
  57.     [sXMLDisplayStatusFunctionName, sStatusRefrFunctionName])) then
  58.   begin
  59.     AddIntf.AddFunction(sStatusRefrFunctionName, Format(sStatusRefrFunction, [sStatusRefrFunctionName]));
  60.   end;
  61.   RowSetName := GetXMLRowSetName;
  62.   VarName := Format('%s_%s', [Name, RowSetName]);
  63.   HTMLForm := GetHTMLForm;
  64.   HTMLControl := Format('%s.%s', [HTMLForm.HTMLFormVarName, GetHTMLControlName]);
  65.   AddIntf.AddVar(HTMLForm.HTMLFormVarName,
  66.      Format('var %0:s = document.forms[''%1:s''];'#13#10,
  67.       [HTMLForm.HTMLFormVarName, HTMLForm.HTMLFormName]));
  68.   AddIntf.AddVar(VarName, Format(sStatusVar, [VarName, sXMLDisplayStatusFunctionName, GetXMLRowSetName, HTMLControl]));
  69. end;
  70.  
  71. function TRowSetStatus.ControlContent(Options: TWebContentOptions): string;
  72. var
  73.   Attrs: string;
  74. begin
  75.   AddQuotedAttrib(Attrs, 'NAME', GetHTMLControlName);
  76.   //AddIntAttrib(Attrs, 'SIZE', DisplayWidth);
  77.   AddQuotedAttrib(Attrs, 'STYLE', Style);
  78.   AddQuotedAttrib(Attrs, 'CLASS', StyleRule);
  79.   AddCustomAttrib(Attrs, Custom);
  80.   Result := Format('<INPUT TYPE=TEXT%0:s>', [Attrs]);
  81. end;
  82.  
  83. constructor TRowSetStatus.Create(AOwner: TComponent);
  84. begin
  85.   inherited;
  86.  
  87. end;
  88.  
  89. function TRowSetStatus.GetSubComponents: TObject;
  90. begin
  91.   Result := nil;
  92. end;
  93.  
  94. end.
  95.