source: oup/current/Unit13_rawedit.pas@ 32

Last change on this file since 32 was 10, checked in by alloc, 18 years ago
  • Property svn:executable set to *
File size: 24.6 KB
RevLine 
[10]1UNIT Unit13_rawedit;
2INTERFACE
3USES
4 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
5 Dialogs, Wrapgrid, StdCtrls, Grids, StrUtils, MPHexEditor, ExtCtrls, Clipbrd,
6 Unit3_data, Unit2_functions, Unit9_data_structures, Unit4_exporters, Unit15_Classes,
7 Menus, Math;
8
9TYPE
10 TForm13 = Class(TForm)
11 Splitter1: TSplitter;
12 panel_data: TPanel;
13 hex: TMPHexEditor;
14 Splitter2: TSplitter;
15 value_viewer: TWrapGrid;
16 value_viewer_context: TPopupMenu;
17 value_viewer_context_copy: TMenuItem;
18 value_viewer_context_copyashex: TMenuItem;
19 value_viewer_context_copyasdec: TMenuItem;
20 value_viewer_context_copyasfloat: TMenuItem;
21 value_viewer_context_copyasbitset: TMenuItem;
22 value_viewer_context_copyasstring: TMenuItem;
23 panel_files: TPanel;
24 opend: TOpenDialog;
25 saved: TSaveDialog;
26 panel_imexport: TPanel;
27 btn_export: TButton;
28 btn_import: TButton;
29 group_file: TGroupBox;
30 list: TListBox;
31 panel_extension: TPanel;
32 lbl_filter: TLabel;
33 combo_extension: TComboBox;
34 edit_filtername: TEdit;
35 check_filtername: TCheckBox;
36 GroupBox1: TGroupBox;
37 list_offset: TListBox;
38 Splitter4: TSplitter;
39 procedure hexKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
40 PROCEDURE list_offsetClick(Sender: TObject);
41 PROCEDURE LoadRaw(raw_info:TRawInfo);
42 PROCEDURE LoadFileNames;
43 PROCEDURE check_filternameClick(Sender: TObject);
44 PROCEDURE combo_extensionClick(Sender: TObject);
45 PROCEDURE panel_extensionResize(Sender: TObject);
46 PROCEDURE listClick(Sender: TObject);
47 PROCEDURE Recreatelist;
48
49 PROCEDURE FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
50 PROCEDURE value_viewerDblClick(Sender: TObject);
51 PROCEDURE value_viewer_context_copyClick(Sender: TObject);
52 PROCEDURE value_viewerMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
53 PROCEDURE value_viewer_contextPopup(Sender: TObject);
54 PROCEDURE btn_importClick(Sender: TObject);
55 PROCEDURE btn_exportClick(Sender: TObject);
56 PROCEDURE panel_imexportResize(Sender: TObject);
57 FUNCTION Save:Boolean;
58 PROCEDURE FormClose(Sender: TObject; var Action: TCloseAction);
59 FUNCTION GetValue(datatype:Word; offset:LongWord):String;
60 PROCEDURE hexSelectionChanged(Sender: TObject);
61 PROCEDURE hexChange(Sender: TObject);
62 PROCEDURE panel_dataResize(Sender: TObject);
63 PROCEDURE FormResize(Sender: TObject);
64 PROCEDURE FormCloseQuery(Sender: TObject; var CanClose: Boolean);
65 PROCEDURE FormCreate(Sender: TObject);
66 PROCEDURE ClearValues;
67 PROCEDURE WriteValues;
68 PROCEDURE SetNewValue(datatype:Word; offset:LongWord; value:String);
69 PRIVATE
70 fileid:LongWord;
71 dat_offset:LongWord;
72 fileid_opened,dat_offset_opened:LongWord;
73 PUBLIC
74 END;
75
76VAR
77 Form13: TForm13;
78
79IMPLEMENTATION
80{$R *.dfm}
81USES Unit1_main, Unit12_ValueEdit;
82
83
84PROCEDURE TForm13.LoadRaw(raw_info:TRawInfo);
85 VAR
86 i:LongWord;
87 data:Tdata;
88 mem:TMemoryStream;
89 BEGIN
90 IF hex.Modified THEN BEGIN
91 IF NOT Save THEN BEGIN
92 Exit;
93 END;
94 END;
95 IF list_offset.Count=0 THEN BEGIN
96 FOR i:=0 TO list.Count-1 DO BEGIN
97 IF OniDataConnection.ExtractFileID(list.Items.Strings[i])=raw_info.src_id THEN BEGIN
98 list.ItemIndex:=i;
99 listClick(Self);
100 Break;
101 END;
102 END;
103 FOR i:=0 TO list_offset.Count-1 DO BEGIN
104 IF MidStr(list_offset.Items.Strings[i],3,8)=IntToHex(raw_info.src_offset,8) THEN BEGIN
105 list_offset.ItemIndex:=i;
106 Break;
107 END;
108 END;
109 END;
110 SetLength(data,raw_info.raw_size);
111 OniDataConnection.LoadRawFile(raw_info.src_id,raw_info.src_offset,@data[0]);
112 IF Length(data)>0 THEN BEGIN
113 hex.DataSize:=0;
114 hex.DataSize:=raw_info.raw_size;
115 FOR i:=0 TO High(data) DO
116 hex.Data[i]:=data[i];
117 //WriteStructureInfos(GetStructureInfoId(GetFileInfo(fileid).Extension));
118// structs.Height:=structs.RowCount*20;
119// IF structs.Height>120 THEN structs.Height:=120;
120 hexSelectionChanged(Self);
121 fileid_opened:=raw_info.src_id;
122 dat_offset_opened:=raw_info.src_offset;
123 hex.Modified:=False;
124 END ELSE BEGIN
125 ClearValues;
126 hex.DataSize:=0;
127 END;
128 END;
129
130PROCEDURE TForm13.Recreatelist;
131 VAR
132 i:LongWord;
133 exts:TStringArray;
134 count:LongWord;
135 BEGIN
136 combo_extension.Items.Clear;
137 combo_extension.Items.Add('_All files_ ('{+IntToStr(dat_header.Files)}+')');
138 exts:=OniDataConnection.GetExtensionsList;
139 FOR i:=0 TO High(RawListHandlers) DO BEGIN
140 count:=Length(OniDataConnection.GetFilesList(RawListHandlers[i].Ext,'',True));
141 combo_extension.Items.Add(RawListHandlers[i].ext+' ('+IntToStr(count)+')');
142 END;
143// FOR i:=0 TO High(exts) DO
144// combo_extension.Items.Add(exts[i]);
145 combo_extension.ItemIndex:=0;
146 combo_extensionClick(Self);
147 END;
148
149PROCEDURE TForm13.LoadFileNames;
150 VAR
151 Extension:String;
152 no_zero_bytes:Boolean;
153 pattern:String;
154 files:TStringArray;
155 i:LongWord;
156 BEGIN
157 Extension:=MidStr(combo_extension.Items.Strings[combo_extension.ItemIndex],1,4);
158 pattern:='';
159 IF check_filtername.Checked THEN pattern:=edit_filtername.Text;
160 IF Extension='_All' THEN BEGIN
161 Extension:='';
162 FOR i:=0 TO High(RawListHandlers) DO BEGIN
163 IF Length(Extension)>0 THEN Extension:=Extension+',';
164 Extension:=Extension+RawListHandlers[i].Ext;
165 END;
166 END;
167
168 files:=OniDataConnection.GetFilesList(extension,pattern,TRUE);
169 list.Items.Clear;
170 IF Length(files)>0 THEN
171 FOR i:=0 TO High(files) DO
172 list.Items.Add(files[i]);
173 list_offset.Items.Clear;
174 END;
175
176PROCEDURE TForm13.panel_extensionResize(Sender: TObject);
177 BEGIN
178 combo_extension.Width:=panel_extension.Width-5;
179 edit_filtername.Width:=panel_extension.Width-5;
180 END;
181
182PROCEDURE TForm13.combo_extensionClick(Sender: TObject);
183 BEGIN
184 LoadFileNames;
185 END;
186
187PROCEDURE TForm13.check_filternameClick(Sender: TObject);
188 BEGIN
189 edit_filtername.Enabled:=NOT check_filtername.Checked;
190 LoadFileNames;
191 END;
192
193PROCEDURE TForm13.listClick(Sender: TObject);
194 VAR
195 mem:TMemoryStream;
196 data:Tdata;
197 i:LongWord;
198 offsets:TRawList;
199 BEGIN
200 IF hex.Modified THEN BEGIN
201 IF NOT Save THEN BEGIN
202 Exit;
203 END;
204 END;
205 ClearValues;
206 hex.DataSize:=0;
207 fileid:=OniDataConnection.ExtractFileID(list.Items.Strings[list.ItemIndex]);
208 list_offset.Enabled:=True;
209 IF OniDataConnection.GetFileInfo(fileid).size>0 THEN BEGIN
210 offsets:=OniDataConnection.GetRawList(fileid);
211 list_offset.Items.Clear;
212 IF Length(offsets)>0 THEN BEGIN
213 FOR i:=0 TO High(offsets) DO BEGIN
214 list_offset.Items.Add('0x'+IntToHex(offsets[i].src_offset,8)+', '+IntToStr(offsets[i].raw_size)+' bytes');
215 END;
216 END ELSE BEGIN
217 list_offset.Enabled:=False;
218 END;
219 END ELSE BEGIN
220 list_offset.Enabled:=False;
221 END;
222 END;
223
224PROCEDURE TForm13.list_offsetClick(Sender: TObject);
225 VAR
226 i:LongWord;
227 raw_info:TRawInfo;
228 BEGIN
229 ClearValues;
230 dat_offset:=StrToInt('$'+MidStr(list_offset.Items.Strings[list_offset.ItemIndex],3,8));
231 LoadRaw(OniDataConnection.GetRawInfo(fileid,dat_offset));
232 END;
233
234
235
236
237FUNCTION IntToBin(value:Byte):String;
238 VAR i:Byte;
239 BEGIN
240 Result:='';
241 FOR i:=7 DOWNTO 0 DO BEGIN
242 Result:=Result+IntToStr((value SHR i) AND $01);
243 END;
244 END;
245
246FUNCTION TForm13.GetValue(datatype:Word; offset:LongWord):String;
247 VAR
248 data:Tdata;
249 i:Word;
250 BEGIN
251 CASE datatype OF
252 1: Result:=IntToStr(hex.data[offset]);
253 2: Result:=IntToStr(hex.data[offset]+hex.data[offset+1]*256);
254 3: Result:=IntToStr(hex.data[offset]+hex.data[offset+1]*256+hex.data[offset+2]*256*256);
255 4: Result:=IntToStr(hex.data[offset]+hex.data[offset+1]*256+hex.data[offset+2]*256*256+hex.data[offset+3]*256*256*256);
256 5: Result:='0x'+IntToHex(hex.data[offset],2);
257 6: Result:='0x'+IntToHex(hex.data[offset]+hex.data[offset+1]*256,4);
258 7: Result:='0x'+IntToHex(hex.data[offset]+hex.data[offset+1]*256+hex.data[offset+2]*256*256,6);
259 8: Result:='0x'+IntToHex(hex.data[offset]+hex.data[offset+1]*256+hex.data[offset+2]*256*256+hex.data[offset+3]*256*256*256,8);
260 9: BEGIN
261 SetLength(data,4);
262 data[0]:=hex.data[offset];
263 data[1]:=hex.data[offset+1];
264 data[2]:=hex.data[offset+2];
265 data[3]:=hex.data[offset+3];
266 Result:=FloatToStr(Decode_Float(data));
267 END;
268 10: Result:=IntToBin(hex.data[offset]);
269 11: Result:='0x'+IntToHex(hex.data[offset]+hex.data[offset+1]*256+hex.data[offset+2]*256*256+hex.data[offset+3]*256*256*256,8);
270 10000..65535: BEGIN
271 Result:='';
272 FOR i:=1 TO datatype-10000 DO BEGIN
273 IF hex.Data[offset+i-1]>=32 THEN
274 Result:=Result+Chr(hex.Data[offset+i-1])
275 ELSE
276 Result:=Result+'.';
277 END;
278 END;
279 END;
280 END;
281
282PROCEDURE TForm13.ClearValues;
283 VAR
284 i:Byte;
285 BEGIN
286 FOR i:=1 TO value_viewer.RowCount-1 DO BEGIN
287 value_viewer.Cells[1,i]:='';
288 END;
289 END;
290
291PROCEDURE TForm13.WriteValues;
292 VAR
293 i,j:Byte;
294 data:Tdata;
295 str:String;
296 value:LongWord;
297 BEGIN
298 FOR i:=1 TO value_viewer.RowCount-1 DO BEGIN
299 IF value_viewer.Cells[0,i]='1 byte, unsigned' THEN BEGIN
300 IF ((hex.SelCount=1) OR (hex.SelCount=0)) AND NOT ((hex.SelStart+1)>hex.DataSize) THEN BEGIN
301 value:=hex.Data[hex.SelStart];
302 value_viewer.Cells[1,i]:=IntToStr( value )+' / 0x'+IntToHex( value , 2 );
303 END ELSE
304 value_viewer.Cells[1,i]:='';
305 END;
306 IF value_viewer.Cells[0,i]='2 bytes, unsigned' THEN BEGIN
307 IF ((hex.SelCount=2) OR (hex.SelCount=0)) AND NOT ((hex.SelStart+2)>hex.DataSize) THEN BEGIN
308 value:=hex.Data[hex.SelStart] + hex.Data[hex.SelStart+1]*256;
309 value_viewer.Cells[1,i]:=IntToStr( value )+' / 0x'+IntToHex( value , 4 );
310 END ELSE
311 value_viewer.Cells[1,i]:='';
312 END;
313 IF value_viewer.Cells[0,i]='4 bytes, unsigned' THEN BEGIN
314 IF ((hex.SelCount=4) OR (hex.SelCount=0)) AND NOT ((hex.SelStart+4)>hex.DataSize) THEN BEGIN
315 value:=hex.Data[hex.SelStart]+hex.Data[hex.SelStart+1]*256+hex.Data[hex.SelStart+2]*256*256+hex.Data[hex.SelStart+3]*256*256*256;
316 value_viewer.Cells[1,i]:=IntToStr( value )+' / 0x'+IntToHex( value , 8 );
317 END ELSE
318 value_viewer.Cells[1,i]:='';
319 END;
320 IF value_viewer.Cells[0,i]='Bitset' THEN BEGIN
321 IF (hex.SelCount<=8) THEN BEGIN
322 IF hex.SelCount=0 THEN BEGIN
323 SetLength(data,1);
324 data[0]:=hex.Data[hex.SelStart];
325 END ELSE BEGIN
326 SetLength(data,hex.SelCount);
327 FOR j:=0 TO hex.SelCount-1 DO
328 data[j]:=hex.Data[hex.SelStart+j];
329 END;
330 value_viewer.Cells[1,i]:=DataToBin(data);
331 END ELSE
332 value_viewer.Cells[1,i]:='';
333 END;
334 IF value_viewer.Cells[0,i]='Float' THEN BEGIN
335 IF ((hex.SelCount=4) OR (hex.SelCount=0)) AND NOT ((hex.SelStart+4)>hex.DataSize) THEN BEGIN
336 SetLength(data,4);
337 FOR j:=0 TO 3 DO
338 data[j]:=hex.Data[hex.SelStart+j];
339 value_viewer.Cells[1,i]:=FloatToStr(Decode_Float(data));
340 END ELSE
341 value_viewer.Cells[1,i]:='';
342 END;
343 IF value_viewer.Cells[0,i]='Selected length' THEN BEGIN
344 value_viewer.Cells[1,i]:=IntToStr(hex.SelCount)+' bytes';
345 END;
346 IF value_viewer.Cells[0,i]='String' THEN BEGIN
347 j:=0;
348 str:='';
349 IF hex.SelCount=0 THEN BEGIN
350 WHILE (hex.Data[hex.SelStart+j]>0) AND ((hex.SelStart+j)<hex.DataSize) DO BEGIN
351 IF hex.Data[hex.selstart+j]>=32 THEN
352 str:=str+Char(hex.Data[hex.SelStart+j])
353 ELSE
354 str:=str+'.';
355 Inc(j);
356 END;
357 END ELSE BEGIN
358 FOR j:=0 TO hex.SelCount-1 DO
359 IF hex.Data[hex.selstart+j]>=32 THEN
360 str:=str+Char(hex.Data[hex.SelStart+j])
361 ELSE
362 IF hex.Data[hex.selstart+j]>0 THEN
363 str:=str+'.'
364 ELSE
365 Break;
366 END;
367 value_viewer.Cells[1,i]:=str;
368 END;
369 END;
370 END;
371
372PROCEDURE TForm13.FormCreate(Sender: TObject);
373 BEGIN
374 Self.Caption:='';
375 fileid:=0;
376 value_viewer.ColCount:=2;
377 value_viewer.RowCount:=8;
378 value_viewer.FixedRows:=1;
379 value_viewer.Cells[0,0]:='Type';
380 value_viewer.Cells[1,0]:='Value';
381 value_viewer.Cells[0,1]:='1 byte, unsigned';
382 value_viewer.Cells[0,2]:='2 bytes, unsigned';
383 value_viewer.Cells[0,3]:='4 bytes, unsigned';
384 value_viewer.Cells[0,4]:='Bitset';
385 value_viewer.Cells[0,5]:='Float';
386 value_viewer.Cells[0,6]:='String';
387 value_viewer.Cells[0,7]:='Selected length';
388 value_viewer.ColWidths[0]:=100;
389 hex.Height:=panel_data.Height-190;
390 Self.panel_dataResize(Self);
391//
392 value_viewer.Font.Charset:=AppSettings.CharSet;
393//
394 END;
395
396FUNCTION TForm13.Save:Boolean;
397 VAR
398 mem:TMemoryStream;
399 data:Tdata;
400 i:LongWord;
401 BEGIN
402 CASE MessageBox(Self.Handle,PChar('Save changes to .raw-part of file '+OniDataConnection.GetFileInfo(fileid).FileName+'?'),PChar('Data changed...'),MB_YESNOCANCEL) OF
403 IDYES: BEGIN
404 mem:=TMemoryStream.Create;
405 hex.SaveToStream(mem);
406 mem.Seek(0,soFromBeginning);
407 SetLength(data,mem.Size);
408 mem.Read(data[0],mem.Size);
409 mem.Free;
410 OniDataConnection.UpdateRawFile(fileid_opened,dat_offset_opened,Length(data),@data[0]);
411 hex.Modified:=False;
412 FOR i:=0 TO hex.Datasize-1 DO hex.ByteChanged[i]:=False;
413 Result:=True;
414 END;
415 IDNO: Result:=True;
416 IDCANCEL: BEGIN
417 Result:=False;
418 END;
419 END;
420 END;
421
422PROCEDURE TForm13.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
423 BEGIN
424 IF hex.Modified THEN BEGIN
425 IF NOT Save THEN CanClose:=False;
426 END;
427 END;
428
429PROCEDURE TForm13.FormResize(Sender: TObject);
430 BEGIN
431 IF Self.Width>=650 THEN BEGIN
432 END ELSE Self.Width:=650;
433 IF Self.Height>=450 THEN BEGIN
434 END ELSE Self.Height:=450;
435 END;
436
437PROCEDURE TForm13.panel_dataResize(Sender: TObject);
438 BEGIN
439 value_viewer.ColWidths[1]:=value_viewer.Width-value_viewer.ColWidths[0]-28;
440 END;
441
442PROCEDURE TForm13.hexChange(Sender: TObject);
443 BEGIN
444 ClearValues;
445 IF hex.DataSize>0 THEN BEGIN
446{ WriteStructureInfos(GetStructureInfoId(GetFileInfo(fileid).Extension));
447 WriteValues;
448} END;
449 END;
450
451PROCEDURE TForm13.hexKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
452 VAR
453 temps: String;
454 BEGIN
455 IF (Shift=[ssCtrl]) AND (Key=Ord('C')) THEN BEGIN
456 IF hex.SelCount>0 THEN BEGIN
457 IF hex.InCharField THEN
458 Clipboard.AsText:=hex.SelectionAsText
459 ELSE
460 Clipboard.AsText:=hex.SelectionAsHex;
461 END;
462 END;
463 IF (Shift=[ssCtrl]) AND (Key=Ord('V')) THEN BEGIN
464{ temps:=Clipboard.AsText;
465 IF hex.SelStart+Length(temps)>hex.DataSize THEN
466 SetLength(temps, hex.DataSize-hex.SelStart);
467 hex.Sel
468 hex.SelCount:=Length(temps);
469 hex.ReplaceSelection(temps,Length(temps));
470} END;
471 END;
472
473PROCEDURE TForm13.hexSelectionChanged(Sender: TObject);
474 VAR
475 selstart:Integer;
476 i,j:Word;
477 BEGIN
478{ FOR i:=1 TO structs.RowCount-1 DO BEGIN
479 FOR j:=0 TO structs.ColCount-1 DO BEGIN
480 structs.CellColors[j,i]:=clWhite;
481 structs.CellFontColors[j,i]:=clBlack;
482 END;
483 END;
484} IF hex.DataSize>0 THEN BEGIN
485{ selstart:=hex.SelStart;
486 IF GetStructureInfoId(GetFileInfo(fileid).Extension)>=0 THEN BEGIN
487 WITH structure_infos[GetStructureInfoId(GetFileInfo(fileid).Extension)] DO BEGIN
488 FOR i:=0 TO High(entries) DO BEGIN
489 IF ((selstart-entries[i].offset)<GetTypeDataLength(entries[i].datatype)) AND ((selstart-entries[i].offset)>=0) THEN BEGIN
490 FOR j:=0 TO structs.ColCount-1 DO BEGIN
491 structs.CellColors[j,i+1]:=clBlue;
492 structs.CellFontColors[j,i+1]:=clWhite;
493 END;
494 structs.Row:=i+1;
495 END;
496 END;
497 END;
498 END;
499} WriteValues;
500 END;
501 END;
502
503PROCEDURE TForm13.FormClose(Sender: TObject; var Action: TCloseAction);
504 BEGIN
505 Action:=caFree;
506 END;
507
508PROCEDURE TForm13.panel_imexportResize(Sender: TObject);
509 BEGIN
510 btn_import.Width:=panel_imexport.Width-8;
511 btn_export.Width:=panel_imexport.Width-8;
512 END;
513
514PROCEDURE TForm13.btn_exportClick(Sender: TObject);
515 VAR
516 fs:TFileStream;
517 BEGIN
518 saved.Filter:='Files of matching extension (*.'+OniDataConnection.GetFileInfo(fileid).Extension+')|*.'+OniDataConnection.GetFileInfo(fileid).Extension+'|All files|*.*';
519 saved.DefaultExt:=OniDataConnection.GetFileInfo(fileid).Extension;
520 IF saved.Execute THEN BEGIN
521 fs:=TFileStream.Create(saved.FileName,fmCreate);
522 hex.SaveToStream(fs);
523 fs.Free;
524 END;
525 END;
526
527PROCEDURE TForm13.btn_importClick(Sender: TObject);
528 VAR
529 data:Tdata;
530 fs:TFileStream;
531 BEGIN
532 opend.Filter:='Files of matching extension (*.'+OniDataConnection.GetFileInfo(fileid).Extension+')|*.'+OniDataConnection.GetFileInfo(fileid).Extension+'|All files|*.*';
533 IF opend.Execute THEN BEGIN
534 fs:=TFileStream.Create(opend.FileName,fmOpenRead);
535 IF fs.Size<>hex.DataSize THEN BEGIN
536 ShowMessage('Can''t import '+ExtractFilename(opend.FileName)+
537 ', file has to have same size as file in .dat.'+CrLf+
538 'Size of file in .dat: '+FormatFileSize(hex.datasize)+CrLf+
539 'Size of chosen file: '+FormatFileSize(fs.Size));
540 END ELSE BEGIN
541 hex.LoadFromStream(fs);
542 hex.Modified:=True;
543 END;
544 fs.Free;
545 END;
546 END;
547
548PROCEDURE TForm13.value_viewer_contextPopup(Sender: TObject);
549 VAR
550 i:Byte;
551 BEGIN
552 FOR i:=0 TO value_viewer_context.Items.Count-1 DO
553 value_viewer_context.Items.Items[i].Visible:=False;
554 WITH value_viewer DO BEGIN
555 IF (Col=1) AND (Row>0) AND (Length(Cells[Col,Row])>0) THEN BEGIN
556 IF Pos(' byte',Cells[0,Row])=2 THEN BEGIN
557 value_viewer_context.Items.Find('Copy to &clipboard').Visible:=True;
558 value_viewer_context.Items.Find('Copy to clipboard (as &dec)').Visible:=True;
559 value_viewer_context.Items.Find('Copy to clipboard (as &hex)').Visible:=True;
560 END;
561 IF Pos('Float',Cells[0,Row])=1 THEN
562 value_viewer_context.Items.Find('Copy to clipboard (as &float)').Visible:=True;
563 IF Pos('Bitset',Cells[0,Row])=1 THEN
564 value_viewer_context.Items.Find('Copy to clipboard (as &bitset)').Visible:=True;
565 IF Pos('String',Cells[0,Row])=1 THEN
566 value_viewer_context.Items.Find('Copy to clipboard (as &string)').Visible:=True;
567 IF Pos('Selected length',Cells[0,Row])=1 THEN
568 value_viewer_context.Items.Find('Copy to &clipboard').Visible:=True;
569 END;
570 END;
571 END;
572
573PROCEDURE TForm13.value_viewerMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
574 VAR
575 ACol,ARow:Integer;
576 BEGIN
577 IF Button=mbRight THEN BEGIN
578 value_viewer.MouseToCell(x,y,ACol,ARow);
579 IF ARow>0 THEN BEGIN
580 value_viewer.Col:=ACol;
581 value_viewer.Row:=ARow;
582 END;
583 END;
584 END;
585
586PROCEDURE TForm13.value_viewer_context_copyClick(Sender: TObject);
587 VAR
588 i:Byte;
589 name:String;
590 value:LongWord;
591 BEGIN
592 name:=TMenuItem(Sender).Name;
593 IF Pos('asstring',name)>0 THEN BEGIN
594 Clipboard.AsText:=value_viewer.Cells[value_viewer.Col,value_viewer.Row];
595 END ELSE
596 IF Pos('asfloat',name)>0 THEN BEGIN
597 Clipboard.AsText:=value_viewer.Cells[value_viewer.Col,value_viewer.Row];
598 END ELSE
599 IF Pos('asbitset',name)>0 THEN BEGIN
600 Clipboard.AsText:=value_viewer.Cells[value_viewer.Col,value_viewer.Row];
601 END ELSE
602 IF (Pos('ashex',name)>0) OR (Pos('asdec',name)>0) THEN BEGIN
603 IF value_viewer.Cells[0,value_viewer.Row]='1 byte, unsigned' THEN BEGIN
604 IF ((hex.SelCount=1) OR (hex.SelCount=0)) AND NOT ((hex.SelStart+1)>hex.DataSize) THEN
605 value:=hex.Data[hex.SelStart];
606 END;
607 IF value_viewer.Cells[0,value_viewer.Row]='2 bytes, unsigned' THEN BEGIN
608 IF ((hex.SelCount=2) OR (hex.SelCount=0)) AND NOT ((hex.SelStart+2)>hex.DataSize) THEN
609 value:=hex.Data[hex.SelStart] + hex.Data[hex.SelStart+1]*256;
610 END;
611 IF value_viewer.Cells[0,value_viewer.Row]='4 bytes, unsigned' THEN BEGIN
612 IF ((hex.SelCount=4) OR (hex.SelCount=0)) AND NOT ((hex.SelStart+4)>hex.DataSize) THEN
613 value:=hex.Data[hex.SelStart]+hex.Data[hex.SelStart+1]*256+hex.Data[hex.SelStart+2]*256*256+hex.Data[hex.SelStart+3]*256*256*256;
614 END;
615 IF Pos('asdec',name)>0 THEN BEGIN
616 Clipboard.AsText:=IntToStr(value);
617 END ELSE BEGIN
618 IF value_viewer.Cells[0,value_viewer.Row]='1 byte, unsigned' THEN
619 Clipboard.AsText:='0x'+IntToHex(value,2);
620 IF value_viewer.Cells[0,value_viewer.Row]='2 bytes, unsigned' THEN
621 Clipboard.AsText:='0x'+IntToHex(value,4);
622 IF value_viewer.Cells[0,value_viewer.Row]='4 bytes, unsigned' THEN
623 Clipboard.AsText:='0x'+IntToHex(value,8);
624 END;
625 END ELSE BEGIN
626 Clipboard.AsText:=value_viewer.Cells[value_viewer.Col,value_viewer.Row];
627 END;
628 END;
629
630PROCEDURE TForm13.SetNewValue(datatype:Word; offset:LongWord; value:String);
631 VAR
632 data:Tdata;
633 value_int:LongWord;
634 value_float:Single;
635 i:Word;
636 BEGIN
637 CASE datatype OF
638 1..4: BEGIN
639 value_int:=StrToInt(value);
640 SetLength(data,datatype);
641 FOR i:=0 TO datatype-1 DO BEGIN
642 data[i]:=value_int MOD 256;
643 value_int:=value_int DIV 256;
644 END;
645 END;
646 5..8: BEGIN
647 value_int:=StrToInt('$'+value);
648 SetLength(data,datatype-4);
649 FOR i:=0 TO datatype-5 DO BEGIN
650 data[i]:=value_int MOD 256;
651 value_int:=value_int DIV 256;
652 END;
653 END;
654 9: BEGIN
655 value_float:=StrToFloat(value);
656 data:=Encode_Float(value_float);
657 END;
658 10: BEGIN
659 value_int:=BinToInt(value);
660 SetLength(data,1);
661 data[0]:=value_int;
662 END;
663 10000..65535: BEGIN
664 SetLength(data,datatype-10000);
665 FOR i:=1 TO datatype-10000 DO BEGIN
666 IF i<=Length(value) THEN
667 data[i-1]:=Ord(value[i])
668 ELSE
669 data[i-1]:=0;
670 END;
671 END;
672 END;
673 FOR i:=0 TO High(data) DO BEGIN
674 IF hex.Data[offset+i]<>data[i] THEN hex.ByteChanged[offset+i]:=True;
675 hex.Data[offset+i]:=data[i];
676 END;
677 hex.Modified:=True;
678 hexChange(Self);
679 hex.Repaint;
680 END;
681
682PROCEDURE TForm13.value_viewerDblClick(Sender: TObject);
683 VAR
684 offset:LongWord;
685 datatype:Word;
686 objectname:String;
687 value:String;
688 BEGIN
689 IF (value_viewer.Col=1) AND (Length(value_viewer.Cells[1,value_viewer.Row])>0) THEN BEGIN
690 offset:=hex.SelStart;
691 IF value_viewer.Cells[0,value_viewer.Row]='1 byte, unsigned' THEN
692 datatype:=1;
693 IF value_viewer.Cells[0,value_viewer.Row]='2 bytes, unsigned' THEN
694 datatype:=2;
695 IF value_viewer.Cells[0,value_viewer.Row]='4 bytes, unsigned' THEN
696 datatype:=4;
697 IF value_viewer.Cells[0,value_viewer.Row]='Bitset' THEN
698 datatype:=10;
699 IF value_viewer.Cells[0,value_viewer.Row]='Float' THEN
700 datatype:=9;
701 IF value_viewer.Cells[0,value_viewer.Row]='Selected length' THEN
702 Exit;
703 IF value_viewer.Cells[0,value_viewer.Row]='String' THEN BEGIN
704 IF hex.SelCount>0 THEN
705 datatype:=10000+hex.SelCount
706 ELSE
707 datatype:=10000+Length(value_viewer.Cells[1,value_viewer.Row]);
708 END;
709 objectname:='';
710 value:=GetValue(datatype,offset);
711 Form12.MakeVarInput(objectname,offset,datatype,value,Self);
712 END;
713 END;
714
715PROCEDURE TForm13.FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
716 BEGIN
717 IF (Shift=[ssCtrl]) AND (Key=83) THEN
718 IF hex.Modified THEN
719 IF NOT Save THEN
720 Exit;
721 END;
722
723END.
Note: See TracBrowser for help on using the repository browser.