下面是我的一段代码.
问题是这样的: 我想实现以下过程 string -> WideString -> ByteArray -> WideString -> string.
但是中间出了问题,输入的string和得到的string并不相同.
以前我是学C++的,后来改用Delphi了,但Pascal基础不好.请大家多多指教.
procedure TfmMain.btnTestClick(Sender: TObject);
var
W, R: WideString;
S: string;
P: PByteArray;
I: Integer;
begin
S := '中国人123';
I := Length(S);
P := AllocMem(I * 2);
try
W := S;
Move(W[1], P^[3], I);
SetLength(R, I);
Move(P^[3], R[1], I);
S := R;
ShowMessage(Format('[%s]', [S]);
finally
FreeMem(P);
end;
end;
问题是这样的: 我想实现以下过程 string -> WideString -> ByteArray -> WideString -> string.
但是中间出了问题,输入的string和得到的string并不相同.
以前我是学C++的,后来改用Delphi了,但Pascal基础不好.请大家多多指教.
procedure TfmMain.btnTestClick(Sender: TObject);
var
W, R: WideString;
S: string;
P: PByteArray;
I: Integer;
begin
S := '中国人123';
I := Length(S);
P := AllocMem(I * 2);
try
W := S;
Move(W[1], P^[3], I);
SetLength(R, I);
Move(P^[3], R[1], I);
S := R;
ShowMessage(Format('[%s]', [S]);
finally
FreeMem(P);
end;
end;
解决方案 »
- 哪位大侠行行好.给俺看看到底哪错了
- 新手请教关于fastreport的问题
- delphi中如何创建无标题栏的MDI子窗体!
- 使用Allocmem分配内存,用Freemem释放,但程序占用的内存一直增加,怎么回事?哪位给解释一下?
- 如何将数据表导出Excel格式文件?
- 高分求救明明已经引用了单元文件,为什么编译时总是出现:File not found:'xxx_TLB.dcu'
- delphi有什么好用的表格控件呀
- 怎样在向数据库添加图片的时候跳出选择图片位置的提示框?
- 如何使主程序的ADO的Connection供多个DLL使用?
- 请问如何用delphi将RGB图像转为灰度图像啊~~~!!! 谢谢各位高手了 越详细越好~~~!!
- Delphi2007 写了个DLL,怎么在Delphi7调用错误
- 动态链接库的接口问题
procedure TfmMain.btnTestClick(Sender: TObject);
var
W, R: WideString;
S: string;
P: PByteArray;
I: Integer;
begin
S := '中国人123';
I := Length(S);
P := AllocMem(I * 2);
try
W := S;
Move(W[1], P^[0], I);
SetLength(R, I);
Move(P^[0], R[1], I);
S := R;
ShowMessage(Format('[%s]', [S]);
finally
FreeMem(P);
end;
end;
procedure TfmMain.btnTestClick(Sender: TObject);
var
W, R: WideString;
S: string;
P: PByteArray;
I: Integer;
begin
S := '中国人123 ';
W := S;
I := Length(W);
P := AllocMem(I * 2);
try
Move(W[1], P^[0], I * 2);
SetLength(R, I);
Move(P^[0], R[1], I * 2);
S := R;
ShowMessage(Format( '[%s] ', [S]));
finally
FreeMem(P);
end;
end;