关于delphi Move函数的用法详解
使用delphi多年,前些天忽然遇到不会string转pbyte,很是失落,此时对于编程基本功的重要性深有体会.这其中用到MOVE函数.
搞了好一会才搞明白其用法.所以想贴出来帮助需要帮助的人.
var
s:string;
ps:Pchar;
b:pbyte;
len:integer;
begin
s:=edit1.Text; //字符串
ps:=pchar(s); //转成pchar类型,
len:=length(s);//取字符串长度,占用多少字节
getmem(b,len);//申请内存,pchar,pbyte在使用前都必须要申请内存,因为他们是指针.
move(ps^,b^,len);//这里 ps^意思是pchar指向内存数据的第一个字节地址,B^是表示申请内存的第一个字节地址,这样就可以一个一个字节的移到b里去了.
memo1.Text:=pchar(b);//显示.
freemem(b);
end;
有些人遇到的困惑是为什么 move(s,b,len)不行呢?同样我也遇到这样的困惑.
看了一样move的函数源码才明白.
procedure Move( const Source; var Dest; count : Integer );
{$IFDEF PUREPASCAL}
var
S, D: PChar;
I: Integer;
begin
S := PChar(@Source);//取内存地址
D := PChar(@Dest);//取内存地址
if S = D then Exit;
if Cardinal(D) > Cardinal(S) then
for I := count-1 downto 0 do
D[I] := S[I]
else
for I := 0 to count-1 do
D[I] := S[I];
end;
如果直接传入s,
S := PChar(@Source);//取内存地址\
就相当于取的字符串S地址的地址.
如果传入的是ps^
S := PChar(@Source);//取内存地址
就相当于取pchar 所指向字符串实际数据的地址.
相关文档:
delphi 编写的com 对象 用php调用
的
实例
delphi:
function Tmyxml.Get_xml: WideString;
begin
Get_xml:='wo shi a lei!';
end;
function Tmyxml.Get_xmldata: WideString;
var
xmlStr:string;
begin
xmlStr := '<?xml version="1.0" & ......
Procedure TForm1.Button1Click(Sender: TObject);
Var
xmlstr,FileName: String;
f: Textfile;
Begin
xmlStr := '<?xml version="1.0" encoding="gb2312"?>';
xmlstr := xmlstr + '<user><name>张三</name><sex>男</sex></user>';
sh ......
Delphi in a Unicode World Part II: New RTL Features and
Classes to Support Unicode
By: Nick
Hodges
原文链接:http://dn.codegear.com/article/38498
Abstract: This article will cover the new features of the Tiburon
Runtime Library that will help handle Unicode strings.
//
& ......
问题背景:
公司希望使用Magento来进行接单,而后把订单导入到一个ERP系统中(订单处理引擎)。
问题:
在使用WebService从Magento中获取Payment信息时,信用卡是被加密的(法律规定不允许在数据库中存储信用卡的明文信息)!
......
Delphi 7之后的版本,增加了运算符的重载。虽然不尽人意(需要写特定英文),但有总比没有强。
例:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
T3DPoint = record
X, Y, Z: Doub ......