UNIT Unit13_rawedit; INTERFACE USES Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Wrapgrid, StdCtrls, Grids, StrUtils, MPHexEditor, ExtCtrls, Clipbrd, Unit3_data, Unit2_functions, Unit9_data_structures, Unit4_exporters, Unit15_Classes, Menus, Math; TYPE TForm13 = Class(TForm) Splitter1: TSplitter; panel_data: TPanel; hex: TMPHexEditor; Splitter2: TSplitter; value_viewer: TWrapGrid; value_viewer_context: TPopupMenu; value_viewer_context_copy: TMenuItem; value_viewer_context_copyashex: TMenuItem; value_viewer_context_copyasdec: TMenuItem; value_viewer_context_copyasfloat: TMenuItem; value_viewer_context_copyasbitset: TMenuItem; value_viewer_context_copyasstring: TMenuItem; panel_files: TPanel; opend: TOpenDialog; saved: TSaveDialog; panel_imexport: TPanel; btn_export: TButton; btn_import: TButton; group_file: TGroupBox; list: TListBox; panel_extension: TPanel; lbl_filter: TLabel; combo_extension: TComboBox; edit_filtername: TEdit; check_filtername: TCheckBox; GroupBox1: TGroupBox; list_offset: TListBox; Splitter4: TSplitter; procedure hexKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState); PROCEDURE list_offsetClick(Sender: TObject); PROCEDURE LoadRaw(raw_info:TRawInfo); PROCEDURE LoadFileNames; PROCEDURE check_filternameClick(Sender: TObject); PROCEDURE combo_extensionClick(Sender: TObject); PROCEDURE panel_extensionResize(Sender: TObject); PROCEDURE listClick(Sender: TObject); PROCEDURE Recreatelist; PROCEDURE FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState); PROCEDURE value_viewerDblClick(Sender: TObject); PROCEDURE value_viewer_context_copyClick(Sender: TObject); PROCEDURE value_viewerMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); PROCEDURE value_viewer_contextPopup(Sender: TObject); PROCEDURE btn_importClick(Sender: TObject); PROCEDURE btn_exportClick(Sender: TObject); PROCEDURE panel_imexportResize(Sender: TObject); FUNCTION Save:Boolean; PROCEDURE FormClose(Sender: TObject; var Action: TCloseAction); FUNCTION GetValue(datatype:Word; offset:LongWord):String; PROCEDURE hexSelectionChanged(Sender: TObject); PROCEDURE hexChange(Sender: TObject); PROCEDURE panel_dataResize(Sender: TObject); PROCEDURE FormResize(Sender: TObject); PROCEDURE FormCloseQuery(Sender: TObject; var CanClose: Boolean); PROCEDURE FormCreate(Sender: TObject); PROCEDURE ClearValues; PROCEDURE WriteValues; PROCEDURE SetNewValue(datatype:Word; offset:LongWord; value:String); PRIVATE fileid:LongWord; dat_offset:LongWord; fileid_opened,dat_offset_opened:LongWord; PUBLIC END; VAR Form13: TForm13; IMPLEMENTATION {$R *.dfm} USES Unit1_main, Unit12_ValueEdit; PROCEDURE TForm13.LoadRaw(raw_info:TRawInfo); VAR i:LongWord; data:Tdata; mem:TMemoryStream; BEGIN IF hex.Modified THEN BEGIN IF NOT Save THEN BEGIN Exit; END; END; IF list_offset.Count=0 THEN BEGIN FOR i:=0 TO list.Count-1 DO BEGIN IF OniDataConnection.ExtractFileID(list.Items.Strings[i])=raw_info.src_id THEN BEGIN list.ItemIndex:=i; listClick(Self); Break; END; END; FOR i:=0 TO list_offset.Count-1 DO BEGIN IF MidStr(list_offset.Items.Strings[i],3,8)=IntToHex(raw_info.src_offset,8) THEN BEGIN list_offset.ItemIndex:=i; Break; END; END; END; SetLength(data,raw_info.raw_size); OniDataConnection.LoadRawFile(raw_info.src_id,raw_info.src_offset,@data[0]); IF Length(data)>0 THEN BEGIN hex.DataSize:=0; hex.DataSize:=raw_info.raw_size; FOR i:=0 TO High(data) DO hex.Data[i]:=data[i]; //WriteStructureInfos(GetStructureInfoId(GetFileInfo(fileid).Extension)); // structs.Height:=structs.RowCount*20; // IF structs.Height>120 THEN structs.Height:=120; hexSelectionChanged(Self); fileid_opened:=raw_info.src_id; dat_offset_opened:=raw_info.src_offset; hex.Modified:=False; END ELSE BEGIN ClearValues; hex.DataSize:=0; END; END; PROCEDURE TForm13.Recreatelist; VAR i:LongWord; exts:TStringArray; count:LongWord; BEGIN combo_extension.Items.Clear; combo_extension.Items.Add('_All files_ ('{+IntToStr(dat_header.Files)}+')'); exts:=OniDataConnection.GetExtensionsList; FOR i:=0 TO High(RawListHandlers) DO BEGIN count:=Length(OniDataConnection.GetFilesList(RawListHandlers[i].Ext,'',True)); combo_extension.Items.Add(RawListHandlers[i].ext+' ('+IntToStr(count)+')'); END; // FOR i:=0 TO High(exts) DO // combo_extension.Items.Add(exts[i]); combo_extension.ItemIndex:=0; combo_extensionClick(Self); END; PROCEDURE TForm13.LoadFileNames; VAR Extension:String; no_zero_bytes:Boolean; pattern:String; files:TStringArray; i:LongWord; BEGIN Extension:=MidStr(combo_extension.Items.Strings[combo_extension.ItemIndex],1,4); pattern:=''; IF check_filtername.Checked THEN pattern:=edit_filtername.Text; IF Extension='_All' THEN BEGIN Extension:=''; FOR i:=0 TO High(RawListHandlers) DO BEGIN IF Length(Extension)>0 THEN Extension:=Extension+','; Extension:=Extension+RawListHandlers[i].Ext; END; END; files:=OniDataConnection.GetFilesList(extension,pattern,TRUE); list.Items.Clear; IF Length(files)>0 THEN FOR i:=0 TO High(files) DO list.Items.Add(files[i]); list_offset.Items.Clear; END; PROCEDURE TForm13.panel_extensionResize(Sender: TObject); BEGIN combo_extension.Width:=panel_extension.Width-5; edit_filtername.Width:=panel_extension.Width-5; END; PROCEDURE TForm13.combo_extensionClick(Sender: TObject); BEGIN LoadFileNames; END; PROCEDURE TForm13.check_filternameClick(Sender: TObject); BEGIN edit_filtername.Enabled:=NOT check_filtername.Checked; LoadFileNames; END; PROCEDURE TForm13.listClick(Sender: TObject); VAR mem:TMemoryStream; data:Tdata; i:LongWord; offsets:TRawList; BEGIN IF hex.Modified THEN BEGIN IF NOT Save THEN BEGIN Exit; END; END; ClearValues; hex.DataSize:=0; fileid:=OniDataConnection.ExtractFileID(list.Items.Strings[list.ItemIndex]); list_offset.Enabled:=True; IF OniDataConnection.GetFileInfo(fileid).size>0 THEN BEGIN offsets:=OniDataConnection.GetRawList(fileid); list_offset.Items.Clear; IF Length(offsets)>0 THEN BEGIN FOR i:=0 TO High(offsets) DO BEGIN list_offset.Items.Add('0x'+IntToHex(offsets[i].src_offset,8)+', '+IntToStr(offsets[i].raw_size)+' bytes'); END; END ELSE BEGIN list_offset.Enabled:=False; END; END ELSE BEGIN list_offset.Enabled:=False; END; END; PROCEDURE TForm13.list_offsetClick(Sender: TObject); VAR i:LongWord; raw_info:TRawInfo; BEGIN ClearValues; dat_offset:=StrToInt('$'+MidStr(list_offset.Items.Strings[list_offset.ItemIndex],3,8)); LoadRaw(OniDataConnection.GetRawInfo(fileid,dat_offset)); END; FUNCTION IntToBin(value:Byte):String; VAR i:Byte; BEGIN Result:=''; FOR i:=7 DOWNTO 0 DO BEGIN Result:=Result+IntToStr((value SHR i) AND $01); END; END; FUNCTION TForm13.GetValue(datatype:Word; offset:LongWord):String; VAR data:Tdata; i:Word; BEGIN CASE datatype OF 1: Result:=IntToStr(hex.data[offset]); 2: Result:=IntToStr(hex.data[offset]+hex.data[offset+1]*256); 3: Result:=IntToStr(hex.data[offset]+hex.data[offset+1]*256+hex.data[offset+2]*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); 5: Result:='0x'+IntToHex(hex.data[offset],2); 6: Result:='0x'+IntToHex(hex.data[offset]+hex.data[offset+1]*256,4); 7: Result:='0x'+IntToHex(hex.data[offset]+hex.data[offset+1]*256+hex.data[offset+2]*256*256,6); 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); 9: BEGIN SetLength(data,4); data[0]:=hex.data[offset]; data[1]:=hex.data[offset+1]; data[2]:=hex.data[offset+2]; data[3]:=hex.data[offset+3]; Result:=FloatToStr(Decode_Float(data)); END; 10: Result:=IntToBin(hex.data[offset]); 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); 10000..65535: BEGIN Result:=''; FOR i:=1 TO datatype-10000 DO BEGIN IF hex.Data[offset+i-1]>=32 THEN Result:=Result+Chr(hex.Data[offset+i-1]) ELSE Result:=Result+'.'; END; END; END; END; PROCEDURE TForm13.ClearValues; VAR i:Byte; BEGIN FOR i:=1 TO value_viewer.RowCount-1 DO BEGIN value_viewer.Cells[1,i]:=''; END; END; PROCEDURE TForm13.WriteValues; VAR i,j:Byte; data:Tdata; str:String; value:LongWord; BEGIN FOR i:=1 TO value_viewer.RowCount-1 DO BEGIN IF value_viewer.Cells[0,i]='1 byte, unsigned' THEN BEGIN IF ((hex.SelCount=1) OR (hex.SelCount=0)) AND NOT ((hex.SelStart+1)>hex.DataSize) THEN BEGIN value:=hex.Data[hex.SelStart]; value_viewer.Cells[1,i]:=IntToStr( value )+' / 0x'+IntToHex( value , 2 ); END ELSE value_viewer.Cells[1,i]:=''; END; IF value_viewer.Cells[0,i]='2 bytes, unsigned' THEN BEGIN IF ((hex.SelCount=2) OR (hex.SelCount=0)) AND NOT ((hex.SelStart+2)>hex.DataSize) THEN BEGIN value:=hex.Data[hex.SelStart] + hex.Data[hex.SelStart+1]*256; value_viewer.Cells[1,i]:=IntToStr( value )+' / 0x'+IntToHex( value , 4 ); END ELSE value_viewer.Cells[1,i]:=''; END; IF value_viewer.Cells[0,i]='4 bytes, unsigned' THEN BEGIN IF ((hex.SelCount=4) OR (hex.SelCount=0)) AND NOT ((hex.SelStart+4)>hex.DataSize) THEN BEGIN 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; value_viewer.Cells[1,i]:=IntToStr( value )+' / 0x'+IntToHex( value , 8 ); END ELSE value_viewer.Cells[1,i]:=''; END; IF value_viewer.Cells[0,i]='Bitset' THEN BEGIN IF (hex.SelCount<=8) THEN BEGIN IF hex.SelCount=0 THEN BEGIN SetLength(data,1); data[0]:=hex.Data[hex.SelStart]; END ELSE BEGIN SetLength(data,hex.SelCount); FOR j:=0 TO hex.SelCount-1 DO data[j]:=hex.Data[hex.SelStart+j]; END; value_viewer.Cells[1,i]:=DataToBin(data); END ELSE value_viewer.Cells[1,i]:=''; END; IF value_viewer.Cells[0,i]='Float' THEN BEGIN IF ((hex.SelCount=4) OR (hex.SelCount=0)) AND NOT ((hex.SelStart+4)>hex.DataSize) THEN BEGIN SetLength(data,4); FOR j:=0 TO 3 DO data[j]:=hex.Data[hex.SelStart+j]; value_viewer.Cells[1,i]:=FloatToStr(Decode_Float(data)); END ELSE value_viewer.Cells[1,i]:=''; END; IF value_viewer.Cells[0,i]='Selected length' THEN BEGIN value_viewer.Cells[1,i]:=IntToStr(hex.SelCount)+' bytes'; END; IF value_viewer.Cells[0,i]='String' THEN BEGIN j:=0; str:=''; IF hex.SelCount=0 THEN BEGIN WHILE (hex.Data[hex.SelStart+j]>0) AND ((hex.SelStart+j)=32 THEN str:=str+Char(hex.Data[hex.SelStart+j]) ELSE str:=str+'.'; Inc(j); END; END ELSE BEGIN FOR j:=0 TO hex.SelCount-1 DO IF hex.Data[hex.selstart+j]>=32 THEN str:=str+Char(hex.Data[hex.SelStart+j]) ELSE IF hex.Data[hex.selstart+j]>0 THEN str:=str+'.' ELSE Break; END; value_viewer.Cells[1,i]:=str; END; END; END; PROCEDURE TForm13.FormCreate(Sender: TObject); BEGIN Self.Caption:=''; fileid:=0; value_viewer.ColCount:=2; value_viewer.RowCount:=8; value_viewer.FixedRows:=1; value_viewer.Cells[0,0]:='Type'; value_viewer.Cells[1,0]:='Value'; value_viewer.Cells[0,1]:='1 byte, unsigned'; value_viewer.Cells[0,2]:='2 bytes, unsigned'; value_viewer.Cells[0,3]:='4 bytes, unsigned'; value_viewer.Cells[0,4]:='Bitset'; value_viewer.Cells[0,5]:='Float'; value_viewer.Cells[0,6]:='String'; value_viewer.Cells[0,7]:='Selected length'; value_viewer.ColWidths[0]:=100; hex.Height:=panel_data.Height-190; Self.panel_dataResize(Self); // value_viewer.Font.Charset:=AppSettings.CharSet; // END; FUNCTION TForm13.Save:Boolean; VAR mem:TMemoryStream; data:Tdata; i:LongWord; BEGIN CASE MessageBox(Self.Handle,PChar('Save changes to .raw-part of file '+OniDataConnection.GetFileInfo(fileid).FileName+'?'),PChar('Data changed...'),MB_YESNOCANCEL) OF IDYES: BEGIN mem:=TMemoryStream.Create; hex.SaveToStream(mem); mem.Seek(0,soFromBeginning); SetLength(data,mem.Size); mem.Read(data[0],mem.Size); mem.Free; OniDataConnection.UpdateRawFile(fileid_opened,dat_offset_opened,Length(data),@data[0]); hex.Modified:=False; FOR i:=0 TO hex.Datasize-1 DO hex.ByteChanged[i]:=False; Result:=True; END; IDNO: Result:=True; IDCANCEL: BEGIN Result:=False; END; END; END; PROCEDURE TForm13.FormCloseQuery(Sender: TObject; var CanClose: Boolean); BEGIN IF hex.Modified THEN BEGIN IF NOT Save THEN CanClose:=False; END; END; PROCEDURE TForm13.FormResize(Sender: TObject); BEGIN IF Self.Width>=650 THEN BEGIN END ELSE Self.Width:=650; IF Self.Height>=450 THEN BEGIN END ELSE Self.Height:=450; END; PROCEDURE TForm13.panel_dataResize(Sender: TObject); BEGIN value_viewer.ColWidths[1]:=value_viewer.Width-value_viewer.ColWidths[0]-28; END; PROCEDURE TForm13.hexChange(Sender: TObject); BEGIN ClearValues; IF hex.DataSize>0 THEN BEGIN { WriteStructureInfos(GetStructureInfoId(GetFileInfo(fileid).Extension)); WriteValues; } END; END; PROCEDURE TForm13.hexKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState); VAR temps: String; BEGIN IF (Shift=[ssCtrl]) AND (Key=Ord('C')) THEN BEGIN IF hex.SelCount>0 THEN BEGIN IF hex.InCharField THEN Clipboard.AsText:=hex.SelectionAsText ELSE Clipboard.AsText:=hex.SelectionAsHex; END; END; IF (Shift=[ssCtrl]) AND (Key=Ord('V')) THEN BEGIN { temps:=Clipboard.AsText; IF hex.SelStart+Length(temps)>hex.DataSize THEN SetLength(temps, hex.DataSize-hex.SelStart); hex.Sel hex.SelCount:=Length(temps); hex.ReplaceSelection(temps,Length(temps)); } END; END; PROCEDURE TForm13.hexSelectionChanged(Sender: TObject); VAR selstart:Integer; i,j:Word; BEGIN { FOR i:=1 TO structs.RowCount-1 DO BEGIN FOR j:=0 TO structs.ColCount-1 DO BEGIN structs.CellColors[j,i]:=clWhite; structs.CellFontColors[j,i]:=clBlack; END; END; } IF hex.DataSize>0 THEN BEGIN { selstart:=hex.SelStart; IF GetStructureInfoId(GetFileInfo(fileid).Extension)>=0 THEN BEGIN WITH structure_infos[GetStructureInfoId(GetFileInfo(fileid).Extension)] DO BEGIN FOR i:=0 TO High(entries) DO BEGIN IF ((selstart-entries[i].offset)=0) THEN BEGIN FOR j:=0 TO structs.ColCount-1 DO BEGIN structs.CellColors[j,i+1]:=clBlue; structs.CellFontColors[j,i+1]:=clWhite; END; structs.Row:=i+1; END; END; END; END; } WriteValues; END; END; PROCEDURE TForm13.FormClose(Sender: TObject; var Action: TCloseAction); BEGIN Action:=caFree; END; PROCEDURE TForm13.panel_imexportResize(Sender: TObject); BEGIN btn_import.Width:=panel_imexport.Width-8; btn_export.Width:=panel_imexport.Width-8; END; PROCEDURE TForm13.btn_exportClick(Sender: TObject); VAR fs:TFileStream; BEGIN saved.Filter:='Files of matching extension (*.'+OniDataConnection.GetFileInfo(fileid).Extension+')|*.'+OniDataConnection.GetFileInfo(fileid).Extension+'|All files|*.*'; saved.DefaultExt:=OniDataConnection.GetFileInfo(fileid).Extension; IF saved.Execute THEN BEGIN fs:=TFileStream.Create(saved.FileName,fmCreate); hex.SaveToStream(fs); fs.Free; END; END; PROCEDURE TForm13.btn_importClick(Sender: TObject); VAR data:Tdata; fs:TFileStream; BEGIN opend.Filter:='Files of matching extension (*.'+OniDataConnection.GetFileInfo(fileid).Extension+')|*.'+OniDataConnection.GetFileInfo(fileid).Extension+'|All files|*.*'; IF opend.Execute THEN BEGIN fs:=TFileStream.Create(opend.FileName,fmOpenRead); IF fs.Size<>hex.DataSize THEN BEGIN ShowMessage('Can''t import '+ExtractFilename(opend.FileName)+ ', file has to have same size as file in .dat.'+CrLf+ 'Size of file in .dat: '+FormatFileSize(hex.datasize)+CrLf+ 'Size of chosen file: '+FormatFileSize(fs.Size)); END ELSE BEGIN hex.LoadFromStream(fs); hex.Modified:=True; END; fs.Free; END; END; PROCEDURE TForm13.value_viewer_contextPopup(Sender: TObject); VAR i:Byte; BEGIN FOR i:=0 TO value_viewer_context.Items.Count-1 DO value_viewer_context.Items.Items[i].Visible:=False; WITH value_viewer DO BEGIN IF (Col=1) AND (Row>0) AND (Length(Cells[Col,Row])>0) THEN BEGIN IF Pos(' byte',Cells[0,Row])=2 THEN BEGIN value_viewer_context.Items.Find('Copy to &clipboard').Visible:=True; value_viewer_context.Items.Find('Copy to clipboard (as &dec)').Visible:=True; value_viewer_context.Items.Find('Copy to clipboard (as &hex)').Visible:=True; END; IF Pos('Float',Cells[0,Row])=1 THEN value_viewer_context.Items.Find('Copy to clipboard (as &float)').Visible:=True; IF Pos('Bitset',Cells[0,Row])=1 THEN value_viewer_context.Items.Find('Copy to clipboard (as &bitset)').Visible:=True; IF Pos('String',Cells[0,Row])=1 THEN value_viewer_context.Items.Find('Copy to clipboard (as &string)').Visible:=True; IF Pos('Selected length',Cells[0,Row])=1 THEN value_viewer_context.Items.Find('Copy to &clipboard').Visible:=True; END; END; END; PROCEDURE TForm13.value_viewerMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); VAR ACol,ARow:Integer; BEGIN IF Button=mbRight THEN BEGIN value_viewer.MouseToCell(x,y,ACol,ARow); IF ARow>0 THEN BEGIN value_viewer.Col:=ACol; value_viewer.Row:=ARow; END; END; END; PROCEDURE TForm13.value_viewer_context_copyClick(Sender: TObject); VAR i:Byte; name:String; value:LongWord; BEGIN name:=TMenuItem(Sender).Name; IF Pos('asstring',name)>0 THEN BEGIN Clipboard.AsText:=value_viewer.Cells[value_viewer.Col,value_viewer.Row]; END ELSE IF Pos('asfloat',name)>0 THEN BEGIN Clipboard.AsText:=value_viewer.Cells[value_viewer.Col,value_viewer.Row]; END ELSE IF Pos('asbitset',name)>0 THEN BEGIN Clipboard.AsText:=value_viewer.Cells[value_viewer.Col,value_viewer.Row]; END ELSE IF (Pos('ashex',name)>0) OR (Pos('asdec',name)>0) THEN BEGIN IF value_viewer.Cells[0,value_viewer.Row]='1 byte, unsigned' THEN BEGIN IF ((hex.SelCount=1) OR (hex.SelCount=0)) AND NOT ((hex.SelStart+1)>hex.DataSize) THEN value:=hex.Data[hex.SelStart]; END; IF value_viewer.Cells[0,value_viewer.Row]='2 bytes, unsigned' THEN BEGIN IF ((hex.SelCount=2) OR (hex.SelCount=0)) AND NOT ((hex.SelStart+2)>hex.DataSize) THEN value:=hex.Data[hex.SelStart] + hex.Data[hex.SelStart+1]*256; END; IF value_viewer.Cells[0,value_viewer.Row]='4 bytes, unsigned' THEN BEGIN IF ((hex.SelCount=4) OR (hex.SelCount=0)) AND NOT ((hex.SelStart+4)>hex.DataSize) THEN 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; END; IF Pos('asdec',name)>0 THEN BEGIN Clipboard.AsText:=IntToStr(value); END ELSE BEGIN IF value_viewer.Cells[0,value_viewer.Row]='1 byte, unsigned' THEN Clipboard.AsText:='0x'+IntToHex(value,2); IF value_viewer.Cells[0,value_viewer.Row]='2 bytes, unsigned' THEN Clipboard.AsText:='0x'+IntToHex(value,4); IF value_viewer.Cells[0,value_viewer.Row]='4 bytes, unsigned' THEN Clipboard.AsText:='0x'+IntToHex(value,8); END; END ELSE BEGIN Clipboard.AsText:=value_viewer.Cells[value_viewer.Col,value_viewer.Row]; END; END; PROCEDURE TForm13.SetNewValue(datatype:Word; offset:LongWord; value:String); VAR data:Tdata; value_int:LongWord; value_float:Single; i:Word; BEGIN CASE datatype OF 1..4: BEGIN value_int:=StrToInt(value); SetLength(data,datatype); FOR i:=0 TO datatype-1 DO BEGIN data[i]:=value_int MOD 256; value_int:=value_int DIV 256; END; END; 5..8: BEGIN value_int:=StrToInt('$'+value); SetLength(data,datatype-4); FOR i:=0 TO datatype-5 DO BEGIN data[i]:=value_int MOD 256; value_int:=value_int DIV 256; END; END; 9: BEGIN value_float:=StrToFloat(value); data:=Encode_Float(value_float); END; 10: BEGIN value_int:=BinToInt(value); SetLength(data,1); data[0]:=value_int; END; 10000..65535: BEGIN SetLength(data,datatype-10000); FOR i:=1 TO datatype-10000 DO BEGIN IF i<=Length(value) THEN data[i-1]:=Ord(value[i]) ELSE data[i-1]:=0; END; END; END; FOR i:=0 TO High(data) DO BEGIN IF hex.Data[offset+i]<>data[i] THEN hex.ByteChanged[offset+i]:=True; hex.Data[offset+i]:=data[i]; END; hex.Modified:=True; hexChange(Self); hex.Repaint; END; PROCEDURE TForm13.value_viewerDblClick(Sender: TObject); VAR offset:LongWord; datatype:Word; objectname:String; value:String; BEGIN IF (value_viewer.Col=1) AND (Length(value_viewer.Cells[1,value_viewer.Row])>0) THEN BEGIN offset:=hex.SelStart; IF value_viewer.Cells[0,value_viewer.Row]='1 byte, unsigned' THEN datatype:=1; IF value_viewer.Cells[0,value_viewer.Row]='2 bytes, unsigned' THEN datatype:=2; IF value_viewer.Cells[0,value_viewer.Row]='4 bytes, unsigned' THEN datatype:=4; IF value_viewer.Cells[0,value_viewer.Row]='Bitset' THEN datatype:=10; IF value_viewer.Cells[0,value_viewer.Row]='Float' THEN datatype:=9; IF value_viewer.Cells[0,value_viewer.Row]='Selected length' THEN Exit; IF value_viewer.Cells[0,value_viewer.Row]='String' THEN BEGIN IF hex.SelCount>0 THEN datatype:=10000+hex.SelCount ELSE datatype:=10000+Length(value_viewer.Cells[1,value_viewer.Row]); END; objectname:=''; value:=GetValue(datatype,offset); Form12.MakeVarInput(objectname,offset,datatype,value,Self); END; END; PROCEDURE TForm13.FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState); BEGIN IF (Shift=[ssCtrl]) AND (Key=83) THEN IF hex.Modified THEN IF NOT Save THEN Exit; END; END.