Changeset 173 for CoolStreaming/Demo/VarBlockSerializer/UMainForm.pas
- Timestamp:
- Feb 23, 2011, 7:42:22 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
CoolStreaming/Demo/VarBlockSerializer/UMainForm.pas
r172 r173 15 15 TMainForm = class(TForm) 16 16 published 17 ButtonEncodeIndexed: TButton; 18 ButtonDecodeIndexed: TButton; 19 ButtonDecodeRaw: TButton; 17 20 ButtonDecodeString: TButton; 18 Button DecodeRaw: TButton;21 ButtonEncodeRaw: TButton; 19 22 ButtonEncodeString: TButton; 20 ButtonEncodeRaw: TButton;21 23 ButtonFloatDecode1: TButton; 22 24 ButtonFloatEncode1: TButton; 23 ButtonUIntDecode: TButton;24 25 ButtonSIntDecode: TButton; 25 26 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; 26 37 EditRaw: TEdit; 27 EditFloat: TEdit; 38 EditRawData: TEdit; 39 EditSInt: TEdit; 40 EditString: TEdit; 28 41 EditStringData: TEdit; 29 EditString: TEdit;30 EditRawData: TEdit;31 42 EditUInt: TEdit; 32 ButtonUIntEncode: TButton;33 EditSInt: TEdit;34 43 FloatSpinEdit1: TFloatSpinEdit; 35 44 GroupBox1: TGroupBox; … … 39 48 GroupBox5: TGroupBox; 40 49 Label1: TLabel; 50 Label2: TLabel; 51 Label3: TLabel; 52 Label4: TLabel; 53 Label5: TLabel; 54 Label6: TLabel; 55 PageControl1: TPageControl; 41 56 SpinEditFloat: TSpinEdit; 57 SpinEditSInt: TSpinEdit; 42 58 SpinEditUInt: TSpinEdit; 43 SpinEditSInt: TSpinEdit; 59 TabSheet1: TTabSheet; 60 TabSheet2: TTabSheet; 61 procedure ButtonDecodeIndexedClick(Sender: TObject); 62 procedure ButtonEncodeIndexedClick(Sender: TObject); 44 63 procedure ButtonDecodeRawClick(Sender: TObject); 45 64 procedure ButtonDecodeStringClick(Sender: TObject); … … 52 71 procedure ButtonUIntDecodeClick(Sender: TObject); 53 72 procedure ButtonUIntEncodeClick(Sender: TObject); 73 procedure FormShow(Sender: TObject); 54 74 public 55 75 function StreamToString(Stream: TStream): string; … … 81 101 Stream.Free; 82 102 Block.Free; 103 end; 104 end; 105 106 procedure TMainForm.ButtonEncodeIndexedClick(Sender: TObject); 107 var 108 IndexedBlock: TVarBlockIndexed; 109 Stream: TMemoryStream; 110 begin 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; 133 end; 134 135 procedure TMainForm.ButtonDecodeIndexedClick(Sender: TObject); 136 var 137 IndexedBlock: TVarBlockIndexed; 138 Stream: TMemoryStream; 139 begin 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; 83 166 end; 84 167 end; … … 207 290 Block.Free; 208 291 end; 292 end; 293 294 procedure TMainForm.FormShow(Sender: TObject); 295 begin 296 PageControl1.TabIndex := 0; 209 297 end; 210 298 … … 246 334 Delete(Text, 1, Pos(' ', Text)); 247 335 end; 248 if TryHexToInt(Text, Number) and (Number < 256) then336 if TryHexToInt(Text, Number) and (Number < 256) and (Text <> '') then 249 337 Stream.WriteByte(Number); 250 338 end;
Note:
See TracChangeset
for help on using the changeset viewer.