Changeset 8 for ProtocolBuffers/UMainForm.pas
- Timestamp:
- Oct 12, 2009, 7:59:16 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
ProtocolBuffers/UMainForm.pas
r7 r8 9 9 StdCtrls, UProtocolBuffers, UMemoryStreamEx; 10 10 11 const 12 SampleProtoFileName = 'Sample.proto'; 13 11 14 type 12 15 { TMainForm } 13 16 TMainForm = class(TForm) 17 Button1: TButton; 18 Button2: TButton; 14 19 Memo1: TMemo; 20 procedure Button1Click(Sender: TObject); 21 procedure Button2Click(Sender: TObject); 15 22 procedure FormCreate(Sender: TObject); 16 23 procedure FormDestroy(Sender: TObject); 17 24 private 18 { private declarations }25 procedure DisplayStream(Stream: TStream); 19 26 public 20 27 PB: TProtocolBuffer; … … 29 36 30 37 procedure TMainForm.FormCreate(Sender: TObject); 38 begin 39 end; 40 41 procedure TMainForm.Button2Click(Sender: TObject); 42 var 43 Stream: TMemoryStream; 44 StringList: TStringList; 45 begin 46 Stream := TMemoryStreamEx.Create; 47 StringList := TStringList.Create; 48 StringList.LoadFromFile(SampleProtoFileName); 49 PB := TProtocolBuffer.Create; 50 with PB do begin 51 LoadFromProto(StringList); 52 SaveToStream(Stream); 53 end; 54 DisplayStream(Stream); 55 StringList.Free; 56 Stream.Free; 57 end; 58 59 procedure TMainForm.Button1Click(Sender: TObject); 31 60 var 32 61 Stream: TMemoryStreamEx; 33 Text: string;34 I: Integer;35 62 NewItem: TPBItem; 36 63 begin … … 45 72 end; 46 73 SaveToStream(Stream); 74 DisplayStream(Stream); 47 75 end; 48 49 Stream.Position := 0;50 Text := '';51 for I := 1 to Stream.Size do begin52 Text := Text + IntToHex(Stream.ReadByte, 2) + ' ';53 end;54 Memo1.Lines.Text := Text;55 76 Stream.Free; 56 77 end; … … 61 82 end; 62 83 84 procedure TMainForm.DisplayStream(Stream: TStream); 85 var 86 I: Integer; 87 Text: string; 88 begin 89 Stream.Position := 0; 90 Text := ''; 91 for I := 1 to Stream.Size do begin 92 Text := Text + IntToHex(Stream.ReadByte, 2) + ' '; 93 end; 94 Memo1.Lines.Text := Text; 95 end; 96 63 97 initialization 64 98 {$I UMainForm.lrs}
Note:
See TracChangeset
for help on using the changeset viewer.