Delphi 7 Copy Array of Byte to Variant [Edit]


I'm using Delphi 7 and need to copy an array of byte to a variant.
The use case is to copy a file on disk to a variant.

What I doing now is shown below, but it would seem that the start of the file is not transferred to the variant correctly:
The buffer which contains the file would seem to be ok but there is something wrong with the variant.

Thanks in advance for any help.

  afile: file of byte;
  buffer: array of byte;
  i: Integer;

  vv : variant;

        // read the file into an array of byte
        AssignFile(afile, LocalPath+LocalFile);
        SetLength(buffer, FileSize(afile));
        For i := 1 to FileSize(afile) do
                Read(afile, buffer[i - 1]);

        // transfer the array of byte to a variant 
        vv := varArrayCreate([0, length(buffer)-1], varByte );
        for i := 1 to length(buffer)-1 do


Edited by: Paul martin on Oct 30, 2012 9:43 AM
10/30/2012 4:43:18 PM
embarcadero.delphi.general 4258 articles. 0 followers. Follow

2 Replies

Similar Articles

[PageSpeed] 28

I would try it little differently

  vVar: OleVariant;
  pData: Pointer;
  TheStream: TMemoryStream
  TheStream := TMemoryStream.Create;
  TheStream.Position := 0;
  vVar := VarArrayCreate([0, TheStream.Size], varByte);
  pData := VarArrayLock(vVar);
    Move(TheStream.Memory^, pData^, TheStream.Size);

  Result := vVar;
10/30/2012 8:51:43 PM

Thanks for the code, I just had to change TheStream.size to the TheStream.size -1 otherwise I was getting an extra unwanted byte.
Apart from that it works perfectly.
Many thanks for the assistance, much appreciated.

10/31/2012 6:56:02 AM

Similar Artilces:

Convert Delphi 7 to Delphi 2009 [Edit]
Hi! Please, I have a code done in Delphi 7... Now I want to convert Delphi 7 to Delphi 2009 but I'm having problems when compile the code. Error message: +[DCC Fatal Error] Far.dpr(9): F2063 Could not compile used unit 'System.pas'+ Please can somebody help me? Source Download (349KB): Mirror Source Download: Password: delphi Thank u so much! (sorry for my bad english, it is not my native language) Edited by: loquax loquax on Jul 15, 2009 12:24 PM Sorry, bu...

Delphi 7 to Delphi XE: TBlobField to XML [Edit]
Hi, I'm migrating a Delphi7 application to Delphi XE. I'm using a TClientDataSet to communicate, by using a XML frame, with my server. In this TClientDataSet I'm using a TBlobField which is an array of 384 byte. The blobField is allocate by a code like this : {code} myStream : TStream; myStream := aClientDataSet.CreateBlobStream(myBlobField, bmwrite); vResult := myStream.Write(ArrayOf384Byte[0], length(ArrayOf384Byte)); //vResult = 384 => GooD ! (...) {code} For communicate with the server, we have to decode the Blobfield in XML before to sending it. We have...

Code works in Delphi 7 but not in Delphi 2010 [Edit]
hello, i have a procedure that open's a file by passing the file name as the parameter to the executable. something like this {code} C : \ P r o g r a m F i l e s \ Da c k e r \ D r a c k e r . e x e " G : \ D E l p h i 7 \ D e l p h i 7 A p p _ l o g . t " {code} The source code is {code} procedure OpenFileWithExe var hReg: HKEY; Ret: Longint; RegDataType, RegDataSize: DWORD; CmdLine: array [0..560] of Char; Len: Integer; SInfo: TStartupInfo; PInfo: TProcessInformation; begin Ret := windows.RegOpenKeyEx(HKEY_CURRENT_USER, ...

Delphi 7 to Delphi XE2
Hi, Still using that old workhorse, Delphi7, but am going to the conference in London hosted by Embarcadero on Delphi XE2. Although I would like to "move with the times" and am keen to get the UNICODE and 64-bit support offered by the latest IDEs, I confess to being more than a little scared about all the UNICODE/String/AnsiString and 32/64 bit issues I'm probably going to fall over. Anyone recently upgraded from Delphi7 to one of the latest Delphi IDEs? Thanks, Alain On 03/02/2012 08:55, Alain Dekker wrote: > Still using that old workhorse, Delphi7, but...

Delphi 7 to Delphi XE
Have been using Delphi 7 for many moons ( have got later versions but never upgraded to ) My first problem is: Component Palette. in XE it is a small toolbar docked in top right in Delphi 7 it gives a large view of all the components. I am struggling to be able to cope/access my Delphi XE. Can I make the component pallette tool bar the same size as Delphi 7, or is there a fast way to view/choose all available components in XE, that I have not spotted yet? Kind Regards, Robert. Hi, What I know is that in Delphi 2010 and XE you can choose between t...

Delphi 2007 to Delphi 7
I've written a class in Delphi 2007 that is not supported in Delphi 7. What would be the best way to achive what I've done in Delphi 2007 in Delphi 7? Thanks, Tom type BondConstants = class { Bond Types } type BondType = record const TREASURY = 3; AGENCY = 0; CORP = 1; MUNI = 2; SBA = 5; MBS = 4; CMO = 6; end; { Day Count Methods } type DayCount = record const ACTUAL_360 = 2; ACTUAL_365 = 1; ACTUAL_ACTUAL = 1; d30_360 = 0; ...

SEPA components for Delphi with Source Code (Delphi 5
Hi all, in the european union change next year the Bankingformat to the SEPA Format. All peoples and companies must change the bankingssoftware and the costumer data form acountnummers in the new IBAN and BIC numbers. See: Functions: - generate SEPA XML'S - Calc IBAN - BIC Database (DE,AT and CH) Questions: PS: Bankinssoftware for Develpoers (Germany only) El 26/10/13 21:38, A...

Copying RawByteString byte by byte in Delphi XE
I just ran into a problem with XE that I never thought of before... copying a RawByteString to another byte by byte does not work on some Windows versions. The example below runs fine on an English Windows, but on a Windows with a Chinese locale (for example Traditional Hong Kong), it fails: procedure TForm1.Button1Click(Sender: TObject); var S1, S2, UTF8BOM: RawByteString; i: integer; begin UTF8BOM := #$EF#$BB#$BF; S1 := UTF8BOM + '<html>TEST</html>'; S2 := ''; for i := 1 to length(S1) do S2 := S2 + S1[i]; //Does NOT wo...

Delphi 7 TFontDialog and Windows 7 [Edit]
When using the TFontDialog on a Windows 7 box, it will not list the device fonts (printer fonts). If I launch M$ Word on that same machine, Word will list them fine. This works fine on an XP box. Any ideas? Edited by: Tim Muenstermann on Apr 29, 2010 9:05 AM > {quote:title=Tim Muenstermann wrote:}{quote} > When using the TFontDialog on a Windows 7 box, it will not list the device fonts (printer fonts). If I launch M$ Word on that same machine, Word will list them fine. > What Word does (BTW, M$ went out about a decade ago) makes absolutely no difference. Office ...

I wrote an application and used cracked delphi 7, after i bought delphi 7
I wrote an application and used cracked delphi 7, I sold it, after i bought delphi 7 and recompiled application, is now my application legal or? > {quote:title=Ivan Ivanov wrote:}{quote} > I wrote an application and used cracked delphi 7, I sold it, after i bought delphi 7 and recompiled application, is now my application legal or? "I embezzled some money from my employer, returned the funds, and then got it back as a bonus. Can I still be arrested?" Uhhh .... didn't you just confess to a crime? > {quote:title=Ivan Ivanov wrote:}{quote} > I wrote an appli...

Migrating From Delphi 7 to Delphi 2010
We did not know which forum was the best for this question. We have been wanting to migrate from Delphi 7 to a later version for years but it appears to be a daunting task. We first looked at D2006 and that was a radical new world. We bought D2010 a couple of years ago and not done much with it because there are so many parts to our applications. We have done a few new applications in D2010 and they seem to work okay. D2010 has not been impressive, perhaps because of the strangeness compared to D7. Is is possible for us to do a phased sort of migration where we do a form at a time? ...

Using Delphi 7 and Delphi 2010
I had a project in Delphi 7. I worked on it in Delphi 2010. When I try to open the .dpr again in Delphi 7, the IDE toolbar widens across both monitors, and Delphi 7 locks up. It appears that Delphi 2010 modifies the .dpr in a way that makes Delphi 7 unable to open it again. All my forms & units appear to open fine in D7 after D2010, except for the warnings on the ExplicitHeight and ExplicitWidth properties being missing... I can easily recreate the .dpr, but is this expected behavior? Thanks. Tom Field wrote: > I had a project in Delphi 7. > > I worked o...

Delphi 7 to Delphi 2009 conversion
Hello group, What do I need to do to comile the following code in D2009. Compiler error after the Else E2010: Incompatible Types 'AnsiChar' and 'Char' if isUnicode then SearchHandle := FindFirstFilew( PWideChar( fn ), FindDataW ) else SearchHandle := FindFirstFile( PAnsiChar( Ansistring( fn ) ), FindDataA ); <<<<<compiler error in the above line >>>>>>>>>>> Regards, Bryan > What do I need to do to comile the following code in D2009. > Compiler error after the Else > E2010: Incompati...

Migrating from Delphi 7 to Delphi XE3
Hello, Its time to leave the old Delphi 7 and move to the new (but not the latest) XE3. I was wondering if there is a good book or reference to learn all new things XE3 added. Any suggestions? On 5/3/2013 10:17 PM, George Karatsiolis wrote: > Hello, Its time to leave the old Delphi 7 and move to the new (but not the latest) XE3. > I was wondering if there is a good book or reference to learn all new things XE3 added. Try this one for starters: Aside from that you really need to evaluate your application. XE3 is Unicode for example.... So her...

Web resources about - Delphi 7 Copy Array of Byte to Variant [Edit] - embarcadero.delphi.general

Floppy disk variants - Wikipedia, the free encyclopedia
Commodore started its tradition of special disk formats with the 5¼-inch disk drives accompanying its PET/CBM , VIC-20 and Commodore 64 home ...

WARNING: Zbot Trojan Variant Creates Fake Instagram Accounts
The creation and sale of fake likes and followers is not limited to Facebook and Twitter, as RSA reported in a blog post that a variant of the ...

Favorites - Colors of green (mosaic), variant - Flickr - Photo Sharing!
Flickr is almost certainly the best online photo management and sharing application in the world. Show off your favorite photos and videos to ...

1989 Juicy Fruit Commercial - "Skiing" Variant (1991) - YouTube
Here's yet another another entry in Wrigley's Juicy Fruit's then-ubiquitous "THE TASTE IS GOING TO MOVE YOU!" ad campaign. This particular commercial, ...

Bournemouth aside, Arsenal to West Ham all use variants of 4-3-3 - why the formation is thriving
Premier League correspondent Richard Jolly examinesthe rise of the 4-3-3 formation and addresses whether it has played a role in the rise in ...

Gene variant could play central role in Alzheimer's disease
A rare mutation of a gene that’s normally linked to inflammation could triple the risk of Alzheimer’s disease, according to new research from ...

Samsung Galaxy S6 unveiling expected at MWC sans Snapgdragon 810, ‘Active’ variant returning
It's definitely not unexpected by any stretch of the imagination, but Samsung's upcoming Galaxy S6 has been tipped to be introduced at the 2015 ...

Logitech announces wired iPad keyboard for the classroom in Lightning and 30-pin variants
... is a big hassle for teachers, and to combat that it is introducing a plug-and-play, wired keyboard in both Lightning and 30-pin variants : ...

ASRock Goes Braswell: Eight SKUs including DC-In Variants
In the wake of the news regarding ASUS’ listing of their Braswell motherboards, both ASRock and MSI have been quick on their heels to also list ...

AT&T Droid Maxx series variant passes through the FCC
Motorola's Droid Maxx series of devices are well loved for their humongous batteries and well hated for their exclusivity. Thankfully, it looks ...

Resources last updated: 11/26/2015 10:20:07 PM