Ignore:
Timestamp:
Feb 23, 2011, 7:42:22 AM (14 years ago)
Author:
george
Message:
  • Added: Demo of indexed varblock structure.
File:
1 edited

Legend:

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

    r172 r173  
    1515  TMainForm = class(TForm)
    1616  published
     17    ButtonEncodeIndexed: TButton;
     18    ButtonDecodeIndexed: TButton;
     19    ButtonDecodeRaw: TButton;
    1720    ButtonDecodeString: TButton;
    18     ButtonDecodeRaw: TButton;
     21    ButtonEncodeRaw: TButton;
    1922    ButtonEncodeString: TButton;
    20     ButtonEncodeRaw: TButton;
    2123    ButtonFloatDecode1: TButton;
    2224    ButtonFloatEncode1: TButton;
    23     ButtonUIntDecode: TButton;
    2425    ButtonSIntDecode: TButton;
    2526    ButtonSIntEncode: TButton;
     27    ButtonUIntDecode: TButton;
     28    ButtonUIntEncode: TButton;
     29    CheckBoxMask1: TCheckBox;
     30    CheckBoxMask2: TCheckBox;
     31    CheckBoxMask3: TCheckBox;
     32    EditIndexedItem1: TEdit;
     33    EditIndexedItem2: TEdit;
     34    EditIndexedItem3: TEdit;
     35    EditIndexed: TEdit;
     36    EditFloat: TEdit;
    2637    EditRaw: TEdit;
    27     EditFloat: TEdit;
     38    EditRawData: TEdit;
     39    EditSInt: TEdit;
     40    EditString: TEdit;
    2841    EditStringData: TEdit;
    29     EditString: TEdit;
    30     EditRawData: TEdit;
    3142    EditUInt: TEdit;
    32     ButtonUIntEncode: TButton;
    33     EditSInt: TEdit;
    3443    FloatSpinEdit1: TFloatSpinEdit;
    3544    GroupBox1: TGroupBox;
     
    3948    GroupBox5: TGroupBox;
    4049    Label1: TLabel;
     50    Label2: TLabel;
     51    Label3: TLabel;
     52    Label4: TLabel;
     53    Label5: TLabel;
     54    Label6: TLabel;
     55    PageControl1: TPageControl;
    4156    SpinEditFloat: TSpinEdit;
     57    SpinEditSInt: TSpinEdit;
    4258    SpinEditUInt: TSpinEdit;
    43     SpinEditSInt: TSpinEdit;
     59    TabSheet1: TTabSheet;
     60    TabSheet2: TTabSheet;
     61    procedure ButtonDecodeIndexedClick(Sender: TObject);
     62    procedure ButtonEncodeIndexedClick(Sender: TObject);
    4463    procedure ButtonDecodeRawClick(Sender: TObject);
    4564    procedure ButtonDecodeStringClick(Sender: TObject);
     
    5271    procedure ButtonUIntDecodeClick(Sender: TObject);
    5372    procedure ButtonUIntEncodeClick(Sender: TObject);
     73    procedure FormShow(Sender: TObject);
    5474  public
    5575    function StreamToString(Stream: TStream): string;
     
    81101    Stream.Free;
    82102    Block.Free;
     103  end;
     104end;
     105
     106procedure TMainForm.ButtonEncodeIndexedClick(Sender: TObject);
     107var
     108  IndexedBlock: TVarBlockIndexed;
     109  Stream: TMemoryStream;
     110begin
     111  try
     112    IndexedBlock := TVarBlockIndexed.Create;
     113    Stream := TMemoryStream.Create;
     114    if CheckBoxMask1.Checked then begin
     115      StringToStream(EditIndexedItem1.Text, Stream);
     116      IndexedBlock.WriteVarStream(0, Stream);
     117    end;
     118    if CheckBoxMask2.Checked then begin
     119      StringToStream(EditIndexedItem2.Text, Stream);
     120      IndexedBlock.WriteVarStream(1, Stream);
     121    end;
     122    if CheckBoxMask3.Checked then begin
     123      StringToStream(EditIndexedItem3.Text, Stream);
     124      IndexedBlock.WriteVarStream(2, Stream);
     125    end;
     126    Stream.Clear;
     127    IndexedBlock.WriteToStream(Stream);
     128    EditIndexed.Text := StreamToString(Stream);
     129  finally
     130    IndexedBlock.Free;
     131    Stream.Free;
     132  end;
     133end;
     134
     135procedure TMainForm.ButtonDecodeIndexedClick(Sender: TObject);
     136var
     137  IndexedBlock: TVarBlockIndexed;
     138  Stream: TMemoryStream;
     139begin
     140  try
     141    IndexedBlock := TVarBlockIndexed.Create;
     142    Stream := TMemoryStream.Create;
     143    StringToStream(EditIndexed.Text, Stream);
     144    IndexedBlock.ReadFromStream(Stream);
     145
     146    CheckBoxMask1.Checked := IndexedBlock.TestIndex(0);
     147    CheckBoxMask2.Checked := IndexedBlock.TestIndex(1);
     148    CheckBoxMask3.Checked := IndexedBlock.TestIndex(2);
     149
     150    Stream.Clear;
     151    if IndexedBlock.TestIndex(0) then begin
     152      IndexedBlock.ReadVarStream(0, Stream);
     153      EditIndexedItem1.Text := StreamToString(Stream);
     154    end else EditIndexedItem1.Text := '';
     155    if IndexedBlock.TestIndex(1) then begin
     156      IndexedBlock.ReadVarStream(1, Stream);
     157      EditIndexedItem2.Text := StreamToString(Stream);
     158    end else EditIndexedItem2.Text := '';
     159    if IndexedBlock.TestIndex(2) then begin
     160      IndexedBlock.ReadVarStream(2, Stream);
     161      EditIndexedItem3.Text := StreamToString(Stream);
     162    end else EditIndexedItem3.Text := '';
     163  finally
     164    IndexedBlock.Free;
     165    Stream.Free;
    83166  end;
    84167end;
     
    207290    Block.Free;
    208291  end;
     292end;
     293
     294procedure TMainForm.FormShow(Sender: TObject);
     295begin
     296  PageControl1.TabIndex := 0;
    209297end;
    210298
     
    246334    Delete(Text, 1, Pos(' ', Text));
    247335  end;
    248   if TryHexToInt(Text, Number) and (Number < 256) then
     336  if TryHexToInt(Text, Number) and (Number < 256) and (Text <> '') then
    249337    Stream.WriteByte(Number);
    250338end;
Note: See TracChangeset for help on using the changeset viewer.