source: oup/releases/0.32a/Unit13_rawedit.pas@ 390

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