📄 hexchfrm.pas
字号:
if FTopRow + FVisRow - 1 > FRowCount - 1 then
FTopRow := FRowCount - FVisRow;
FCurRow := FTopRow;
end;
Offset2 := GetOffset;
if ShiftPressed then AdjustBlockB(Offset1, Offset2);
VertScrollBar.Position := FTopRow;
DrawAllRow;
ShowStatusInfo;
FillDataInspValue;
end;
procedure THexChForm.DoHomeKey(ShiftPressed: Boolean);
var
Offset1, Offset2: Integer;
begin
if (FCurCol = 0) and (FCurInHigh) then Exit;
Offset1 := GetOffset;
FCurCol := 0;
FCurInHigh := True;
Offset2 := GetOffset;
if ShiftPressed then AdjustBlockA(Offset1, Offset2);
DrawAllRow;
ShowStatusInfo;
FillDataInspValue;
end;
procedure THexChForm.DoEndKey(ShiftPressed: Boolean);
var
Offset1, Offset2, CurDLen: Integer;
begin
CurDLen := GetDLen;
if (CurDlen mod 32 = 0) or (CurDLen = FBufSize * 2) then Exit;
Offset1 := GetOffset;
if FCurRow = FRowCount - 1 then FCurCol := (FBufSize-1) mod 16
else FCurCol := 15;
FCurInHigh := False;
Offset2 := GetOffset;
if ShiftPressed then AdjustBlockB(Offset1, Offset2);
DrawAllRow;
ShowStatusInfo;
FillDataInspValue;
end;
procedure THexChForm.DoTabKey;
begin
FCurInHex := not FCurInHex;
DrawCurItem(True);
DrawCursor(False);
end;
procedure THexChForm.DoCtrlJKey;
begin
Options.ShowDot := not Options.ShowDot;
DrawAllRow;
end;
procedure THexChForm.DoCtrlKKey(Key: Word);
begin
if (Key >= Ord('0')) and (Key <= Ord('9')) then DoCtrlKNumKey(Key)
else if (Key = Ord('B')) or (Key = Ord('b')) then DoCtrlKBKey(Key)
else if (Key = Ord('K')) or (Key = Ord('k')) then DoCtrlKKKey(Key)
else if (Key = Ord('H')) or (Key = Ord('h')) then DoCtrlKHKey(Key)
else if (Key = Ord('W')) or (Key = Ord('w')) then DoCtrlKWKey(Key);
end;
procedure THexChForm.DoCtrlQKey(Key: Word);
begin
if (Key >= Ord('0')) and (Key <= Ord('9')) then DoCtrlQNumKey(Key)
else if (Key = Ord('F')) or (Key = Ord('f')) then DoCtrlQFKey(Key)
else if (Key = Ord('A')) or (Key = Ord('a')) then DoCtrlQAKey(Key);
end;
procedure THexChForm.DoCtrlKNumKey(Key: Word);
var
Idx: Integer;
begin
Idx := Key - Ord('0');
if Idx >= BookmarkCount then Exit;
FBookmark[Idx].Active := True;
FBookmark[Idx].DLen := GetDLen;
FBookmark[Idx].CurInHex := FCurInHex;
end;
procedure THexChForm.DoCtrlKBKey(Key: Word);
begin
FBlock.StartOffset := GetOffset;
if FBlock.StartOffset > FBlock.EndOffset then
FBlock.Active := False
else
FBlock.Active := True;
DrawAllRow;
ShowStatusInfo;
FillDataInspValue;
end;
procedure THexChForm.DoCtrlKKKey(Key: Word);
begin
FBlock.EndOffset := GetOffset;
if FBlock.StartOffset > FBlock.EndOffset then
FBlock.Active := False
else
FBlock.Active := True;
DrawAllRow;
ShowStatusInfo;
FillDataInspValue;
end;
procedure THexChForm.DoCtrlKHKey(Key: Word);
begin
SetBlockVisible(not FBlock.Active);
end;
procedure THexChForm.DoCtrlKWKey(Key: Word);
begin
WriteBlockActExecute(nil);
end;
procedure THexChForm.DoCtrlQNumKey(Key: Word);
var
Idx: Integer;
begin
Idx := Key - Ord('0');
if Idx >= BookmarkCount then Exit;
if not FBookmark[Idx].Active then Exit;
FCurInHex := FBookmark[Idx].CurInHex;
MoveCurTo(FBookmark[Idx].DLen);
end;
procedure THexChForm.DoCtrlQFKey(Key: Word);
begin
SearchTextItemClick(nil);
end;
procedure THexChForm.DoCtrlQAKey(Key: Word);
begin
SearchReplaceTextItemClick(nil);
end;
procedure THexChForm.DoCtrlUpKey;
begin
if FTopRow = 0 then Exit;
Dec(FTopRow);
if FCurRow < FTopRow then FCurRow := FTopRow;
if FCurRow > FTopRow + FVisRow - 1 then
FCurRow := FTopRow + FVisRow -1;
VertScrollBar.Position := FTopRow;
DrawAllRow;
ShowStatusInfo;
FillDataInspValue;
end;
procedure THexChForm.DoCtrlDownKey;
begin
if FTopRow = FRowCount - FVisRow then Exit;
Inc(FTopRow);
if FCurRow < FTopRow then FCurRow := FTopRow;
if FCurRow > FTopRow + FVisRow - 1 then
FCurRow := FTopRow + FVisRow -1;
VertScrollBar.Position := FTopRow;
DrawAllRow;
ShowStatusInfo;
FillDataInspValue;
end;
procedure THexChForm.DoCtrlLeftKey;
begin
MoveCur(-2);
end;
procedure THexChForm.DoCtrlRightKey;
begin
MoveCur(2);
end;
procedure THexChForm.DoCtrlPageUpKey(ShiftPressed: Boolean);
var
Offset1, Offset2: Integer;
begin
Offset1 := GetOffset;
if Offset1 = 0 then Exit;
MoveCurTo(1);
Offset2 := GetOffset;
if ShiftPressed then AdjustBlockA(Offset1, Offset2);
DrawAllRow;
end;
procedure THexChForm.DoCtrlPageDownKey(ShiftPressed: Boolean);
var
Offset1, Offset2: Integer;
begin
Offset1 := GetOffset;
if Offset1 = FBufSize - 1 then Exit;
MoveCurTo(FBufSize * 2 - 1);
Offset2 := GetOffset;
if ShiftPressed then AdjustBlockB(Offset1, Offset2);
DrawAllRow;
end;
procedure THexChForm.DoCharKey(Key: Char);
begin
if FCurInHex then
DoCharKeyForHexArea(Key)
else
DoCharKeyForChrArea(Key);
end;
procedure THexChForm.DoCharKeyForHexArea(Key: Char);
var
P: PByte;
B: Byte;
Offset: Integer;
begin
if not IsHexChar(Key) then Exit;
Offset := GetOffset;
CreateUndoForModify(Offset, 1, 1);
P := PByte(GetRowColPointer(FCurRow, FCurCol));
if IsAlphaChar(Key) then
B := Ord(UpperCase(Key)[1]) - Ord('A') + 10
else
B := Ord(Key) - Ord('0');
if FCurInHigh then
begin
P^ := P^ and $0F;
P^ := P^ or (B shl 4);
end else
begin
P^ := P^ and $F0;
P^ := P^ or B;
end;
DrawItem(FCurRow - FTopRow, FCurCol, GetCharAttrByRowCol(FCurRow, FCurCol, True), GetCharAttrByRowCol(FCurRow, FCurCol, True));
FModified := True;
DoRightKey(False);
ShowStatusInfo;
FillDataInspValue;
CreateRedoForModify(Offset, 1, 1);
end;
procedure THexChForm.DoCharKeyForChrArea(Key: Char);
var
P: PChar;
Offset: Integer;
begin
if Ord(Key) < 32 then Exit;
Offset := GetOffset;
CreateUndoForModify(Offset, 1, 1);
P := GetRowColPointer(FCurRow, FCurCol);
P^ := Key;
DrawItem(FCurRow - FTopRow, FCurCol, GetCharAttrByRowCol(FCurRow, FCurCol, True), GetCharAttrByRowCol(FCurRow, FCurCol, True));
FModified := True;
DoRightKey(False);
ShowStatusInfo;
FillDataInspValue;
CreateRedoForModify(Offset, 1, 1);
end;
procedure THexChForm.CMDialogKey(var Message: TCMDialogKey);
begin
with Message do
case CharCode of
VK_TAB:
DoTabKey;
end
end;
procedure THexChForm.SetBuf(BufPointer: PChar; BufSize: Integer);
begin
FBufPointer := BufPointer;
FBufSize := BufSize;
FRowCount := GetRowCount(FBufSize);
FCurRow := 0;
FCurCol := 0;
FTopRow := 0;
FCurInHex := True;
FCurInHigh := True;
if FRowCount > FVisRow then
begin
VertScrollBar.Max := FRowCount - FVisRow;
VertScrollBar.Enabled := True;
end else
begin
VertScrollBar.Max := 0;
VertScrollBar.Enabled := False;
end;
VertScrollBar.Position := FTopRow;
end;
procedure THexChForm.SetBestSize;
begin
Width := GetFormMaxWidth;
end;
procedure THexChForm.FlashCursor;
const
ShowCur: Boolean = True;
begin
if not FFormShowed then Exit;
ShowCur := not ShowCur;
DrawCursor(ShowCur);
end;
procedure THexChForm.ReDraw;
begin
Self.Font := Options.HexEditFont;
//if Width > GetFormMaxWidth then
// Width := GetFormMaxWidth;
FormResize(nil);
DrawAllRow;
end;
procedure THexChForm.FillDataInspValue;
var
ValuePtr: Pointer;
MaxByte: Integer;
begin
if not DataInspForm.Visible then Exit;
ValuePtr := GetRowColPointer(FCurRow, FCurCol);
MaxByte := FBufSize - GetOffset;
DataInspForm.SetData(ValuePtr, MaxByte);
end;
procedure THexChForm.ChangeMaxUndo(Value: Integer);
begin
if FActsMgr.MaxUndo <> Value then
begin
FActsMgr.MaxUndo := Value;
AdjustUndoRedoEnabled;
end;
end;
procedure THexChForm.ReplaceRange(Offset, Count: Integer; S: string);
begin
CreateUndoForModify(Offset, Count, Length(S));
ModifyRange(Offset, Count, S);
MoveCurTo(Offset*2+1);
CreateRedoForModify(Offset, Count, Length(S));
end;
procedure THexChForm.DoSearch;
begin
SearchTextItemClick(nil);
end;
procedure THexChForm.DoCut;
var
S: string;
Len, BakPos: Integer;
begin
if FBlock.StartOffset > FBlock.EndOffset then Exit;
Len := FBlock.EndOffset - FBlock.StartOffset + 1;
BakPos := FBlock.StartOffset;
if Len = FBufSize then
begin
MessageBox(Handle, '不能删除整个缓冲区。', '提示', 48);
Exit;
end;
CreateUndoForDelete(BakPos, Len);
SetLength(S, Len*2);
ConvertBinToHex(FBufPointer + FBlock.StartOffset, @S[1], Len);
Clipboard.AsText := S;
SetLength(S, 0);
DeleteBlock;
MoveCurTo(BakPos * 2 - 1);
DrawAllRow;
CreateRedoForDelete(BakPos, Len);
end;
procedure THexChForm.DoCopy;
var
S: string;
Len: Integer;
begin
if FBlock.StartOffset > FBlock.EndOffset then Exit;
Len := FBlock.EndOffset - FBlock.StartOffset + 1;
SetLength(S, Len*2);
ConvertBinToHex(FBufPointer + FBlock.StartOffset, @S[1], Len);
Clipboard.AsText := S;
SetLength(S, 0);
end;
procedure THexChForm.DoPaste;
var
S: string;
Offset, Len: Integer;
begin
S := Clipboard.AsText;
ConvertHexToBin(@S[1], @S[1], Length(S), Len);
SetLength(S, Len);
Offset := GetOffset;
CreateUndoForInsert(Offset, Len);
InsertRange(GetOffset, S);
CreateRedoForInsert(Offset, Len);
end;
function THexChForm.NewBuf(BufSize: Integer): Boolean;
begin
try
FBuf.SetSize(BufSize);
ZeroMemory(FBuf.Memory, BufSize);
SetBuf(FBuf.Memory, FBuf.Size);
ShowStatusInfo;
FillDataInspValue;
Result := True;
except
FBuf.Clear;
SetBuf(FBuf.Memory, FBuf.Size);
MessageBox(Handle, '内存溢出错误!', '错误', 16);
Result := False;
end;
end;
function THexChForm.LoadFromFile(FileName: string): Boolean;
begin
Result := True;
try
FBuf.LoadFromFile(FileName);
if FBuf.Size = 0 then
begin
FBuf.SetSize(1);
ZeroMemory(FBuf.Memory, 1);
end;
except
Result := False;
FBuf.Clear;
end;
SetBuf(FBuf.Memory, FBuf.Size);
FFileName := FileName;
ShowStatusInfo;
FillDataInspValue;
end;
function THexChForm.SaveToFile(FileName: string): Boolean;
var
FileVar: file of Byte;
begin
if Options.CreateBak then
begin
CreateBakFile(FileName, 'bak');
end;
AssignFile(FileVar, FileName);
try
Rewrite(FileVar);
BlockWrite(FileVar, FBufPointer^, FBufSize);
CloseFile(FileVar);
Result := True;
except
Result := False;
end;
end;
function THexChForm.InsertChar(Offset: Integer; Chr: Char; Count: Integer): Boolean;
var
CurPtr: PChar;
begin
FBuf.SetSize(FBuf.Size + Count);
CurPtr := PChar(FBuf.Memory) + Offset;
Move(CurPtr^, (CurPtr + Count)^, FBufSize - Offset);
FillChar(CurPtr^, Count, Chr);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -