易截截图软件、单文件、免安装、纯绿色、仅160KB

关于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和C++数据类型对照表

Delphi和C++数据类型对照表
Delphi        字长/值域                                C++
ShortInt  &n ......

delphi 编写的com 对象 用php调用的实例

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" & ......

我的Delphi开发经验谈

 
我的Delphi开发经验谈

作者:Icebird
--------
开发环境
--------
    Delphi
7是一个很经典的版本,在Win2000/XP下推荐安装Delphi 7来开发软件,在Vista下推荐使用Delphi 2007开发软件。安装好Delphi
7后,应立即安装Delphi 7 Update Pack 1,Delphi
2007则建议尽量安装最新 ......

Delphi in a Unicode World Part II

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.
//
 & ......

改写了一个常用的DELPHI的加解密函数

DELPHI
//////////////////////////////////
Function   EncrypKey   (Src:String;   Key:String):string;
  var  
  idx   :integer;  
  KeyLen   :Integer;  
  KeyPos   :Integer; &nbs ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号