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

  1. unit SortFlds;
  2.  
  3. interface
  4.  
  5. uses Classes, HTTPApp, Db, DbClient, Midas,
  6.   XMLBrokr, WebComp, PagItems, MidItems;
  7.  
  8. type
  9.  
  10.   TSortTextColumn = class(TTextColumn, IFormatColumn, IScriptComponent)
  11.   private
  12.     FButtonCaption: string;
  13.   protected
  14.     function FormatColumnHeading: string;
  15.     function FormatColumnData(Content: string): string;
  16.     { IScriptComponent }
  17.     procedure AddElements(AddIntf: IAddScriptElements);
  18.     function GetSubComponents: TObject;
  19.   public
  20.     constructor Create(AOwner: TComponent); override;
  21.   published
  22.     property ButtonCaption: string read FButtonCaption write FButtonCaption;
  23.   end;
  24.  
  25. implementation
  26.  
  27. uses sysutils, MidProd;
  28.  
  29. resourcestring 
  30.   sButtonCaption = 'Sort';
  31.  
  32. const 
  33.   sSortFunctionName = 'SortXMLDisplay';
  34.   sSortFunction =
  35.    'function %0:s(xmld,name)'     + #13#10 +
  36.    '{'                              + #13#10 +
  37.    '  xmld.sort(name);'                   + #13#10 +
  38.    '}'                             + #13#10;
  39.  
  40. constructor TSortTextColumn.Create(AOwner: TComponent);
  41. begin
  42.   inherited;
  43.   ButtonCaption := sButtonCaption;
  44. end;
  45.  
  46. function TSortTextColumn.FormatColumnData(Content: string): string;
  47. begin
  48.   Result := MidItems.FormatColumnData(Self, Content);
  49. end;
  50.  
  51. function TSortTextColumn.FormatColumnHeading: string;
  52. var
  53.   Attribs: string;
  54.   Button: string;
  55.   Events: string;
  56. begin
  57.   AddQuotedAttrib(Attribs, 'VALUE', ButtonCaption);
  58.   if not (csDesigning in ComponentState) then
  59.     Events := Format('onclick=''if(%3:s)%0:s(%1:s,"%2:s");''', [sSortFunctionName,
  60.       GetXMLDisplayName, FieldName, sXMLReadyVar]);
  61.   if GetXMLDisplayName <> '' then
  62.     Button := Format('<INPUT TYPE=BUTTON %s %s>',
  63.       [Attribs, Events]);
  64.   Attribs := '';
  65.   AddQuotedAttrib(Attribs, 'STYLE', CaptionAttributes.Style);
  66.   AddCustomAttrib(Attribs, CaptionAttributes.Custom);
  67.   AddQuotedAttrib(Attribs, 'CLASS', CaptionAttributes.StyleRule);
  68.   Result := Format('<TH%s>%s%s</TH>'#13#10, [Attribs, Caption, Button]);
  69. end;
  70.  
  71. function TSortTextColumn.GetSubComponents: TObject;
  72. begin
  73.   Result := nil;
  74. end;
  75.  
  76. procedure TSortTextColumn.AddElements(AddIntf: IAddScriptElements);
  77. begin
  78.   inherited;
  79.   AddIntf.AddFunction(sSortFunctionName, Format(sSortFunction, [sSortFunctionName]));
  80. end;
  81.  
  82.  
  83. end.
  84.