Ignore:
Timestamp:
Jan 16, 2011, 4:31:02 PM (14 years ago)
Author:
george
Message:
  • Fixed: Bad QWord shifting.
  • Fixed: Reading dynamic value from bit stream.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • CoolStreaming/Demo/DynNumber/UMainForm.pas

    r127 r128  
    77uses
    88  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
    9   ComCtrls, UDynNumber, Math;
     9  ComCtrls, Spin, UDynNumber, Math;
    1010
    1111type
     
    1616    Button1: TButton;
    1717    Button2: TButton;
     18    Button3: TButton;
     19    Button4: TButton;
    1820    Edit1: TEdit;
     21    Edit2: TEdit;
     22    Edit3: TEdit;
    1923    ListView1: TListView;
     24    PageControl1: TPageControl;
     25    SpinEdit1: TSpinEdit;
     26    TabSheet1: TTabSheet;
     27    TabSheet2: TTabSheet;
    2028    procedure Button1Click(Sender: TObject);
    2129    procedure Button2Click(Sender: TObject);
     30    procedure Button3Click(Sender: TObject);
     31    procedure Button4Click(Sender: TObject);
    2232    procedure FormCreate(Sender: TObject);
    2333    procedure FormDestroy(Sender: TObject);
    2434  private
    25     { private declarations }
    2635  public
    2736    DynamicNumber: TDynamicNumber;
     
    4453  Parts: array of Integer;
    4554  N: TDynamicNumber;
    46   Line: string;
    4755  NewItem: TListItem;
    4856begin
     
    5159    ListView1.BeginUpdate;
    5260    ListView1.Clear;
    53     for I := 0 to 10000 do begin
     61    for I := 0 to SpinEdit1.Value do begin
    5462      N.Stream.Size := 0;
    55       N.Write(I);
    56       Line := '';
    57       N.Stream.Position := 0;
    58       for J := 0 to N.Stream.Size - 1 do
    59         Line := Line + IntToStr(Integer(N.Stream.ReadBit));
     63      N.WriteNumber(I);
    6064      NewItem := ListView1.Items.Add;
    6165      NewItem.Caption := IntToStr(I);
    6266      J := Floor(Log2(I)) + 1;
    6367      NewItem.SubItems.Add(FloatToStr(Round((1 - (J / N.Stream.Size)) * 100) / 100));
    64       NewItem.SubItems.Add(Line);
     68      NewItem.SubItems.Add(N.Stream.AsString);
    6569    end;
    6670  finally
     
    7983  MaxValue: Integer;
    8084  J: Integer;
    81   Line: string;
    8285  NewItem: TListItem;
    8386  N: TDynamicNumber;
     
    9194    ListView1.BeginUpdate;
    9295    ListView1.Clear;
    93     for II := 0 to 20000 do begin
     96    for II := 0 to SpinEdit1.Value do begin
    9497      I := II * Step;
    9598    // Write
     
    109112    J := Floor(Log2(I)) + 1;
    110113    NewItem.SubItems.Add(FloatToStr(Round((1 - (J / N.Stream.Size)) * 100) / 100));
    111     Line := '';
    112     N.Stream.Position := 0;
    113     for J := 0 to N.Stream.Size - 1 do
    114       Line := Line + IntToStr(Integer(N.Stream.ReadBit));
    115     NewItem.SubItems.Add(Line);
     114    NewItem.SubItems.Add(N.Stream.AsString);
    116115
    117116    // Increment value
     
    142141end;
    143142
     143procedure TMainForm.Button3Click(Sender: TObject);
     144var
     145  N: TDynamicNumber;
     146begin
     147  try
     148    N := TDynamicNumber.Create;
     149    N.Stream.Size := 0;
     150    N.WriteNumber(StrToInt64(Edit1.Text));
     151    N.Stream.Position := 0;
     152    Edit2.Text := N.Stream.AsString;
     153  finally
     154    N.Free;
     155  end;
     156end;
     157
     158procedure TMainForm.Button4Click(Sender: TObject);
     159var
     160  N: TDynamicNumber;
     161begin
     162  try
     163    N := TDynamicNumber.Create;
     164    N.Stream.AsString := Edit2.Text;
     165    Edit3.Text := IntToStr(N.ReadNumber);
     166  finally
     167    N.Free;
     168  end;
     169end;
     170
    144171procedure TMainForm.FormCreate(Sender: TObject);
    145172begin
Note: See TracChangeset for help on using the changeset viewer.