source: oup/current/Tools/RawEdit.pas@ 51

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