var
bb:array[0..15] of byte
ss:string;
nn,ii,nret:integer;
nn:=288;
ii:=258;
zeroMemory(@bb[0],16);
copyMemory(@bb[0],@nn,2);
copyMemory(@bb[2],@ii,2); //288可以用2Byte存储(16bit),258也是,现在上面已经成功的存入bb中了,问题是怎么取出还原出来?其中bb中还不止存了这些,还有4B存的32bit整数,8B存的64bit整数,都要分段读还原出来。
type
pint=^integer;
var
pi:pint;
pi:=bb
nret:=pi^;//这不行的,我要分别将288和258还原出来,还有就是,就算我只存了288,这样取出来的也不是288,而是很大的一个整数。
还有用makeword,makelong来实现也不行,好像还原后都变了,都是大大的一整数。请高手帮帮忙。
bb:array[0..15] of byte
ss:string;
nn,ii,nret:integer;
nn:=288;
ii:=258;
zeroMemory(@bb[0],16);
copyMemory(@bb[0],@nn,2);
copyMemory(@bb[2],@ii,2); //288可以用2Byte存储(16bit),258也是,现在上面已经成功的存入bb中了,问题是怎么取出还原出来?其中bb中还不止存了这些,还有4B存的32bit整数,8B存的64bit整数,都要分段读还原出来。
type
pint=^integer;
var
pi:pint;
pi:=bb
nret:=pi^;//这不行的,我要分别将288和258还原出来,还有就是,就算我只存了288,这样取出来的也不是288,而是很大的一个整数。
还有用makeword,makelong来实现也不行,好像还原后都变了,都是大大的一整数。请高手帮帮忙。
解决方案 »
- 散分了,麻烦帮ping一下,100分送上
- 麻烦大家帮我看看:读写注册表的问题!
- 问:wwDBGrid如何实现点按Columns标题列排序???
- 串口操作的问题
- 关于动态数组 内存溢出,大家都是怎么解决地?
- ListView如何进行排序操作?可以吗?
- 急急,今天要加进程序中,大家帮忙啊,狂送50分
- 急求adotable操作问题,在线等待。
- 如何取得openDialog的路径?
- 五十多个功能模块(表单),是做成dll还是编译进一个exe?
- 100分寻求答案!Select * from [;Database=D:\hacc\Data\db1.mdb;pwd=123456].table1 此语句粘帖到Access查询中执行没问题,但是在程序中
- 求一个从SQLSERVER2000中导数据到TXT文件的方法!
begin
{$IFDEF DotNet}
Result := System.BitConverter.GetBytes(AValue);
{$ELSE}
SetLength(Result, SizeOf(Byte));
Result[0] := Byte(AValue);
{$ENDIF}
end;function ToBytes(const AValue: Int64): TBytes; overload;
begin
{$IFDEF DotNet}
Result := System.BitConverter.GetBytes(AValue);
{$ELSE}
SetLength(Result, SizeOf(Int64));
PInt64(@Result[0])^ := AValue;
{$ENDIF}
end;function ToBytes(const AValue: Integer): TBytes; overload;
begin
{$IFDEF DotNet}
Result := System.BitConverter.GetBytes(AValue);
{$ELSE}
SetLength(Result, SizeOf(Integer));
PInteger(@Result[0])^ := AValue;
{$ENDIF}
end;function ToBytes(const AValue: Cardinal): TBytes; overload;
begin
{$IFDEF DotNet}
Result := System.BitConverter.GetBytes(AValue);
{$ELSE}
SetLength(Result, SizeOf(Cardinal));
PCardinal(@Result[0])^ := AValue;
{$ENDIF}
end;function ToBytes(const AValue: Short): TBytes; overload;
begin
{$IFDEF DotNet}
Result := System.BitConverter.GetBytes(AValue);
{$ELSE}
SetLength(Result, SizeOf(Shortint));
PShortint(@Result[0])^ := AValue;
{$ENDIF}
end;function ToBytes(const AValue: Word): TBytes; overload;
begin
{$IFDEF DotNet}
Result := System.BitConverter.GetBytes(AValue);
{$ELSE}
SetLength(Result, SizeOf(Word));
PWord(@Result[0])^ := AValue;
{$ENDIF}
end;function ToBytes(const AValue: Byte): TBytes; overload;
begin
SetLength(Result, SizeOf(Byte));
Result[0] := AValue;
end;
function BytesToChar(const AValue: TBytes): Char;
begin
{$IFDEF DotNet}
Result := System.BitConverter.ToChar(AValue, 0);
{$ELSE}
Result := Char(AValue[0]);
{$ENDIF}
end;function BytesToInteger(const AValue: TBytes): Integer;
begin
{$IFDEF DotNet}
Result := System.BitConverter.ToInt32(AValue, 0);
{$ELSE}
Result := PInteger(@AValue[0])^;
{$ENDIF}
end;function BytesToInt64(const AValue: TBytes): Int64;
begin
{$IFDEF DotNet}
Result := System.BitConverter.ToInt64(AValue,0);
{$ELSE}
Result := PInt64(@AValue[0])^;
{$ENDIF}
end;function BytesToWord(const AValue: TBytes): Word;
begin
{$IFDEF DotNet}
Result := System.BitConverter.ToUInt16(AValue,0);
{$ELSE}
Result := PWord(@AValue[0])^;
{$ENDIF}
end;function BytesToShort(const AValue: TBytes): Short;
begin
{$IFDEF DotNet}
Result := System.BitConverter.ToInt16(AValue,0);
{$ELSE}
Result := PShortint(@AValue[0])^;
{$ENDIF}
end;function BytesToCardinal(const AValue: TBytes): Cardinal;
begin
{$IFDEF DotNet}
Result := System.BitConverter.ToUInt32(AValue, 0);
{$ELSE}
Result := PCardinal(@AValue[0])^;
{$ENDIF}
end;