Ignore:
Timestamp:
Oct 12, 2009, 7:59:16 AM (15 years ago)
Author:
george
Message:
  • Added: Uncompleted proto file loading support.
  • Modified: String type serialization implmentation.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • ProtocolBuffers/UMainForm.pas

    r7 r8  
    99  StdCtrls, UProtocolBuffers, UMemoryStreamEx;
    1010
     11const
     12  SampleProtoFileName = 'Sample.proto';
     13
    1114type
    1215  { TMainForm }
    1316  TMainForm = class(TForm)
     17    Button1: TButton;
     18    Button2: TButton;
    1419    Memo1: TMemo;
     20    procedure Button1Click(Sender: TObject);
     21    procedure Button2Click(Sender: TObject);
    1522    procedure FormCreate(Sender: TObject);
    1623    procedure FormDestroy(Sender: TObject);
    1724  private
    18     { private declarations }
     25    procedure DisplayStream(Stream: TStream);
    1926  public
    2027    PB: TProtocolBuffer;
     
    2936
    3037procedure TMainForm.FormCreate(Sender: TObject);
     38begin
     39end;
     40
     41procedure TMainForm.Button2Click(Sender: TObject);
     42var
     43  Stream: TMemoryStream;
     44  StringList: TStringList;
     45begin
     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;
     57end;
     58
     59procedure TMainForm.Button1Click(Sender: TObject);
    3160var
    3261  Stream: TMemoryStreamEx;
    33   Text: string;
    34   I: Integer;
    3562  NewItem: TPBItem;
    3663begin
     
    4572    end;
    4673    SaveToStream(Stream);
     74    DisplayStream(Stream);
    4775  end;
    48 
    49   Stream.Position := 0;
    50   Text := '';
    51   for I := 1 to Stream.Size do begin
    52     Text := Text + IntToHex(Stream.ReadByte, 2) + ' ';
    53   end;
    54   Memo1.Lines.Text := Text;
    5576  Stream.Free;
    5677end;
     
    6182end;
    6283
     84procedure TMainForm.DisplayStream(Stream: TStream);
     85var
     86  I: Integer;
     87  Text: string;
     88begin
     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;
     95end;
     96
    6397initialization
    6498  {$I UMainForm.lrs}
Note: See TracChangeset for help on using the changeset viewer.