Mutual embedding of variant and stream in Delphi

Source: Internet
Author: User

Conversion of stream and variant types is often required when using COM and COM + in Delphi.

 

1 Procedure Vartostream ( VaR ASTM: tstream; VaR Aovar: olevariant );
2 VaR
3 P: pointer;
4 Begin
5 ASTM: = Tmemorystream. Create;
6 ASTM. Position: =   0 ;
7 P: = Vararraylock (aovar );
8 ASTM. Write (P ^, vararrayhighbound (aovar, 1 ));
9 Vararrayunlock (aovar );
10 End ;
11
12 Procedure Streamtovar ( VaR ASTM: tstream; VaR Aovar: olevariant );
13 VaR
14 P: pointer;
15 Begin
16 Aovar: = Vararraycreate ([ 0 , ASTM. Size -   1 ], Varbyte );
17 P: = Vararraylock (aovar );
18 ASTM. readbuffer (P ^, ASTM. size );
19 Vararrayunlock (aovar );
20 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.