Delphi 的字符及字符串[5] - 字符串与 Windows API

Windows API 中的字符串对应这 Delphi 的 PChar(PAnsiChar); 在 API 中使用 Delphi 的字符串还是比较灵活的.

先说赋值:


 

 
 
  SetWindowText(Handle, );
;

  p: PChar;

  p := ;
  SetWindowText(Handle, p);
;

  str: ;

  str := ;
  SetWindowText(Handle, PChar(str));
;


  arr: [..]  Char;

  arr := ;
  SetWindowText(Handle, arr);
;

再说取值:


 

 
 
  arr: [..]  Char;

  GetWindowText(Handle, arr, );
  ShowMessage(arr); 
;

  p: PChar;

  GetMem(p, ); 
  GetWindowText(Handle, p, );
  ShowMessage(p); 
  FreeMem(p);     
;

  p: HGLOBAL;

  p := GlobalAlloc(, ); 
  GetWindowText(Handle, PChar(p), );
  ShowMessage(PChar(p)); 
  GlobalFree(p);         
;

  str: ;

  SetLength(str, ); 
  GetWindowText(Handle, PChar(str), );

  

  str := PChar(str); 
  ShowMessage(str);  
;

定长字符串不是 #0 结束的, 和 API 不好兼容, 一般不用于 API 中.


 

转载于:https://www.cnblogs.com/skysunmoon/archive/2009/04/07/1430858.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值