CAD从二制流数据中加载图形(com接口Delphi语言)

时间:2023-01-26 16:31:43

主要用到函数说明:

_DMxDrawX::ReadBinStream

从二制流数据中加载图形,详细说明如下:

参数 说明

VARIANT varBinArray

二制流数据,是个byte数组

BSTR sPassword

图纸密码.没有密码,传空字符串

LONG lReadContent

加载内容,如果全部加载,传16777215,十六进制0xFFFFFF

Delphi代码实现如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
            function OleToMStream(OV:OleVariant): TMemoryStream;
            var
              Data: PByteArray;
              Size: integer;
            beginResult:=TMemoryStream.Create;                     try
                       Size:=VarArrayHighBound(OV,1)-VarArrayLowBound(OV,1)+1;
                       Data:=VarArrayLock(OV);                         try
                           Result.Position:=0;
                           Result.WriteBuffer(Data^,Size);
                         finally
                           VarArrayUnlock(OV);
                         end;
                     except
                       Result.Free;Result:=nil;
                     end;
                   end;
  
                   function MStreamToOle(Strm:TMemoryStream): OleVariant;
                   var
                     Data: PByteArray;
                   beginResult:= VarArrayCreate([0,   Strm.Size   -   1],   varByte);
                     Data:=   VarArrayLock(Result);                     try
                         Strm.Position   :=   0;
                         Strm.ReadBuffer(Data^,   Strm.Size);
                     finally
                         VarArrayUnlock(Result);
                     end;
                   end;
  
                   procedure TForm2.Button6Click(Sender: TObject);
                   var
                     aryData:OleVariant;
                     memStream : TMemoryStream ;
                     aryReadData:     OleVariant;
                   begin 
                      // 写到内存流
                      MxDrawX1.WriteBinStream(aryData,'',23);
                      memStream := OleToMStream(aryData); 
                      // 从内存流加载
                      aryReadData := MStreamToOle( memStream);
                      MxDrawX1.ReadBinStream(aryData,'',23);
  
                   end;