全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:2446
推到 Plurk!
推到 Facebook!

字串搜尋取代問題

答題得分者是:syntax
ycl2005
一般會員


發表:15
回覆:14
積分:5
註冊:2005-10-01

發送簡訊給我
#1 引用回覆 回覆 發表時間:2007-05-11 14:45:23 IP:211.21.xxx.xxx 訂閱
我想寫一個程式,是用來修改遊戲中的存檔內容,
程式內容如下, 請高手指點,謝謝.

var
iFileHandle1: Integer;
iFileLength: Integer;
iBytesRead: Integer;
Buffer: PChar;
i: Integer;
str1:string;

begin


try
//把遊戲存檔讀入buffer中
iFileHandle1 := FileOpen(ExtractFilePath(application.ExeName) '\' TargetFile, fmOpenRead);
iFileLength := FileSeek(iFileHandle1,0,2);
FileSeek(iFileHandle1,0,0);
Buffer := PChar(AllocMem(iFileLength 1));
iBytesRead := FileRead(iFileHandle1, Buffer^, iFileLength);
FileClose(iFileHandle1);


//現在問題出在這一段
for i := 0 to iBytesRead-1 do
begin

//我要搜尋 16進位 216F 的資料, 然後改成 16進位 255B不曉得要從何下手
Str1 :=Buffer[i];
end;

//把buffer中的內容存檔
iFileHandle1 := FileCreate(ExtractFilePath(application.ExeName) '\' TargetFile);
FileWrite(iFileHandle1,Buffer^,iFileLength);
FileClose(iFileHandle1);

finally

FreeMem(Buffer);
end;

end;

pcboy
版主


發表:177
回覆:1838
積分:1463
註冊:2004-01-13

發送簡訊給我
#2 引用回覆 回覆 發表時間:2007-05-12 18:11:23 IP:203.204.xxx.xxx 訂閱
Chr(charcode)
 
Remarks
The charcode argument is a number that identifies a character.
Numbers from 0 to 31 are the same as standard, nonprintable ASCII codes. For example, Chr(10) returns a linefeed character.
The following example uses the Chr function to return the character associated with the specified character code: 
  Copy Code 
Dim MyChar
MyChar = Chr(65)   ' Returns A.
MyChar = Chr(97)   ' Returns a.
MyChar = Chr(62)   ' Returns >.
MyChar = Chr(37)   ' Returns %.
 
=============================
Hex(number)
 
Remarks
The number argument is any valid expression.
If number is not already a whole number, it is rounded to the nearest whole number before being evaluated. 
If number is  Hex returns  
Null
 Null.
 
Empty
 Zero (0).
 
Any other number
 Up to eight hexadecimal characters.
 
You can represent hexadecimal numbers directly by preceding numbers in the proper range with &H. For example, &H10 represents decimal 16 in hexadecimal notation.
The following example uses the Hex function to return the hexadecimal value of a number: 
  Copy Code 
Dim MyHex
MyHex = Hex(5)   ' Returns 5.
MyHex = Hex(10)   ' Returns A.
MyHex = Hex(459)   ' Returns 1CB.
 
------
能力不足,求助於人;有能力時,幫幫別人;如果您滿意答覆,請適時結案!

子曰:問有三種,不懂則問,雖懂有疑則問,雖懂而想知更多則問!
syntax
尊榮會員


發表:26
回覆:1139
積分:1258
註冊:2002-04-23

發送簡訊給我
#3 引用回覆 回覆 發表時間:2007-05-14 14:45:00 IP:61.64.xxx.xxx 訂閱
多看、多聽、還要多用你的大腦

Buffer 請用 WORD 或 SmallInt

先將 216F 轉成數字,並放在 Value 內

然後直接比對 Value := Buffer[i] 即可

(懶得寫回存程式的話,直接用 Memory Map file)
ycl2005
一般會員


發表:15
回覆:14
積分:5
註冊:2005-10-01

發送簡訊給我
#4 引用回覆 回覆 發表時間:2007-05-14 14:50:14 IP:211.21.xxx.xxx 訂閱
看了各位的指點, 已有些靈感和方向,

我先結案, 若程式完成會與大家分享,

若還有問題,還請繼續指點. 謝謝.
系統時間:2024-05-19 10:38:49
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!