立案

2016-03-17 27 views
-1

德爾福更改十六進制地址,我想在德爾福變化六角ADRESS 15字符,立案

enter image description here

我按照這樣的方式,但我沒有得到成功,

BlockRead(F,arrChar,1);     //read all to the buf 
CloseFile(F);       //close file 
IMEI:=Form1.Edit1.Text;     //get the number 
Form1.Memo1.Lines.Add('new IMEI is'+IMEI); //output 

for i:=524288 to 524288+15 do    /
    arrChar[i]:=IMEI[i-524287]; 

回答

2

與執行此操作一個文件流。

var 
    Stream: TFileStream; 
.... 
Stream := TFileStream.Create(FileName, fmOpenWrite); 
try 
    Stream.Position := $080000; 
    Stream.WriteBuffer(IMEI, SizeOf(IMEI)); 
finally 
    Stream.Free; 
end; 

我假設IMEI是長度爲15字節的固定長度的數組,但你的代碼試圖寫入16個字節,因此這樣看來,您是從程度的混亂痛苦。

在你的代碼中,你的變量IMEI是一個字符串。這不是一個字節數組。請不要將字符串視爲一個字節數組的經典錯誤。

你可能會宣佈一個IMEI類型是這樣的:

type 
    TIMEI = array [0..14] of Byte; 

然後,你可以寫一個函數從文本填充這樣一個變量:

function TextToIMEI(const Text: string): TIMEI; 
var 
    ResultIndex, TextIndex: Integer; 
    C: Char; 
begin 
    if Length(Text) <> Length(Result) then 
    raise SomeExceptionClass.Create(...); 

    TextIndex := low(Text); 
    for ResultIndex := low(Result) to high(Result) do 
    begin 
    C := Result[TextIndex]; 
    if (C < '0') or (C > '9') then 
     raise SomeExceptionClass.Create(...); 
    Result[ResultIndex] := ord(C); 
    inc(TextIndex); 
    end; 
end; 

你可能會再與上面結合該代碼:

procedure WriteIMEItoFile(const FileName: string; FileOffset: Int64; const IMEI: TIMEI); 
var 
    Stream: TFileStream; 
begin 
    Stream := TFileStream.Create(FileName, fmOpenWrite); 
    try 
    Stream.Position := FileOffset; 
    Stream.WriteBuffer(IMEI, SizeOf(IMEI)); 
    finally 
    Stream.Free; 
    end; 
end; 

請這樣稱呼:

WriteIMEItoFile(FileName, $080000, TextToIMEI(Form1.Edit1.Text)); 

雖然你是明確使用Form1全局變量看起來有點奇怪。如果該代碼以TForm1的方法執行,則應使用隱含的Self變量。

+0

謝謝!工作鏈像魅力:) –