unit CScroll2;

interface

uses
  Classes, SysUtils, IWAppForm, IWApplication, IWTypes, IWTMSCC,
  IWCompEdit, Controls, IWBaseControl, IWControl, IWCompLabel, LeftFrame,
  Forms, TopFrame, IWVCLBaseControl, IWBaseHTMLControl, IWAutoFormFill,
  IWTMSCtrls, IWContinuousScroll, IWCompListbox, IWCompExtCtrls, IWColor, DateUtils;

type
  TformScroll2 = class(TIWAppForm)
    FrameTopFrame1: TFrameTopFrame;
    FrameLeftFrame1: TFrameLeftFrame;
    IWLabel4: TIWLabel;
    IWLabel7: TIWLabel;
    TIWClientCode1: TTIWClientCode;
    IWRadioGroup1: TIWRadioGroup;
    IWLabel2: TIWLabel;
    IWListbox1: TIWListbox;
    TIWContinuousScroll1: TTIWContinuousScroll;
    TIWHTMLLabel1: TTIWHTMLLabel;
    procedure IWAppFormCreate(Sender: TObject);
    procedure IWRadioGroup1Click(Sender: TObject);
    procedure TIWContinuousScroll1AsyncControlEvent(Sender: TObject;
      EventParams: TStringList; EventType, ControlID: string;
      ItemIndex: Integer);
    procedure TIWContinuousScroll1NeedItemData(Sender: TObject;
      ItemIndex: Integer; FieldName: string; var Value: string);
  public
  end;

implementation

{$R *.dfm}

uses
  ServerController;


procedure TformScroll2.IWAppFormCreate(Sender: TObject);
begin
  IWListbox1.Clear;

  TIWContinuousScroll1.MaxItemCount := 200;
  TIWContinuousScroll1.LoadItemsButton.Caption := 'Load ' + IntToStr(TIWContinuousScroll1.ItemDelta) + ' more items ...';
  TIWContinuousScroll1.LoadItemsButton.Font.FontFamily := 'Arial';
  TIWContinuousScroll1.LoadItemsButton.BGHoverColor := clWebLIGHTSTEELBLUE;

  TIWContinuousScroll1.ItemTemplate :=
    '<div class="csitem">'
    + '<div style="float:right"><input type="checkbox" onclick="'
    + TIWContinuousScroll1.HTMLName + 'ControlEventHandler(event, ''Click'', (#Index))"></div>'
    + '<img style="float:left;" src="(#Image)">'
    + '<span style="font-weight:bold;">(#Type):</span> (#Company) ((#Index)) '
    + '<div class="date">(#Date)</div>'
    + '<br><span class="msg">(#Message)</span>'
    + '</div>'
    + '<div style="clear:left"></div>';
end;

procedure TformScroll2.IWRadioGroup1Click(Sender: TObject);
begin
  if IWRadioGroup1.ItemIndex = 0 then
    TIWContinuousScroll1.LoadItems := liOnScroll
  else
    TIWContinuousScroll1.LoadItems := liOnButtonClick;

  TIWContinuousScroll1.InitialItemCount := 30;
end;

procedure TformScroll2.TIWContinuousScroll1AsyncControlEvent(Sender: TObject;
  EventParams: TStringList; EventType, ControlID: string; ItemIndex: Integer);
begin
  IWListbox1.Items.Add('Item ' + IntToStr(ItemIndex))
end;

procedure TformScroll2.TIWContinuousScroll1NeedItemData(Sender: TObject;
  ItemIndex: Integer; FieldName: string; var Value: string);
const
  Companies: array[0..1] of string = ('TMS Software','Embarcadero');
  Images: array[0..1] of string = ('tmslogo1.png','embarcadero.png');
  Types: array[0..1] of string = ('News','Update');
var
  index: integer;
begin

  if FieldName = 'Index' then
  begin
    Value := IntToStr(ItemIndex + 1);
  end;

  if FieldName = 'Company' then
  begin
    Randomize;
    index := Random(Length(Companies));
    Value := Companies[index];
  end;

  if FieldName = 'Message' then
  begin
    Value := 'Lorem ipsum dolor sit amet, consectetur adipisicing elit.';
  end;

  if FieldName = 'Image' then
  begin
    Randomize;
    index := Random(Length(Images));
    Value := 'files/' + Images[index];
  end;

  if FieldName = 'Type' then
  begin
    Randomize;
    index := Random(Length(Types));
    Value := Types[index];
  end;

  if FieldName = 'Date' then
  begin
    Value := DateToStr(IncDay(Date, -ItemIndex));
  end;
end;

initialization
  TformScroll2.SetAsMainForm


end.
