Changeset 9 for ProtocolBuffers
- Timestamp:
- Oct 12, 2009, 11:01:02 AM (15 years ago)
- Location:
- ProtocolBuffers
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
ProtocolBuffers/Demo.lpi
r8 r9 9 9 <Icon Value="0"/> 10 10 <UseXPManifest Value="True"/> 11 <ActiveEditorIndexAtStart Value=" 2"/>11 <ActiveEditorIndexAtStart Value="1"/> 12 12 </General> 13 13 <VersionInfo> … … 33 33 </Item1> 34 34 </RequiredPackages> 35 <Units Count=" 7">35 <Units Count="9"> 36 36 <Unit0> 37 37 <Filename Value="Demo.lpr"/> … … 41 41 <TopLine Value="1"/> 42 42 <EditorIndex Value="6"/> 43 <UsageCount Value=" 24"/>43 <UsageCount Value="30"/> 44 44 <Loaded Value="True"/> 45 45 </Unit0> … … 50 50 <ResourceBaseClass Value="Form"/> 51 51 <UnitName Value="UMainForm"/> 52 <CursorPos X=" 29" Y="86"/>53 <TopLine Value=" 31"/>52 <CursorPos X="42" Y="112"/> 53 <TopLine Value="79"/> 54 54 <EditorIndex Value="0"/> 55 <UsageCount Value=" 24"/>55 <UsageCount Value="30"/> 56 56 <Loaded Value="True"/> 57 57 </Unit1> … … 60 60 <IsPartOfProject Value="True"/> 61 61 <UnitName Value="UProtocolBuffers"/> 62 <CursorPos X=" 3" Y="87"/>63 <TopLine Value=" 85"/>62 <CursorPos X="45" Y="137"/> 63 <TopLine Value="131"/> 64 64 <EditorIndex Value="1"/> 65 <UsageCount Value=" 24"/>65 <UsageCount Value="30"/> 66 66 <Loaded Value="True"/> 67 67 </Unit2> … … 73 73 <TopLine Value="1"/> 74 74 <EditorIndex Value="5"/> 75 <UsageCount Value=" 24"/>75 <UsageCount Value="30"/> 76 76 <Loaded Value="True"/> 77 77 </Unit3> … … 81 81 <TopLine Value="810"/> 82 82 <EditorIndex Value="4"/> 83 <UsageCount Value="1 1"/>83 <UsageCount Value="14"/> 84 84 <Loaded Value="True"/> 85 85 </Unit4> … … 90 90 <TopLine Value="1"/> 91 91 <EditorIndex Value="3"/> 92 <UsageCount Value="2 2"/>92 <UsageCount Value="28"/> 93 93 <Loaded Value="True"/> 94 94 <SyntaxHighlighter Value="None"/> … … 101 101 <TopLine Value="2"/> 102 102 <EditorIndex Value="2"/> 103 <UsageCount Value="2 1"/>103 <UsageCount Value="27"/> 104 104 <Loaded Value="True"/> 105 105 </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> 106 119 </Units> 107 120 <JumpHistory Count="30" HistoryIndex="29"> 108 121 <Position1> 109 122 <Filename Value="UProtocolBuffers.pas"/> 110 <Caret Line=" 159" Column="49" TopLine="144"/>123 <Caret Line="219" Column="1" TopLine="203"/> 111 124 </Position1> 112 125 <Position2> 113 126 <Filename Value="UProtocolBuffers.pas"/> 114 <Caret Line="2 8" Column="14" TopLine="12"/>127 <Caret Line="29" Column="15" TopLine="13"/> 115 128 </Position2> 116 129 <Position3> 117 130 <Filename Value="UProtocolBuffers.pas"/> 118 <Caret Line=" 170" Column="60" TopLine="155"/>131 <Caret Line="227" Column="5" TopLine="195"/> 119 132 </Position3> 120 133 <Position4> 121 <Filename Value="U ProtocolBuffers.pas"/>122 <Caret Line="1 75" Column="10" TopLine="159"/>134 <Filename Value="UMainForm.pas"/> 135 <Caret Line="156" Column="9" TopLine="135"/> 123 136 </Position4> 124 137 <Position5> 125 <Filename Value="U ProtocolBuffers.pas"/>126 <Caret Line=" 206" Column="5" TopLine="174"/>138 <Filename Value="UMainForm.pas"/> 139 <Caret Line="155" Column="16" TopLine="134"/> 127 140 </Position5> 128 141 <Position6> 129 142 <Filename Value="UProtocolBuffers.pas"/> 130 <Caret Line=" 234" Column="1" TopLine="202"/>143 <Caret Line="136" Column="27" TopLine="120"/> 131 144 </Position6> 132 145 <Position7> 133 146 <Filename Value="UProtocolBuffers.pas"/> 134 <Caret Line=" 222" Column="34" TopLine="203"/>147 <Caret Line="112" Column="9" TopLine="121"/> 135 148 </Position7> 136 149 <Position8> 137 150 <Filename Value="UProtocolBuffers.pas"/> 138 <Caret Line=" 230" Column="37" TopLine="205"/>151 <Caret Line="134" Column="1" TopLine="118"/> 139 152 </Position8> 140 153 <Position9> 141 154 <Filename Value="UProtocolBuffers.pas"/> 142 <Caret Line=" 223" Column="56" TopLine="207"/>155 <Caret Line="135" Column="1" TopLine="119"/> 143 156 </Position9> 144 157 <Position10> 145 158 <Filename Value="UProtocolBuffers.pas"/> 146 <Caret Line=" 230" Column="55" TopLine="207"/>159 <Caret Line="136" Column="1" TopLine="120"/> 147 160 </Position10> 148 161 <Position11> 149 162 <Filename Value="UProtocolBuffers.pas"/> 150 <Caret Line=" 229" Column="27" TopLine="207"/>163 <Caret Line="137" Column="1" TopLine="121"/> 151 164 </Position11> 152 165 <Position12> 153 166 <Filename Value="UProtocolBuffers.pas"/> 154 <Caret Line=" 28" Column="15" TopLine="12"/>167 <Caret Line="135" Column="1" TopLine="119"/> 155 168 </Position12> 156 169 <Position13> 157 170 <Filename Value="UProtocolBuffers.pas"/> 158 <Caret Line=" 229" Column="28" TopLine="207"/>171 <Caret Line="136" Column="1" TopLine="120"/> 159 172 </Position13> 160 173 <Position14> 161 174 <Filename Value="UProtocolBuffers.pas"/> 162 <Caret Line="1 83" Column="65" TopLine="183"/>175 <Caret Line="137" Column="1" TopLine="121"/> 163 176 </Position14> 164 177 <Position15> 165 178 <Filename Value="UProtocolBuffers.pas"/> 166 <Caret Line=" 88" Column="5" TopLine="56"/>179 <Caret Line="138" Column="1" TopLine="122"/> 167 180 </Position15> 168 181 <Position16> 169 182 <Filename Value="UProtocolBuffers.pas"/> 170 <Caret Line=" 89" Column="27" TopLine="73"/>183 <Caret Line="141" Column="1" TopLine="125"/> 171 184 </Position16> 172 185 <Position17> 173 <Filename Value="U MainForm.pas"/>174 <Caret Line=" 40" Column="19" TopLine="31"/>186 <Filename Value="UProtocolBuffers.pas"/> 187 <Caret Line="142" Column="1" TopLine="126"/> 175 188 </Position17> 176 189 <Position18> 177 <Filename Value="U MainForm.pas"/>178 <Caret Line="1 7" Column="22" TopLine="17"/>190 <Filename Value="UProtocolBuffers.pas"/> 191 <Caret Line="135" Column="1" TopLine="119"/> 179 192 </Position18> 180 193 <Position19> 181 <Filename Value="U MainForm.pas"/>182 <Caret Line=" 21" Column="5" TopLine="17"/>194 <Filename Value="UProtocolBuffers.pas"/> 195 <Caret Line="136" Column="1" TopLine="120"/> 183 196 </Position19> 184 197 <Position20> 185 <Filename Value="U MainForm.pas"/>186 <Caret Line=" 90" Column="5" TopLine="58"/>198 <Filename Value="UProtocolBuffers.pas"/> 199 <Caret Line="137" Column="1" TopLine="121"/> 187 200 </Position20> 188 201 <Position21> 189 <Filename Value="U MainForm.pas"/>190 <Caret Line=" 21" Column="5" TopLine="5"/>202 <Filename Value="UProtocolBuffers.pas"/> 203 <Caret Line="138" Column="1" TopLine="122"/> 191 204 </Position21> 192 205 <Position22> 193 <Filename Value="U MainForm.pas"/>194 <Caret Line=" 77" Column="1" TopLine="49"/>206 <Filename Value="UProtocolBuffers.pas"/> 207 <Caret Line="141" Column="1" TopLine="125"/> 195 208 </Position22> 196 209 <Position23> 197 <Filename Value="U MainForm.pas"/>198 <Caret Line=" 49" Column="15" TopLine="35"/>210 <Filename Value="UProtocolBuffers.pas"/> 211 <Caret Line="142" Column="1" TopLine="126"/> 199 212 </Position23> 200 213 <Position24> 201 214 <Filename Value="UProtocolBuffers.pas"/> 202 <Caret Line=" 63" Column="28" TopLine="43"/>215 <Caret Line="149" Column="1" TopLine="133"/> 203 216 </Position24> 204 217 <Position25> 205 <Filename Value="U MainForm.pas"/>206 <Caret Line=" 49" Column="15" TopLine="35"/>218 <Filename Value="UProtocolBuffers.pas"/> 219 <Caret Line="81" Column="39" TopLine="65"/> 207 220 </Position25> 208 221 <Position26> 209 <Filename Value="U MainForm.pas"/>210 <Caret Line=" 51" Column="29" TopLine="35"/>222 <Filename Value="UProtocolBuffers.pas"/> 223 <Caret Line="134" Column="1" TopLine="118"/> 211 224 </Position26> 212 225 <Position27> 213 <Filename Value="U MainForm.pas"/>214 <Caret Line=" 56" Column="8" TopLine="40"/>226 <Filename Value="UProtocolBuffers.pas"/> 227 <Caret Line="135" Column="1" TopLine="119"/> 215 228 </Position27> 216 229 <Position28> 217 <Filename Value="UP arser.pas"/>218 <Caret Line="1 4" Column="3" TopLine="1"/>230 <Filename Value="UProtocolBuffers.pas"/> 231 <Caret Line="136" Column="6" TopLine="120"/> 219 232 </Position28> 220 233 <Position29> 221 <Filename Value="UP arser.pas"/>222 <Caret Line=" 34" Column="5" TopLine="2"/>234 <Filename Value="UProtocolBuffers.pas"/> 235 <Caret Line="82" Column="19" TopLine="78"/> 223 236 </Position29> 224 237 <Position30> 225 <Filename Value="U Parser.pas"/>226 <Caret Line=" 7" Column="60" TopLine="3"/>238 <Filename Value="UMainForm.pas"/> 239 <Caret Line="112" Column="39" TopLine="88"/> 227 240 </Position30> 228 241 </JumpHistory> … … 246 259 </CompilerOptions> 247 260 <Debugging> 261 <BreakPoints Count="1"> 262 <Item1> 263 <Source Value="UProtocolBuffers.pas"/> 264 <Line Value="135"/> 265 </Item1> 266 </BreakPoints> 248 267 <Exceptions Count="3"> 249 268 <Item1> -
ProtocolBuffers/UMainForm.lfm
r8 r9 1 1 object MainForm: TMainForm 2 Left = 2 813 Height = 3194 Top = 1 895 Width = 4482 Left = 254 3 Height = 446 4 Top = 150 5 Width = 597 6 6 Caption = 'Demo ProtocolBuffers' 7 ClientHeight = 3198 ClientWidth = 4487 ClientHeight = 446 8 ClientWidth = 597 9 9 OnCreate = FormCreate 10 10 OnDestroy = FormDestroy 11 11 LCLVersion = '0.9.29' 12 12 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] 17 18 TabOrder = 0 18 19 end … … 29 30 Left = 88 30 31 Height = 25 31 Top = 28 932 Top = 288 32 33 Width = 75 33 34 Caption = 'From file' … … 35 36 TabOrder = 2 36 37 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 37 54 end -
ProtocolBuffers/UMainForm.lrs
r8 r9 1 { Toto je automaticky generovaný zdrojový soubor lazarusu } 2 1 3 LazarusResources.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 11 18 ]); -
ProtocolBuffers/UMainForm.pas
r8 r9 7 7 uses 8 8 Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs, 9 StdCtrls, UProtocolBuffers, UMemoryStreamEx;9 StdCtrls, ComCtrls, UProtocolBuffers, UMemoryStreamEx; 10 10 11 11 const … … 18 18 Button2: TButton; 19 19 Memo1: TMemo; 20 TreeView1: TTreeView; 21 TreeView2: TTreeView; 20 22 procedure Button1Click(Sender: TObject); 21 23 procedure Button2Click(Sender: TObject); … … 24 26 private 25 27 procedure DisplayStream(Stream: TStream); 28 procedure DisplayTree(ProtocolBuffer: TProtocolBuffer; TreeView: TTreeView); 29 procedure MessageToNode(PBMessage: TPBMessageItem; Node: TTreeNode); 26 30 public 27 PB: TProtocolBuffer; 28 end; 31 end; 29 32 30 33 var … … 43 46 Stream: TMemoryStream; 44 47 StringList: TStringList; 48 PB: TProtocolBuffer; 45 49 begin 46 50 Stream := TMemoryStreamEx.Create; … … 61 65 Stream: TMemoryStreamEx; 62 66 NewItem: TPBItem; 67 PB: TProtocolBuffer; 63 68 begin 64 69 Stream := TMemoryStreamEx.Create; … … 68 73 Name := 'SampleMessage'; 69 74 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; 71 88 Items.Add(NewItem); 72 89 end; 90 DisplayTree(PB, TreeView1); 73 91 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; 75 118 end; 76 119 Stream.Free; … … 79 122 procedure TMainForm.FormDestroy(Sender: TObject); 80 123 begin 81 PB.Free;82 124 end; 83 125 … … 95 137 end; 96 138 139 procedure TMainForm.DisplayTree(ProtocolBuffer: TProtocolBuffer; 140 TreeView: TTreeView); 141 begin 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; 150 end; 151 152 procedure TMainForm.MessageToNode(PBMessage: TPBMessageItem; Node: TTreeNode); 153 var 154 I: Integer; 155 NewNode: TTreeNode; 156 begin 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; 176 end; 177 97 178 initialization 98 179 {$I UMainForm.lrs} -
ProtocolBuffers/UProtocolBuffers.pas
r8 r9 25 25 procedure SaveVariantToStream(Stream: TStream; Value: Integer); 26 26 function LoadVariantFromStream(Stream: TStream): Integer; 27 procedure SaveHeadToStream(Stream: TStream); 28 procedure LoadHeadFromStream(Stream: TStream); 27 29 procedure SaveToStream(Stream: TStream); virtual; 28 30 procedure LoadFromStream(Stream: TStream); virtual; … … 50 52 TPBMessageItem = class(TPBItem) 51 53 Items: TList; // TList<TPBItem>; 54 function SearchItemByTag(Tag: Integer): TPBItem; 52 55 procedure SaveToStream(Stream: TStream); override; 53 56 procedure LoadFromStream(Stream: TStream); override; … … 75 78 procedure TProtocolBuffer.LoadFromStream(Stream: TStream); 76 79 begin 80 BaseMessage.LoadHeadFromStream(Stream); 77 81 BaseMessage.LoadFromStream(Stream); 78 82 end; … … 101 105 { TPBMessageItem } 102 106 107 function TPBMessageItem.SearchItemByTag(Tag: Integer): TPBItem; 108 var 109 I: Integer; 110 begin 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; 115 end; 116 103 117 procedure TPBMessageItem.SaveToStream(Stream: TStream); 104 118 var 105 119 I: Integer; 106 120 begin 107 inherited SaveToStream(Stream); 121 inherited; 122 SaveHeadToStream(Stream); 108 123 for I := 0 to Items.Count - 1 do 109 124 TPBItem(Items[I]).SaveToStream(Stream); … … 113 128 var 114 129 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; 132 begin 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; 119 150 end; 120 151 … … 154 185 end; 155 186 156 procedure TPBItem.Save ToStream(Stream: TStream);187 procedure TPBItem.SaveHeadToStream(Stream: TStream); 157 188 var 158 189 ByteIndex: Byte; … … 171 202 end; 172 203 173 procedure TPBItem.Load FromStream(Stream: TStream);204 procedure TPBItem.LoadHeadFromStream(Stream: TStream); 174 205 var 175 206 Data: Byte; … … 187 218 end; 188 219 220 procedure TPBItem.SaveToStream(Stream: TStream); 221 begin 222 223 end; 224 225 procedure TPBItem.LoadFromStream(Stream: TStream); 226 begin 227 228 end; 229 189 230 function TPBItem.LoadVariantFromStream(Stream: TStream): Integer; 190 231 var … … 206 247 procedure TPBIntegerItem.SaveToStream(Stream: TStream); 207 248 begin 208 inherited SaveToStream(Stream); 249 inherited; 250 SaveHeadToStream(Stream); 209 251 SaveVariantToStream(Stream, Value); 210 252 end; … … 212 254 procedure TPBIntegerItem.LoadFromStream(Stream: TStream); 213 255 begin 214 inherited LoadFromStream(Stream);215 LoadVariantFromStream(Stream);256 inherited; 257 Value := LoadVariantFromStream(Stream); 216 258 end; 217 259 … … 225 267 procedure TPBStringItem.SaveToStream(Stream: TStream); 226 268 begin 227 inherited SaveToStream(Stream); 269 inherited; 270 SaveHeadToStream(Stream); 228 271 SaveVariantToStream(Stream, Length(Value)); 229 272 TMemoryStreamEx(Stream).Write(Value[1], Length(Value)); … … 232 275 procedure TPBStringItem.LoadFromStream(Stream: TStream); 233 276 begin 234 inherited LoadFromStream(Stream);277 inherited; 235 278 SetLength(Value, LoadVariantFromStream(Stream)); 236 279 TMemoryStreamEx(Stream).Read(Value[1], Length(Value));
Note:
See TracChangeset
for help on using the changeset viewer.