Changeset 9


Ignore:
Timestamp:
Oct 12, 2009, 11:01:02 AM (15 years ago)
Author:
george
Message:
  • Modified: Enhanced loading from stream.
  • Added: Demo form is displaying original PB tree and target loaded PB tree.
Location:
ProtocolBuffers
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • ProtocolBuffers/Demo.lpi

    r8 r9  
    99      <Icon Value="0"/>
    1010      <UseXPManifest Value="True"/>
    11       <ActiveEditorIndexAtStart Value="2"/>
     11      <ActiveEditorIndexAtStart Value="1"/>
    1212    </General>
    1313    <VersionInfo>
     
    3333      </Item1>
    3434    </RequiredPackages>
    35     <Units Count="7">
     35    <Units Count="9">
    3636      <Unit0>
    3737        <Filename Value="Demo.lpr"/>
     
    4141        <TopLine Value="1"/>
    4242        <EditorIndex Value="6"/>
    43         <UsageCount Value="24"/>
     43        <UsageCount Value="30"/>
    4444        <Loaded Value="True"/>
    4545      </Unit0>
     
    5050        <ResourceBaseClass Value="Form"/>
    5151        <UnitName Value="UMainForm"/>
    52         <CursorPos X="29" Y="86"/>
    53         <TopLine Value="31"/>
     52        <CursorPos X="42" Y="112"/>
     53        <TopLine Value="79"/>
    5454        <EditorIndex Value="0"/>
    55         <UsageCount Value="24"/>
     55        <UsageCount Value="30"/>
    5656        <Loaded Value="True"/>
    5757      </Unit1>
     
    6060        <IsPartOfProject Value="True"/>
    6161        <UnitName Value="UProtocolBuffers"/>
    62         <CursorPos X="3" Y="87"/>
    63         <TopLine Value="85"/>
     62        <CursorPos X="45" Y="137"/>
     63        <TopLine Value="131"/>
    6464        <EditorIndex Value="1"/>
    65         <UsageCount Value="24"/>
     65        <UsageCount Value="30"/>
    6666        <Loaded Value="True"/>
    6767      </Unit2>
     
    7373        <TopLine Value="1"/>
    7474        <EditorIndex Value="5"/>
    75         <UsageCount Value="24"/>
     75        <UsageCount Value="30"/>
    7676        <Loaded Value="True"/>
    7777      </Unit3>
     
    8181        <TopLine Value="810"/>
    8282        <EditorIndex Value="4"/>
    83         <UsageCount Value="11"/>
     83        <UsageCount Value="14"/>
    8484        <Loaded Value="True"/>
    8585      </Unit4>
     
    9090        <TopLine Value="1"/>
    9191        <EditorIndex Value="3"/>
    92         <UsageCount Value="22"/>
     92        <UsageCount Value="28"/>
    9393        <Loaded Value="True"/>
    9494        <SyntaxHighlighter Value="None"/>
     
    101101        <TopLine Value="2"/>
    102102        <EditorIndex Value="2"/>
    103         <UsageCount Value="21"/>
     103        <UsageCount Value="27"/>
    104104        <Loaded Value="True"/>
    105105      </Unit6>
     106      <Unit7>
     107        <Filename Value="..\..\..\Programy\Lazarus_0.9.27\lcl\comctrls.pp"/>
     108        <UnitName Value="ComCtrls"/>
     109        <CursorPos X="19" Y="2336"/>
     110        <TopLine Value="2476"/>
     111        <UsageCount Value="11"/>
     112      </Unit7>
     113      <Unit8>
     114        <Filename Value="..\..\..\Programy\Lazarus_0.9.27\lcl\include\treeview.inc"/>
     115        <CursorPos X="1" Y="358"/>
     116        <TopLine Value="342"/>
     117        <UsageCount Value="10"/>
     118      </Unit8>
    106119    </Units>
    107120    <JumpHistory Count="30" HistoryIndex="29">
    108121      <Position1>
    109122        <Filename Value="UProtocolBuffers.pas"/>
    110         <Caret Line="159" Column="49" TopLine="144"/>
     123        <Caret Line="219" Column="1" TopLine="203"/>
    111124      </Position1>
    112125      <Position2>
    113126        <Filename Value="UProtocolBuffers.pas"/>
    114         <Caret Line="28" Column="14" TopLine="12"/>
     127        <Caret Line="29" Column="15" TopLine="13"/>
    115128      </Position2>
    116129      <Position3>
    117130        <Filename Value="UProtocolBuffers.pas"/>
    118         <Caret Line="170" Column="60" TopLine="155"/>
     131        <Caret Line="227" Column="5" TopLine="195"/>
    119132      </Position3>
    120133      <Position4>
    121         <Filename Value="UProtocolBuffers.pas"/>
    122         <Caret Line="175" Column="10" TopLine="159"/>
     134        <Filename Value="UMainForm.pas"/>
     135        <Caret Line="156" Column="9" TopLine="135"/>
    123136      </Position4>
    124137      <Position5>
    125         <Filename Value="UProtocolBuffers.pas"/>
    126         <Caret Line="206" Column="5" TopLine="174"/>
     138        <Filename Value="UMainForm.pas"/>
     139        <Caret Line="155" Column="16" TopLine="134"/>
    127140      </Position5>
    128141      <Position6>
    129142        <Filename Value="UProtocolBuffers.pas"/>
    130         <Caret Line="234" Column="1" TopLine="202"/>
     143        <Caret Line="136" Column="27" TopLine="120"/>
    131144      </Position6>
    132145      <Position7>
    133146        <Filename Value="UProtocolBuffers.pas"/>
    134         <Caret Line="222" Column="34" TopLine="203"/>
     147        <Caret Line="112" Column="9" TopLine="121"/>
    135148      </Position7>
    136149      <Position8>
    137150        <Filename Value="UProtocolBuffers.pas"/>
    138         <Caret Line="230" Column="37" TopLine="205"/>
     151        <Caret Line="134" Column="1" TopLine="118"/>
    139152      </Position8>
    140153      <Position9>
    141154        <Filename Value="UProtocolBuffers.pas"/>
    142         <Caret Line="223" Column="56" TopLine="207"/>
     155        <Caret Line="135" Column="1" TopLine="119"/>
    143156      </Position9>
    144157      <Position10>
    145158        <Filename Value="UProtocolBuffers.pas"/>
    146         <Caret Line="230" Column="55" TopLine="207"/>
     159        <Caret Line="136" Column="1" TopLine="120"/>
    147160      </Position10>
    148161      <Position11>
    149162        <Filename Value="UProtocolBuffers.pas"/>
    150         <Caret Line="229" Column="27" TopLine="207"/>
     163        <Caret Line="137" Column="1" TopLine="121"/>
    151164      </Position11>
    152165      <Position12>
    153166        <Filename Value="UProtocolBuffers.pas"/>
    154         <Caret Line="28" Column="15" TopLine="12"/>
     167        <Caret Line="135" Column="1" TopLine="119"/>
    155168      </Position12>
    156169      <Position13>
    157170        <Filename Value="UProtocolBuffers.pas"/>
    158         <Caret Line="229" Column="28" TopLine="207"/>
     171        <Caret Line="136" Column="1" TopLine="120"/>
    159172      </Position13>
    160173      <Position14>
    161174        <Filename Value="UProtocolBuffers.pas"/>
    162         <Caret Line="183" Column="65" TopLine="183"/>
     175        <Caret Line="137" Column="1" TopLine="121"/>
    163176      </Position14>
    164177      <Position15>
    165178        <Filename Value="UProtocolBuffers.pas"/>
    166         <Caret Line="88" Column="5" TopLine="56"/>
     179        <Caret Line="138" Column="1" TopLine="122"/>
    167180      </Position15>
    168181      <Position16>
    169182        <Filename Value="UProtocolBuffers.pas"/>
    170         <Caret Line="89" Column="27" TopLine="73"/>
     183        <Caret Line="141" Column="1" TopLine="125"/>
    171184      </Position16>
    172185      <Position17>
    173         <Filename Value="UMainForm.pas"/>
    174         <Caret Line="40" Column="19" TopLine="31"/>
     186        <Filename Value="UProtocolBuffers.pas"/>
     187        <Caret Line="142" Column="1" TopLine="126"/>
    175188      </Position17>
    176189      <Position18>
    177         <Filename Value="UMainForm.pas"/>
    178         <Caret Line="17" Column="22" TopLine="17"/>
     190        <Filename Value="UProtocolBuffers.pas"/>
     191        <Caret Line="135" Column="1" TopLine="119"/>
    179192      </Position18>
    180193      <Position19>
    181         <Filename Value="UMainForm.pas"/>
    182         <Caret Line="21" Column="5" TopLine="17"/>
     194        <Filename Value="UProtocolBuffers.pas"/>
     195        <Caret Line="136" Column="1" TopLine="120"/>
    183196      </Position19>
    184197      <Position20>
    185         <Filename Value="UMainForm.pas"/>
    186         <Caret Line="90" Column="5" TopLine="58"/>
     198        <Filename Value="UProtocolBuffers.pas"/>
     199        <Caret Line="137" Column="1" TopLine="121"/>
    187200      </Position20>
    188201      <Position21>
    189         <Filename Value="UMainForm.pas"/>
    190         <Caret Line="21" Column="5" TopLine="5"/>
     202        <Filename Value="UProtocolBuffers.pas"/>
     203        <Caret Line="138" Column="1" TopLine="122"/>
    191204      </Position21>
    192205      <Position22>
    193         <Filename Value="UMainForm.pas"/>
    194         <Caret Line="77" Column="1" TopLine="49"/>
     206        <Filename Value="UProtocolBuffers.pas"/>
     207        <Caret Line="141" Column="1" TopLine="125"/>
    195208      </Position22>
    196209      <Position23>
    197         <Filename Value="UMainForm.pas"/>
    198         <Caret Line="49" Column="15" TopLine="35"/>
     210        <Filename Value="UProtocolBuffers.pas"/>
     211        <Caret Line="142" Column="1" TopLine="126"/>
    199212      </Position23>
    200213      <Position24>
    201214        <Filename Value="UProtocolBuffers.pas"/>
    202         <Caret Line="63" Column="28" TopLine="43"/>
     215        <Caret Line="149" Column="1" TopLine="133"/>
    203216      </Position24>
    204217      <Position25>
    205         <Filename Value="UMainForm.pas"/>
    206         <Caret Line="49" Column="15" TopLine="35"/>
     218        <Filename Value="UProtocolBuffers.pas"/>
     219        <Caret Line="81" Column="39" TopLine="65"/>
    207220      </Position25>
    208221      <Position26>
    209         <Filename Value="UMainForm.pas"/>
    210         <Caret Line="51" Column="29" TopLine="35"/>
     222        <Filename Value="UProtocolBuffers.pas"/>
     223        <Caret Line="134" Column="1" TopLine="118"/>
    211224      </Position26>
    212225      <Position27>
    213         <Filename Value="UMainForm.pas"/>
    214         <Caret Line="56" Column="8" TopLine="40"/>
     226        <Filename Value="UProtocolBuffers.pas"/>
     227        <Caret Line="135" Column="1" TopLine="119"/>
    215228      </Position27>
    216229      <Position28>
    217         <Filename Value="UParser.pas"/>
    218         <Caret Line="14" Column="3" TopLine="1"/>
     230        <Filename Value="UProtocolBuffers.pas"/>
     231        <Caret Line="136" Column="6" TopLine="120"/>
    219232      </Position28>
    220233      <Position29>
    221         <Filename Value="UParser.pas"/>
    222         <Caret Line="34" Column="5" TopLine="2"/>
     234        <Filename Value="UProtocolBuffers.pas"/>
     235        <Caret Line="82" Column="19" TopLine="78"/>
    223236      </Position29>
    224237      <Position30>
    225         <Filename Value="UParser.pas"/>
    226         <Caret Line="7" Column="60" TopLine="3"/>
     238        <Filename Value="UMainForm.pas"/>
     239        <Caret Line="112" Column="39" TopLine="88"/>
    227240      </Position30>
    228241    </JumpHistory>
     
    246259  </CompilerOptions>
    247260  <Debugging>
     261    <BreakPoints Count="1">
     262      <Item1>
     263        <Source Value="UProtocolBuffers.pas"/>
     264        <Line Value="135"/>
     265      </Item1>
     266    </BreakPoints>
    248267    <Exceptions Count="3">
    249268      <Item1>
  • ProtocolBuffers/UMainForm.lfm

    r8 r9  
    11object MainForm: TMainForm
    2   Left = 281
    3   Height = 319
    4   Top = 189
    5   Width = 448
     2  Left = 254
     3  Height = 446
     4  Top = 150
     5  Width = 597
    66  Caption = 'Demo ProtocolBuffers'
    7   ClientHeight = 319
    8   ClientWidth = 448
     7  ClientHeight = 446
     8  ClientWidth = 597
    99  OnCreate = FormCreate
    1010  OnDestroy = FormDestroy
    1111  LCLVersion = '0.9.29'
    1212  object Memo1: TMemo
    13     Left = 9
    14     Height = 272
    15     Top = 9
    16     Width = 433
     13    Left = 7
     14    Height = 123
     15    Top = 320
     16    Width = 587
     17    Anchors = [akTop, akLeft, akRight, akBottom]
    1718    TabOrder = 0
    1819  end
     
    2930    Left = 88
    3031    Height = 25
    31     Top = 289
     32    Top = 288
    3233    Width = 75
    3334    Caption = 'From file'
     
    3536    TabOrder = 2
    3637  end
     38  object TreeView1: TTreeView
     39    Left = 9
     40    Height = 272
     41    Top = 7
     42    Width = 293
     43    DefaultItemHeight = 15
     44    TabOrder = 3
     45  end
     46  object TreeView2: TTreeView
     47    Left = 312
     48    Height = 272
     49    Top = 7
     50    Width = 279
     51    DefaultItemHeight = 15
     52    TabOrder = 4
     53  end
    3754end
  • ProtocolBuffers/UMainForm.lrs

    r8 r9  
     1{ Toto je automaticky generovaný zdrojový soubor lazarusu }
     2
    13LazarusResources.Add('TMainForm','FORMDATA',[
    2   'TPF0'#9'TMainForm'#8'MainForm'#4'Left'#3#25#1#6'Height'#3'?'#1#3'Top'#3#189#0
    3   +#5'Width'#3#192#1#7'Caption'#6#20'Demo ProtocolBuffers'#12'ClientHeight'#3'?'
    4   +#1#11'ClientWidth'#3#192#1#8'OnCreate'#7#10'FormCreate'#9'OnDestroy'#7#11'Fo'
    5   +'rmDestroy'#10'LCLVersion'#6#6'0.9.29'#0#5'TMemo'#5'Memo1'#4'Left'#2#9#6'Hei'
    6   +'ght'#3#16#1#3'Top'#2#9#5'Width'#3#177#1#8'TabOrder'#2#0#0#0#7'TButton'#7'Bu'
    7   +'tton1'#4'Left'#2#7#6'Height'#2#25#3'Top'#3' '#1#5'Width'#2'K'#7'Caption'#6#7
    8   +'Runtime'#7'OnClick'#7#12'Button1Click'#8'TabOrder'#2#1#0#0#7'TButton'#7'But'
    9   +'ton2'#4'Left'#2'X'#6'Height'#2#25#3'Top'#3'!'#1#5'Width'#2'K'#7'Caption'#6#9
    10   +'From file'#7'OnClick'#7#12'Button2Click'#8'TabOrder'#2#2#0#0#0
     4  'TPF0'#9'TMainForm'#8'MainForm'#4'Left'#3#254#0#6'Height'#3#190#1#3'Top'#3#150
     5  +#0#5'Width'#3'U'#2#7'Caption'#6#20'Demo ProtocolBuffers'#12'ClientHeight'#3
     6  +#190#1#11'ClientWidth'#3'U'#2#8'OnCreate'#7#10'FormCreate'#9'OnDestroy'#7#11
     7  +'FormDestroy'#10'LCLVersion'#6#6'0.9.29'#0#5'TMemo'#5'Memo1'#4'Left'#2#7#6'H'
     8  +'eight'#2'{'#3'Top'#3'@'#1#5'Width'#3'K'#2#7'Anchors'#11#5'akTop'#6'akLeft'#7
     9  +'akRight'#8'akBottom'#0#8'TabOrder'#2#0#0#0#7'TButton'#7'Button1'#4'Left'#2#7
     10  +#6'Height'#2#25#3'Top'#3' '#1#5'Width'#2'K'#7'Caption'#6#7'Runtime'#7'OnClic'
     11  +'k'#7#12'Button1Click'#8'TabOrder'#2#1#0#0#7'TButton'#7'Button2'#4'Left'#2'X'
     12  +#6'Height'#2#25#3'Top'#3' '#1#5'Width'#2'K'#7'Caption'#6#9'From file'#7'OnCl'
     13  +'ick'#7#12'Button2Click'#8'TabOrder'#2#2#0#0#9'TTreeView'#9'TreeView1'#4'Lef'
     14  +'t'#2#9#6'Height'#3#16#1#3'Top'#2#7#5'Width'#3'%'#1#17'DefaultItemHeight'#2
     15  +#15#8'TabOrder'#2#3#0#0#9'TTreeView'#9'TreeView2'#4'Left'#3'8'#1#6'Height'#3
     16  +#16#1#3'Top'#2#7#5'Width'#3#23#1#17'DefaultItemHeight'#2#15#8'TabOrder'#2#4#0
     17  +#0#0
    1118]);
  • ProtocolBuffers/UMainForm.pas

    r8 r9  
    77uses
    88  Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
    9   StdCtrls, UProtocolBuffers, UMemoryStreamEx;
     9  StdCtrls, ComCtrls, UProtocolBuffers, UMemoryStreamEx;
    1010
    1111const
     
    1818    Button2: TButton;
    1919    Memo1: TMemo;
     20    TreeView1: TTreeView;
     21    TreeView2: TTreeView;
    2022    procedure Button1Click(Sender: TObject);
    2123    procedure Button2Click(Sender: TObject);
     
    2426  private
    2527    procedure DisplayStream(Stream: TStream);
     28    procedure DisplayTree(ProtocolBuffer: TProtocolBuffer; TreeView: TTreeView);
     29    procedure MessageToNode(PBMessage: TPBMessageItem; Node: TTreeNode);
    2630  public
    27     PB: TProtocolBuffer;
    28   end;
     31  end;
    2932
    3033var
     
    4346  Stream: TMemoryStream;
    4447  StringList: TStringList;
     48  PB: TProtocolBuffer;
    4549begin
    4650  Stream := TMemoryStreamEx.Create;
     
    6165  Stream: TMemoryStreamEx;
    6266  NewItem: TPBItem;
     67  PB: TProtocolBuffer;
    6368begin
    6469  Stream := TMemoryStreamEx.Create;
     
    6873      Name := 'SampleMessage';
    6974      NewItem := TPBIntegerItem.Create;
    70       TPBIntegerItem(NewItem).Value := $5555555;
     75      TPBIntegerItem(NewItem).Name := 'Height';
     76      TPBIntegerItem(NewItem).Tag := 1;
     77      TPBIntegerItem(NewItem).Value := 12;
     78      Items.Add(NewItem);
     79      NewItem := TPBIntegerItem.Create;
     80      TPBIntegerItem(NewItem).Name := 'Width';
     81      TPBIntegerItem(NewItem).Tag := 2;
     82      TPBIntegerItem(NewItem).Value := 34;
     83      Items.Add(NewItem);
     84      NewItem := TPBIntegerItem.Create;
     85      TPBIntegerItem(NewItem).Name := 'Age';
     86      TPBIntegerItem(NewItem).Tag := 3;
     87      TPBIntegerItem(NewItem).Value := 45;
    7188      Items.Add(NewItem);
    7289    end;
     90    DisplayTree(PB, TreeView1);
    7391    SaveToStream(Stream);
    74     DisplayStream(Stream);
     92    Free;
     93  end;
     94
     95  DisplayStream(Stream);
     96  Stream.Position := 0;
     97
     98  PB := TProtocolBuffer.Create;
     99  with PB do begin
     100    with BaseMessage do begin
     101      Name := 'SampleMessage';
     102      NewItem := TPBIntegerItem.Create;
     103      TPBIntegerItem(NewItem).Name := 'Height';
     104      TPBIntegerItem(NewItem).Tag := 1;
     105      Items.Add(NewItem);
     106      NewItem := TPBIntegerItem.Create;
     107      TPBIntegerItem(NewItem).Name := 'Age';
     108      TPBIntegerItem(NewItem).Tag := 3;
     109      Items.Add(NewItem);
     110      NewItem := TPBIntegerItem.Create;
     111      TPBIntegerItem(NewItem).Name := 'Weight';
     112      TPBIntegerItem(NewItem).Tag := 4;
     113      Items.Add(NewItem);
     114    end;
     115    LoadFromStream(Stream);
     116    DisplayTree(PB, TreeView2);
     117    Free;
    75118  end;
    76119  Stream.Free;
     
    79122procedure TMainForm.FormDestroy(Sender: TObject);
    80123begin
    81   PB.Free;
    82124end;
    83125
     
    95137end;
    96138
     139procedure TMainForm.DisplayTree(ProtocolBuffer: TProtocolBuffer;
     140  TreeView: TTreeView);
     141begin
     142  with TreeView do begin
     143    BeginUpdate;
     144    Items.Clear;
     145    TopItem := Items.Add(nil, 'message');
     146    MessageToNode(ProtocolBuffer.BaseMessage, TopItem);
     147    TopItem.Expand(True);
     148    EndUpdate;
     149  end;
     150end;
     151
     152procedure TMainForm.MessageToNode(PBMessage: TPBMessageItem; Node: TTreeNode);
     153var
     154  I: Integer;
     155  NewNode: TTreeNode;
     156begin
     157  for I := 0 to PBMessage.Items.Count - 1 do begin
     158    NewNode := Node.Owner.AddChild(Node, '');
     159    if TPBItem(PBMessage.Items[I]) is TPBStringItem then begin
     160      NewNode.Text := IntToStr(TPBItem(PBMessage.Items[I]).Tag) + ': string ' +
     161        TPBItem(PBMessage.Items[I]).Name + ' = ' +
     162        TPBStringItem(PBMessage.Items[I]).Value;
     163    end else
     164    if TPBItem(PBMessage.Items[I]) is TPBIntegerItem then begin
     165      NewNode.Text := IntToStr(TPBItem(PBMessage.Items[I]).Tag) + ': uint32 ' +
     166        TPBItem(PBMessage.Items[I]).Name + ' = ' +
     167        IntToStr(TPBIntegerItem(PBMessage.Items[I]).Value);
     168    end else
     169    if TPBItem(PBMessage.Items[I]) is TPBMessageItem then begin
     170      NewNode.Text := IntToStr(TPBItem(PBMessage.Items[I]).Tag) + ': message ' +
     171        TPBItem(PBMessage.Items[I]).Name;
     172      MessageToNode(TPBMessageItem(PBMessage.Items[I]), NewNode);
     173    end;
     174
     175  end;
     176end;
     177
    97178initialization
    98179  {$I UMainForm.lrs}
  • ProtocolBuffers/UProtocolBuffers.pas

    r8 r9  
    2525    procedure SaveVariantToStream(Stream: TStream; Value: Integer);
    2626    function LoadVariantFromStream(Stream: TStream): Integer;
     27    procedure SaveHeadToStream(Stream: TStream);
     28    procedure LoadHeadFromStream(Stream: TStream);
    2729    procedure SaveToStream(Stream: TStream); virtual;
    2830    procedure LoadFromStream(Stream: TStream); virtual;
     
    5052  TPBMessageItem = class(TPBItem)
    5153    Items: TList; // TList<TPBItem>;
     54    function SearchItemByTag(Tag: Integer): TPBItem;
    5255    procedure SaveToStream(Stream: TStream); override;
    5356    procedure LoadFromStream(Stream: TStream); override;
     
    7578procedure TProtocolBuffer.LoadFromStream(Stream: TStream);
    7679begin
     80  BaseMessage.LoadHeadFromStream(Stream);
    7781  BaseMessage.LoadFromStream(Stream);
    7882end;
     
    101105{ TPBMessageItem }
    102106
     107function TPBMessageItem.SearchItemByTag(Tag: Integer): TPBItem;
     108var
     109  I: Integer;
     110begin
     111  I := 0;
     112  while (I < Items.Count) and (TPBItem(Items[I]).Tag <> Tag) do Inc(I);
     113  if I < Items.Count then Result := Items[I]
     114    else Result := nil;
     115end;
     116
    103117procedure TPBMessageItem.SaveToStream(Stream: TStream);
    104118var
    105119  I: Integer;
    106120begin
    107   inherited SaveToStream(Stream);
     121  inherited;
     122  SaveHeadToStream(Stream);
    108123  for I := 0 to Items.Count - 1 do
    109124    TPBItem(Items[I]).SaveToStream(Stream);
     
    113128var
    114129  I: Integer;
    115 begin
    116   inherited LoadFromStream(Stream);
    117   for I := 0 to Items.Count - 1 do
    118     TPBItem(Items[I]).LoadFromStream(Stream);
     130  TempItem: TPBItem;
     131  SearchItem: TPBItem;
     132begin
     133  inherited;
     134  TempItem := TPBItem.Create;
     135  for I := 0 to Items.Count - 1 do begin
     136    TempItem.LoadHeadFromStream(Stream);
     137    SearchItem := SearchItemByTag(TempItem.Tag);
     138    if Assigned(SearchItem) then begin
     139      if SearchItem.ItemType <> TempItem.ItemType then
     140        raise Exception.Create('Bad type for item "' + SearchItem.Name +
     141          '" with tag ' + IntToStr(SearchItem.Tag));
     142      if SearchItem is TPBIntegerItem then
     143        TPBIntegerItem(SearchItem).LoadFromStream(Stream)
     144      else if SearchItem is TPBStringItem then
     145        TPBStringItem(SearchItem).LoadFromStream(Stream)
     146      else if SearchItem is TPBMessageItem then
     147        TPBMessageItem(SearchItem).LoadFromStream(Stream);
     148    end;
     149  end;
    119150end;
    120151
     
    154185end;
    155186
    156 procedure TPBItem.SaveToStream(Stream: TStream);
     187procedure TPBItem.SaveHeadToStream(Stream: TStream);
    157188var
    158189  ByteIndex: Byte;
     
    171202end;
    172203
    173 procedure TPBItem.LoadFromStream(Stream: TStream);
     204procedure TPBItem.LoadHeadFromStream(Stream: TStream);
    174205var
    175206  Data: Byte;
     
    187218end;
    188219
     220procedure TPBItem.SaveToStream(Stream: TStream);
     221begin
     222
     223end;
     224
     225procedure TPBItem.LoadFromStream(Stream: TStream);
     226begin
     227
     228end;
     229
    189230function TPBItem.LoadVariantFromStream(Stream: TStream): Integer;
    190231var
     
    206247procedure TPBIntegerItem.SaveToStream(Stream: TStream);
    207248begin
    208   inherited SaveToStream(Stream);
     249  inherited;
     250  SaveHeadToStream(Stream);
    209251  SaveVariantToStream(Stream, Value);
    210252end;
     
    212254procedure TPBIntegerItem.LoadFromStream(Stream: TStream);
    213255begin
    214   inherited LoadFromStream(Stream);
    215   LoadVariantFromStream(Stream);
     256  inherited;
     257  Value := LoadVariantFromStream(Stream);
    216258end;
    217259
     
    225267procedure TPBStringItem.SaveToStream(Stream: TStream);
    226268begin
    227   inherited SaveToStream(Stream);
     269  inherited;
     270  SaveHeadToStream(Stream);
    228271  SaveVariantToStream(Stream, Length(Value));
    229272  TMemoryStreamEx(Stream).Write(Value[1], Length(Value));
     
    232275procedure TPBStringItem.LoadFromStream(Stream: TStream);
    233276begin
    234   inherited LoadFromStream(Stream);
     277  inherited;
    235278  SetLength(Value, LoadVariantFromStream(Stream));
    236279  TMemoryStreamEx(Stream).Read(Value[1], Length(Value));
Note: See TracChangeset for help on using the changeset viewer.