?? archiveeditunit.pas
字號:
Single_value:begin
val(InputValue,SingleTemp,Ecode);
if Ecode<>0 then Exit else
begin
ScanValue:=InputValue;
Result:=Single_value;
end;
end;
Double_value:begin
val(InputValue,DoubleTemp,Ecode);
if Ecode<>0 then Exit else
begin
ScanValue:=InputValue;
Result:=Double_value;
end;
end;
String_value:begin
ScanValue:=InputValue;
Result:=String_value;
end;
end; //case end;
end; ///not auto_value End;
end;///Extrac_scan end
end;///with end;
end;
///////////////////////////////////////////////////////////////////////////////////////////
///////////查找到的 地址數據加入列表
Procedure TArchiveEditForm.AddFoundToListView(theIndex:integer);
var FileSize:Dword;
BufSize:Int64;
AddressBuf:Dword;
i,j:Integer;
TempByte:Byte;
TempWord:Word;
TempDword:Dword;
Tempint64:int64;
TempSingle:Single;
TempDouble:Double;
TempStringBYTE:BYTE;
TempStringCount:byte;
Tempstring:string;
tempFileStream:TmemoryStream;
begin
Found_LV.Items.BeginUpdate;///防止閃爍
Found_LV.Items.Clear;
with theFiletask[theIndex] do
begin
FileSize:=checkAndGetFileSize(FilePathName);
if FileSize=0 then exit;
tempFileStream:=TmemoryStream.Create;
try
tempFileStream.LoadFromFile(FilePathName);
AddressmemStream.Seek(0,soFrombeginning); ////低階搜索BufSize=0;
BufSize:= AddressMemStream.Size;
if (BufSize>0) and ( not theFiletask[theIndex].InSearchProcess) then
begin
BufSize:=BufSize shr 2;
if BufSize>200 then BufSize:=200; ///只顯示前面200個值
For i:=1 to BufSize do
begin
try
AddressMemStream.ReadBuffer(AddressBuf,Sizeof(AddressBuf));
if (AddressBuf+1)<=FileSize then
begin
tempFileStream.Seek(AddressBuf,soFrombeginning);
tempFileStream.ReadBuffer(TempByte,1);
end;
if (AddressBuf+2)<=FileSize then
begin
tempFileStream.Seek(AddressBuf,soFrombeginning);
tempFileStream.ReadBuffer(TempWord,2);
end;
if (AddressBuf+4)<=FileSize then
begin
tempFileStream.Seek(AddressBuf,soFrombeginning);
tempFileStream.ReadBuffer(TempDWord,4);
end;
if (AddressBuf+8)<=FileSize then
begin
tempFileStream.Seek(AddressBuf,soFrombeginning);
tempFileStream.ReadBuffer(TempInt64,8);
end;
if (AddressBuf+4)<=FileSize then
begin
tempFileStream.Seek(AddressBuf,soFrombeginning);
tempFileStream.ReadBuffer(TempSingle,4);
end;
if (AddressBuf+8)<=FileSize then
begin
tempFileStream.Seek(AddressBuf,soFrombeginning);
tempFileStream.ReadBuffer(TempDouble,8);
end;
tempStringCount:=(FileSize-AddressBuf);
if tempStringCount>16 then tempStringCount:=16;
tempFileStream.Seek(AddressBuf,soFrombeginning);
Tempstring:='';
for j:=1 to tempStringCount do
begin
tempFileStream.ReadBuffer(TempStringBYTE,1);
Tempstring:=Tempstring+chr(TempstringBYTE);
end;
with Found_LV.Items.Add do
begin
Caption:=intTohex(AddressBuf,8);
SubItems.Add(intToStr(TempByte));
SubItems.Add(intToStr(TempWord));
SubItems.Add(intToStr(TempDword));
SubItems.Add(intToStr(TempInt64));
SubItems.Add(FloatToStr(TempSingle));
SubItems.Add(FloatToStr(TempDouble));
SubItems.Add(TempString);
end;
except
Continue;
end;
end;//for end
end; //if end
finally
FreeandNIl(tempFileStream);
end;
end;///with end
Found_lv.Items.EndUpdate;
end;
Procedure TArchiveEditForm.RaiseInputError;
begin
with theFileTask[CurrentFiletaskIndex] do
begin
inc(ErrorInputNum);
Value_Edit.SetFocus;
if ErrorInputNum>3 then
begin
Messagebeep(0);
ErrorInputNum:=0;
InputHelp_sb.click;
end;
end;
end;
procedure TArchiveEditForm.AddFIle_TBClick(Sender: TObject);
begin
AddFiletaskForm.Show;
end;
procedure TArchiveEditForm.delFile_tbClick(Sender: TObject);
var i,SelListIndex,theIndex:integer;
begin
if Filetasknum=0 then Exit;
if FIleTasks_LV.Selected<>nil then
begin
SelListIndex:=FIleTasks_LV.Selected.Index+1;
theIndex:=ListToFileTaskIndex[SelListIndex];
if theFileTask[theindex].InSearchProcess then
begin
MessageBox(Application.Handle,pchar(String_FileInScan),pchar(String_FileInScanTitle),
MB_OK or MB_ICONINFORMATION);
exit;
end;
theFileTask[theindex].Applyed:=False;
theFileTask[theIndex].AddressMemStream.Clear;
Dec(FiletaskNUm);
for i:=SelListIndex to FiletaskNum do
begin
ListToFileTaskIndex[i]:=ListToFileTaskIndex[i+1];
end;
FileTasks_lv.selected.Delete;
DeleteFile(theFileTask[theIndex].SaveFileName);
UpdateTaskInfo(theFileTask[theIndex].Index);
end;
end;
procedure TArchiveEditForm.Filetasks_LVEdited(Sender: TObject;
Item: TListItem; var S: String);
begin
theFileTask[CurrentFiletaskIndex].Name:=S;
UpdateTaskInfo(CurrentFiletaskIndex);
end;
procedure TArchiveEditForm.Filetasks_LVClick(Sender: TObject);
var selListIndex:Integer;
begin
if Filetasks_LV.Selected=nil then exit;
selListIndex:=Filetasks_LV.Selected.Index+1;
CurrentFiletaskIndex:=ListToFiletaskIndex[selListIndex];
Scan_Gauge.MaxValue:=theFileTask[CurrentFiletaskIndex].TotalProcess;
Value_Edit.Text:=theFileTask[CurrentFiletaskIndex].ScanValue;
if theFileTask[CurrentFileTaskIndex].ScanType=String_Scan then
Value_Edit.Text:=''''+theFileTask[CurrentFiletaskIndex].ScanValue+'''';
UpdateTaskInfo(CurrentFiletaskIndex);
VarType_cb.ItemIndex:=0;
AddFoundToListView(CurrentFiletaskIndex);
File_name:=theFileTask[CurrentFiletaskIndex].FilepathName;
EditFileName:=File_name;
FileRecordForm.FormRefresh;
end;
//////必須考慮前面的搜索類型
function TArchiveEditForm.AnalyseScan(theIndex:Integer):integer;
var TempLength:Dword;
TempSize:Dword;
begin
result:=-999;
with theFileTask[theIndex] do
begin
////////////////////檢查文件是否存在/////////////////////////////////////
TempLength:=checkAndgetFilesize(FilepathName);
if TempLength=0 then
begin
result:=0;
exit;
end;
////////////////////////////////////////////////////////////
if SearchTimes=0 then
begin
tempSize:=tempLength;
TotalProcess:= TempSize;
Result:=4; ///ok
exit;
end;
/////////////////////是否重復低階搜索初始化////////////////////////////////////////
if ((SearchTimes=1) and (OldVartype=LowLevel_value) and (ScanType=InitialLowLevel_Scan) )then
begin
Result:=1;
Exit;
end;
//////////////////高低階是否匹配///////////////////////////////////////////////
if SearchTimes>0 then
begin
if ( (OldVarType=Lowlevel_Value) and (VarType<>Lowlevel_Value) ) or
( (OldVarType<>Lowlevel_Value) and (VarType=Lowlevel_Value))
then
begin
result:=2;
exit;
end;
end;
/////////////////////確定搜索范圍大小,////////////////////////////////////////////////////////////
if SearchTimes>0 then
begin
if (SearchTimes=1) and (OldvarType=LowLevel_Value) then
begin
///TempLength:=checkAndgetFilesize(FilepathName);
TempSize:=TempLength;
end else
begin
TempLength:=AddressMemStream.Size;
TempSize:=TempLength shr 2;
end;
if TempSize=0 then begin Result:=3; exit; end;
TotalProcess:= TempSize;
Result:=4;/////ok
end;
///////////////////////////////
end;//////with end
end;
function TArchiveEditForm.CheckForScan:boolean;
begin
Result:=false;
with theFiletask[CurrentFileTaskIndex] do begin
case AnalyseScan(CurrentFileTaskIndex) of
0: begin
Raise Exception.Create(String_FileTaskinvalid);
end;
1: begin
if MessageBox(Application.Handle,pchar(String_FileAskRepeatInitLowLevel),
pchar(String_FileAskRepeatInitLowLevelTitle),
MB_YESNO or MB_ICONINFORMATION)=IDYES then
begin
TotalProcess:=0;
SearchTimes:=0;
AttachedNum:=0;
AddressMemStream.Clear;
Result:=True;
Exit;
end else exit;
end;
2: begin
if MessageBox(Application.Handle,pchar(String_FileTypeNoMatch),
pchar(String_FileTypeNoMatchTitle),
MB_YESNO or MB_ICONINFORMATION)=IDYES then
begin
TotalProcess:=0;
SearchTimes:=0;
AttachedNum:=0;
AddressMemStream.Clear;
Result:=True;
exit;
end else Exit;
end;
3: begin
if MessageBox(Application.Handle,pchar(String_FileNoResultAgain),
pchar(String_FileNoResultAgainTitle),
MB_YESNO or MB_ICONINFORMATION)=IDYES then
begin
TotalProcess:=0;
SearchTimes:=0;
AttachedNum:=0;
AddressMemStream.Clear;
Result:=True;
Exit;
end else Exit;
end;
4: Result:=True;
end; ///case end
end;///with edn
end;
procedure TArchiveEditForm.Scan_bnClick(Sender: TObject);
begin
if FileTaskNum=0 then
begin
if MessageBox(Application.Handle,pchar(String_Addtask),pchar(String_Addtasktitle),
MB_YESNO or MB_ICONINFORMATION)=IDYES then
AddFile_TB.Click;
Exit;
end;
with theFileTask[CurrentFiletaskIndex] do
begin
if InSearchProcess then
begin
MessageBox(Application.Handle,pchar(String_InScan),pchar(String_InScanTitle),
MB_OK or MB_ICONINFORMATION);
exit;
end;///防止搜索過程中不斷點擊
ScanType:=GetScanTypeAndTempVar(Value_Edit.text,CurrentFiletaskIndex);
if ScanType=-999 then begin RaiseInputError;exit;end;
/////Vartype必須考慮Combobox的選擇
theFileTask[CurrentFiletaskIndex].VarType:=VarType_cb.ItemIndex;
varType:=GetVarTypeAndVarValue(ScanValue,CurrentFiletaskIndex);
if varType=-999 then begin RaiseInputError;exit;end;
if not CheckForScan then exit;
if SearchTimes=0 then
begin
TFileFirstScanThread.Create(CurrentFileTaskIndex);
end else
begin
TFileNextScanThread.Create(CurrentFileTaskIndex);
end;
end;///with end;
end;
//////////////////初次掃描////////////////////////////////
constructor TFileFirstScanThread.Create(theIndex:integer);
begin
TheTaskIndex:=theIndex;
inherited Create(False);
end;
Procedure TFileFirstScanThread.Execute;
var TempLength: DWORD; ////字節大小
TempSize:DWORD; //// 實際的讀取尺寸
ReadByte: Byte;
ReadWord: Word;
ReadDWord: Dword;
ReadInt64: Int64;
// ReadSingle: Single;
// Readdouble: double;
ReadCharByte:Byte;
PhelpSingleDword:^Dword;
helpsingleDWord1:DWord; //存放原數的符號位與指數位
HelpSingleDword2:Dword;
PhelpDoubleint64:^int64;
helpDoubleint641:int64; //存放原數的符號位與指數位
HelpDoubleint642:int64;
HelpStringLength:Byte;
chartoFind:integer;
Time1:Dword;
Time2:Dword;
i: integer;
// j: integer;
// k: integer;
ByteValue: Byte;
WordValue: Word;
DWordValue: Dword;
Int64Value: Int64;
SingleValue: Single;
doubleValue: double;
tempFileMemStream:TmemoryStream;
tempAddress:Dword;
begin
FreeOnTerminate:=True;
/////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
/////////////再次并得到最終數據/////////////////////////////////////////
with theFileTask[theTaskIndex] do
begin
if (scanType=Number_Scan) then
begin
if Vartype=Byte_value then
begin
val(scanvalue,bytevalue,i);
if i>0 then raise Exception.Create(Format(String_InvalidByte,[scanvalue]));
end;
if vartype=word_value then
begin
val(scanvalue,wordvalue,i);
if i>0 then raise Exception.Create(Format(String_InvalidWord,[scanvalue]));
end;
if vartype=dword_value then
begin
val(scanvalue,dwordvalue,i);
if i>0 then raise Exception.Create(Format(String_InvalidDword,[scanvalue]));
end;
if vartype=Int64_value then
begin
val(scanvalue,Int64value,i);
if i>0 then raise Exception.Create(Format(String_InvalidInt64,[scanvalue]));
end;
if vartype=single_value then
begin
val(scanvalue,singlevalue,i);
if i>0 then raise Exception.Create(Format(String_InvalidSingle,[scanvalue]));
end;
if vartype=double_value then
begin
val(scanvalue,doublevalue,i);
if i>0 then raise Exception.create(Format(String_InvalidDouble,[scanvalue]));
end;
if vartype=String_value then
begin
if Length(scanvalue)>255 then raise Exception.create(Format(String_InvalidString,[scanvalue]));
end;
end;//if end;
////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
AddressMemStream.Seek(0,soFromBeginning);
OldScanType:=ScanType;
InSearchProcess:=True;
Searchtimes:=1;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -