Recent

Author Topic: TPropVariant problem  (Read 10218 times)

Ricco

  • Newbie
  • Posts: 3
TPropVariant problem
« on: May 25, 2010, 07:50:21 pm »
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: [Select]
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;
Error Message: Illegal type conversion: "OleVariant" to "<record type>"

Ciao
  Riccardo :)

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4468
  • I like bugs.
Re: TPropVariant problem
« Reply #1 on: May 26, 2010, 03:46:25 am »
What is the second parameter type for : arch.SetPropertie(name, value);
?
Make the "value" variable's type match the parameter type.

Juha
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

Ricco

  • Newbie
  • Posts: 3
Re: TPropVariant problem
« Reply #2 on: May 26, 2010, 05:48:29 am »
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: [Select]
...
...
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;

Ciao
  Ricco :)

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11453
  • FPC developer.
Re: TPropVariant problem
« Reply #3 on: May 26, 2010, 06:32:00 am »
Some olevariant stuff was fixed in 2.5.1.

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4468
  • I like bugs.
Re: TPropVariant problem
« Reply #4 on: May 27, 2010, 07:05:14 am »
> The second parameter type for arch.SetPropertie(name, value) is OleVariant.

Ricco, maybe this would work:

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

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
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

Ricco

  • Newbie
  • Posts: 3
Re: TPropVariant problem
« Reply #5 on: May 27, 2010, 01:50:25 pm »
Hey Juha,

thanks for the code snippet.
But the compiler still complains about OleVariant and TPropVariant:
Code: [Select]
value := PropVar;
Incompatible types: got "TPROPVARIANT" expected "OleVariant"

So it looks like there is no workaround for this at the moment.
The problem is that it's not so easy to access the 7z.dll because
in my opinion it's badly developed.
Normally you should easily access the functions in the 7z.dll.

I'm sure it is possible to make a portable lazarus package but it's
a hard task in my opinion ;)
Maybe I write an email to the developer of peazip and ask him how he
accessed 7z files.

But thanks for all of your suggestions 'til now :)

Ciao Ricco :)

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4468
  • I like bugs.
Re: TPropVariant problem
« Reply #6 on: May 27, 2010, 06:04:03 pm »
So it looks like there is no workaround for this at the moment.
The problem is that it's not so easy to access the 7z.dll because
in my opinion it's badly developed.
Normally you should easily access the functions in the 7z.dll.

I'm sure it is possible to make a portable lazarus package but it's
a hard task in my opinion ;)
Maybe I write an email to the developer of peazip and ask him how he
accessed 7z files.

It seems that Peazip runs a command line 7z program. I was not able to compile  Peazip's source. Maybe it is for some older version of FPC or something.

7zip is ported. There is also 7z.so library available. It should be possible to make a pascal wrapper for the lib about like bzip2lib does.
http://wiki.lazarus.freepascal.org/bzip2lib

Juha
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

 

TinyPortal © 2005-2018