Forum > General

TPropVariant problem

(1/2) > >>

Ricco:
Hey guys :)

I'm trying to convert a unit that was written for delphi to lazarus.
The unit is the Delphi 7zip plugin Api by Henri Gourvest.
http://www.progdigy.com/?page_id=13
http://code.google.com/p/d7zip/downloads/list
I've used the 'convert delphi to lazarus unit' option but how surprisingly there are still some erros left.
Maybe one of you can help me ;)
The code:

--- Code: ---procedure SetCardinalProperty(arch: I7zOutArchive; const name: UnicodeString; card: Cardinal);
var
  value: OleVariant;
begin
  TPropVariant(value).vt := VT_UI4;
  TPropVariant(value).ulVal := card;
  arch.SetPropertie(name, value);
end;

--- End code ---
Error Message: Illegal type conversion: "OleVariant" to "<record type>"

Ciao
  Riccardo :)

JuhaManninen:
What is the second parameter type for : arch.SetPropertie(name, value);
?
Make the "value" variable's type match the parameter type.

Juha

Ricco:
Hey Juha :)

The second parameter type for arch.SetPropertie(name, value) is OleVariant.
I7zOutArchive = interface
  ['{BAA9D5DC-9FF4-4382-9BFD-EC9065BD0125}']
procedure SetPropertie(name: UnicodeString; value: OleVariant); stdcall;

But the code the compiler complains about is TPropVariant(value).vt := VT_UI4; <- Error Message: Illegal type conversion: "OleVariant" to "<record type>".

The TPropVariant declaration in the ActiveX Unit is:

--- Code: ---...
...
VT_UI4 = 19;
...
...
 TPROPVARIANT = record
          vt : VARTYPE;
          wReserved1 : PROPVAR_PAD1;
          wReserved2 : PROPVAR_PAD2;
          wReserved3 : PROPVAR_PAD3;
          case longint of
                 0 : ( cVal : CHAR );
                 1 : ( bVal : UCHAR );
                 2 : ( iVal : SHORT );
                 3 : ( uiVal : USHORT );
                 4 : ( lVal : LONG );
                 5 : ( ulVal : ULONG );
                 6 : ( intVal : longINT );
                 7 : ( uintVal : UINT );
                 8 : ( hVal : LARGE_INTEGER );
                 9 : ( uhVal : ULARGE_INTEGER );
                 10 : ( fltVal : SINGLE );
                 11 : ( dblVal : DOUBLE );
                 12 : ( boolVal : VARIANT_BOOL );
                 13 : ( bool : _VARIANT_BOOL );
                 14 : ( scode : SCODE );
                 15 : ( cyVal : CY );
                 16 : ( date : DATE );
                 17 : ( filetime : FILETIME );
                 18 : ( puuid : ^CLSID );
                 19 : ( pclipdata : ^CLIPDATA );
                 20 : ( bstrVal : BSTR );
                 21 : ( bstrblobVal : BSTRBLOB );
                 22 : ( blob : BLOB );
                 23 : ( pszVal : LPSTR );
                 24 : ( pwszVal : LPWSTR );
                 25 : ( punkVal : pointer; { IUnknown to avoid Data types which require initialization/finalization can't be used in variant records});
                 26 : ( pdispVal : pointer; {IDispatch} );
                 27 : ( pStream : pointer {IStream} );
                 28 : ( pStorage : pointer{IStorage} );
                 29 : ( pVersionedStream : LPVERSIONEDSTREAM );
                 30 : ( parray : LPSAFEARRAY );
                 31 : ( cac : CAC );
                 32 : ( caub : CAUB );
                 33 : ( cai : CAI );
                 34 : ( caui : CAUI );
                 35 : ( cal : CAL );
                 36 : ( caul : CAUL );
                 37 : ( cah : CAH );
                 38 : ( cauh : CAUH );
                 39 : ( caflt : CAFLT );
                 40 : ( cadbl : CADBL );
                 41 : ( cabool : CABOOL );
                 42 : ( cascode : CASCODE );
                 43 : ( cacy : CACY );
                 44 : ( cadate : CADATE );
                 45 : ( cafiletime : CAFILETIME );
                 46 : ( cauuid : CACLSID );
                 47 : ( caclipdata : CACLIPDATA );
                 48 : ( cabstr : CABSTR );
                 49 : ( cabstrblob : CABSTRBLOB );
                 50 : ( calpstr : CALPSTR );
                 51 : ( calpwstr : CALPWSTR );
                 52 : ( capropvar : CAPROPVARIANT );
                 53 : ( pcVal : pCHAR );
                 54 : ( pbVal : pUCHAR );
                 55 : ( piVal : pSHORT );
                 56 : ( puiVal : pUSHORT );
                 57 : ( plVal : pLONG );
                 58 : ( pulVal : pULONG );
                 59 : ( pintVal : plongint );
                 60 : ( puintVal : pUINT );
                 61 : ( pfltVal : psingle );
                 62 : ( pdblVal : pDOUBLE );
                 63 : ( pboolVal : ^VARIANT_BOOL );
                 64 : ( pdecVal : pDECIMAL );
                 65 : ( pscode : ^SCODE );
                 66 : ( pcyVal : ^CY );
                 67 : ( pdate : ^DATE );
                 68 : ( pbstrVal : ^TBSTR );
                 69 : ( ppunkVal : ^IUnknown );
                 70 : ( ppdispVal : ^IDispatch );
                 71 : ( pparray : ^LPSAFEARRAY );
                 72 : ( pvarVal : ^PROPVARIANT );
             end;
     PROPVARIANT=TPROPVARIANT;
     TagPROPVARIANT = TPROPVARIANT;

--- End code ---

Ciao
  Ricco :)

marcov:
Some olevariant stuff was fixed in 2.5.1.

JuhaManninen:
> The second parameter type for arch.SetPropertie(name, value) is OleVariant.

Ricco, maybe this would work:


--- Code: ---var
  PropVar: TPropVariant;
  value: OleVariant;
begin
  PropVar.vt := VT_UI4;
  PropVar.ulVal := card;
  value := PropVar;
  arch.SetPropertie(name, value);

--- End code ---

I didn't test it because I don't have Windows here now.

It is a pity your port will be Windows only. Do you think it's possible to extract the code without OLE ActiveX and make a portable Lazarus package?

Regards,
Juha

Navigation

[0] Message Index

[#] Next page

Go to full version