Board index » delphi » Converting some VB code - saving a variant array

Converting some VB code - saving a variant array

Hi,

I need to use a component to interface with a digital camera.
The examples are given in VB, and I need to convert the code to Delphi.

The camera's GetIndex() method, in Delphi, returns an OleVariant. I'm not
sure how I should save this variable into a valid jpg file on disk.

The VB code is as follows:

' capture the picture
RyeCtrl.Capture (0)

indexSize = RyeCtrl.propIndexSize(0)

If indexSize <> 0 Then

  ' create buffer size of index
  ReDim indexBuff(indexSize) As Byte

  ' get picture from camera
  RyeCtrl.GetIndex 0, indexSize, indexBuff

  ' save to file
  FileNum = FreeFile
  Open "index.jpg" For Random as FileNum Len = 1
  ' write index picture data
  For cnt = 1 to indexSize
    Put FileNum, cnt, indexBuff(cnt - 1)
  Next

  Close FileNum

End If

In Delphi the GetIndex method is defined as follows:

GetIndex (ACamNum : Integer; AIndexSize : Integer; Var ABuffer : OleVariant);

How could I save the returned buffer to a file?

regards,

TopDogg

 

Re:Converting some VB code - saving a variant array


I assume the translation would be:

var
  IndexSize: Integer;
  IndexBuff: OleVariant;
  F: File;
  P: Pointer;
begin
  RyeCtrl.Capture(0);
  IndexSize := RyeCtrl.propIndexSize(0);
  if IndexSize <> 0 then
  begin
    IndexBuff := VarArrayCreate([0, IndexSize - 1], varByte);
    RyeCtrl.GetIndex(0, IndexSize, IndexBuff);
    AssignFile(F, 'index.jpg');
    Rewrite(F, 1);
    try
      P := VarArrayLock(IndexBuff);
      try
        BlockWrite(F, P^, IndexSize);
      finally
        VarArrayUnlock(IndexBuff);
      end;
    finally
      CloseFile(F);
    end;
  end;
end;

Quote
"TopDogg" <topd...@start.no> wrote in message

news:fa1418d.0109252229.283ab073@posting.google.com...
Quote
> Hi,

> I need to use a component to interface with a digital camera.
> The examples are given in VB, and I need to convert the code to Delphi.

> The camera's GetIndex() method, in Delphi, returns an OleVariant. I'm not
> sure how I should save this variable into a valid jpg file on disk.

> The VB code is as follows:

> ' capture the picture
> RyeCtrl.Capture (0)

> indexSize = RyeCtrl.propIndexSize(0)

> If indexSize <> 0 Then

>   ' create buffer size of index
>   ReDim indexBuff(indexSize) As Byte

>   ' get picture from camera
>   RyeCtrl.GetIndex 0, indexSize, indexBuff

>   ' save to file
>   FileNum = FreeFile
>   Open "index.jpg" For Random as FileNum Len = 1
>   ' write index picture data
>   For cnt = 1 to indexSize
>     Put FileNum, cnt, indexBuff(cnt - 1)
>   Next

>   Close FileNum

> End If

> In Delphi the GetIndex method is defined as follows:

> GetIndex (ACamNum : Integer; AIndexSize : Integer; Var ABuffer :
OleVariant);

> How could I save the returned buffer to a file?

> regards,

> TopDogg

Re:Converting some VB code - saving a variant array


Hi and thanks for the response,

I tried the code and it writes the amount of bytes in IndexSize
to the specified file, however the result does not seem to be
a valid jpg file (it just displays as all black in ACDSee, for instance).

Also tried via TFileStream.WriteBuffer, with the same result.

Do you know how I could inspect the variant to see if it contains
real data before it is written to file?

regards,

Top D.

Quote
"M.H. Avegaart" <avega...@NOSPAMmccomm.nl> wrote in message <news:9os1p7$vf4$1@scavenger.euro.net>...
> I assume the translation would be:

> var
>   IndexSize: Integer;
>   IndexBuff: OleVariant;
>   F: File;
>   P: Pointer;
> begin
>   RyeCtrl.Capture(0);
>   IndexSize := RyeCtrl.propIndexSize(0);
>   if IndexSize <> 0 then
>   begin
>     IndexBuff := VarArrayCreate([0, IndexSize - 1], varByte);
>     RyeCtrl.GetIndex(0, IndexSize, IndexBuff);
>     AssignFile(F, 'index.jpg');
>     Rewrite(F, 1);
>     try
>       P := VarArrayLock(IndexBuff);
>       try
>         BlockWrite(F, P^, IndexSize);
>       finally
>         VarArrayUnlock(IndexBuff);
>       end;
>     finally
>       CloseFile(F);
>     end;
>   end;
> end;

> "TopDogg" <topd...@start.no> wrote in message
> news:fa1418d.0109252229.283ab073@posting.google.com...
> > Hi,

> > I need to use a component to interface with a digital camera.
> > The examples are given in VB, and I need to convert the code to Delphi.

> > The camera's GetIndex() method, in Delphi, returns an OleVariant. I'm not
> > sure how I should save this variable into a valid jpg file on disk.

> > The VB code is as follows:

> > ' capture the picture
> > RyeCtrl.Capture (0)

> > indexSize = RyeCtrl.propIndexSize(0)

> > If indexSize <> 0 Then

> >   ' create buffer size of index
> >   ReDim indexBuff(indexSize) As Byte

> >   ' get picture from camera
> >   RyeCtrl.GetIndex 0, indexSize, indexBuff

> >   ' save to file
> >   FileNum = FreeFile
> >   Open "index.jpg" For Random as FileNum Len = 1
> >   ' write index picture data
> >   For cnt = 1 to indexSize
> >     Put FileNum, cnt, indexBuff(cnt - 1)
> >   Next

> >   Close FileNum

> > End If

> > In Delphi the GetIndex method is defined as follows:

> > GetIndex (ACamNum : Integer; AIndexSize : Integer; Var ABuffer :
>  OleVariant);

> > How could I save the returned buffer to a file?

> > regards,

> > TopDogg

Re:Converting some VB code - saving a variant array


The variant is just an array of bytes (index values 0 to IndexSize - 1).You
could check if:

IndexBuff[6] = $4a
IndexBuff[7] = $46
IndexBuff[8] = $49
IndexBuff[9] = $46

Quote
"TopDogg" <topd...@start.no> wrote in message

news:fa1418d.0109260824.1ac8ebaf@posting.google.com...
Quote
> Hi and thanks for the response,

> I tried the code and it writes the amount of bytes in IndexSize
> to the specified file, however the result does not seem to be
> a valid jpg file (it just displays as all black in ACDSee, for instance).

> Also tried via TFileStream.WriteBuffer, with the same result.

> Do you know how I could inspect the variant to see if it contains
> real data before it is written to file?

> regards,

> Top D.

> "M.H. Avegaart" <avega...@NOSPAMmccomm.nl> wrote in message

<news:9os1p7$vf4$1@scavenger.euro.net>...

- Show quoted text -

Quote
> > I assume the translation would be:

> > var
> >   IndexSize: Integer;
> >   IndexBuff: OleVariant;
> >   F: File;
> >   P: Pointer;
> > begin
> >   RyeCtrl.Capture(0);
> >   IndexSize := RyeCtrl.propIndexSize(0);
> >   if IndexSize <> 0 then
> >   begin
> >     IndexBuff := VarArrayCreate([0, IndexSize - 1], varByte);
> >     RyeCtrl.GetIndex(0, IndexSize, IndexBuff);
> >     AssignFile(F, 'index.jpg');
> >     Rewrite(F, 1);
> >     try
> >       P := VarArrayLock(IndexBuff);
> >       try
> >         BlockWrite(F, P^, IndexSize);
> >       finally
> >         VarArrayUnlock(IndexBuff);
> >       end;
> >     finally
> >       CloseFile(F);
> >     end;
> >   end;
> > end;

> > "TopDogg" <topd...@start.no> wrote in message
> > news:fa1418d.0109252229.283ab073@posting.google.com...
> > > Hi,

> > > I need to use a component to interface with a digital camera.
> > > The examples are given in VB, and I need to convert the code to
Delphi.

> > > The camera's GetIndex() method, in Delphi, returns an OleVariant. I'm
not
> > > sure how I should save this variable into a valid jpg file on disk.

> > > The VB code is as follows:

> > > ' capture the picture
> > > RyeCtrl.Capture (0)

> > > indexSize = RyeCtrl.propIndexSize(0)

> > > If indexSize <> 0 Then

> > >   ' create buffer size of index
> > >   ReDim indexBuff(indexSize) As Byte

> > >   ' get picture from camera
> > >   RyeCtrl.GetIndex 0, indexSize, indexBuff

> > >   ' save to file
> > >   FileNum = FreeFile
> > >   Open "index.jpg" For Random as FileNum Len = 1
> > >   ' write index picture data
> > >   For cnt = 1 to indexSize
> > >     Put FileNum, cnt, indexBuff(cnt - 1)
> > >   Next

> > >   Close FileNum

> > > End If

> > > In Delphi the GetIndex method is defined as follows:

> > > GetIndex (ACamNum : Integer; AIndexSize : Integer; Var ABuffer :
> >  OleVariant);

> > > How could I save the returned buffer to a file?

> > > regards,

> > > TopDogg

Other Threads