unit CSCroll1;

interface

uses
  Classes, SysUtils, IWAppForm, IWApplication, IWTypes, IWTMSCC,
  IWCompEdit, Controls, IWBaseControl, IWControl, IWCompLabel, LeftFrame,
  Forms, TopFrame, IWVCLBaseControl, IWBaseHTMLControl, IWAutoFormFill,
  IWTMSCtrls, IWContinuousScroll, IWBaseComponent, IWBaseHTMLComponent,
  IWBaseHTML40Component, IWCompExtCtrls;

type
  TformScroll1 = class(TIWAppForm)
    FrameTopFrame1: TFrameTopFrame;
    FrameLeftFrame1: TFrameLeftFrame;
    IWLabel4: TIWLabel;
    IWLabel7: TIWLabel;
    IWTimer1: TIWTimer;
    IWLabel3: TIWLabel;
    IWLabel2: TIWLabel;
    TIWHTMLLabel1: TTIWHTMLLabel;
    TIWClientCode1: TTIWClientCode;
    TIWContinuousScroll1: TTIWContinuousScroll;
    procedure IWAppFormCreate(Sender: TObject);
    procedure TIWContinuousScroll1NeedItemData(Sender: TObject;
      ItemIndex: Integer; FieldName: string; var Value: string);
    procedure IWTimer1AsyncTimer(Sender: TObject; EventParams: TStringList);
  public
    NewOrder: boolean;
  end;

implementation

{$R *.dfm}

uses
  ServerController;


procedure TformScroll1.IWAppFormCreate(Sender: TObject);
begin
  TIWContinuousScroll1.ItemDelta := 1;
  TIWContinuousScroll1.MaxItemCount := 1000;
  TIWContinuousScroll1.InitialItemCount := 30;
  TIWContinuousScroll1.ScrollElement := seControl;
  NewOrder := false;
end;

procedure TformScroll1.IWTimer1AsyncTimer(Sender: TObject;
  EventParams: TStringList);
begin
  NewOrder := true;
  TIWContinuousScroll1.AsyncInsertItemsBefore;
end;

procedure TformScroll1.TIWContinuousScroll1NeedItemData(Sender: TObject;
  ItemIndex: Integer; FieldName: string; var Value: string);
const
  Names: array[0..7] of string = ('John','Mike','Nicole','George','Robert','David','Philip','Anne');
  Products: array[0..7] of string = ('Apples','Oranges','Pineapples','Bananas','Strawberries','Coconuts','Peaches','Raspberries');

  function GetRandomDate(const Min, Max: TDateTime): TDateTime;
  begin
    Result := Random(Trunc(Max) - Trunc(Min) + 1) + Min;
  end;

begin

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

  if FieldName = 'Customer' then
  begin
    Randomize;
    Value := Names[Random(Length(Names))];
  end;

  if FieldName = 'Product' then
  begin
    Randomize;
    Value := Products[Random(Length(Products))];
  end;

  if FieldName = 'Amount' then
  begin
    Randomize;
    Value := IntToStr(Random(52) + 1);
  end;

  if FieldName = 'OrderDate' then
  begin
    if NewOrder then
      Value := DateToStr(Date)
    else
      Value := DateToStr(GetRandomDate(StrToDate('01/01/2012'), Date));
    NewOrder := false;
  end;
end;

initialization
  TformScroll1.SetAsMainForm


end.
