Solve the astext method garbled problem of Delphi clipboard

Source: Internet
Author: User
  1. UseDelphiThe astext method of the clipboard will cause non-English garbled characters. How can this problem be solved? Use Unicode instead.
  2. Procedure setclipboardtext (astr: string );
  3. VaR// Setbuffer (cf_text, pchar (value) ^, length (value) + 1 );
  4. Data: thandle;
  5. Dataptr: pointer;
  6. Size: integer;
  7. Wstr: pwidechar;
  8. Begin
  9. Size: = length (astr )*4;
  10. Wstr: = allocmem (size );
  11. Try
  12. // Convert to Unicode
  13. Stringtowidechar (astr, wstr, size );
  14. Openclipboard (0);
  15. Emptyclipboard;
  16. Data: = globalalloc (gmem_moveable + gmem_ddeshare, size );
  17. Try
  18. Dataptr: = globallock (data );
  19. Try
  20. Move (wstr ^, dataptr ^, size );
  21. Setclipboarddata (cf_unicodetext, data );
  22. Finally
  23. Globalunlock (data );
  24. End;
  25. Except
  26. Globalfree (data );
  27. Raise;
  28. End;
  29. Finally
  30. Closeclipboard;
  31. Freemem (wstr );
  32. End;
  33. End;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.