Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I've done this many times in vb.net and thought I had it working in Delphi but I'm stuck. I'm using Delphi 10.2.

I'm reading a PDF file into a memory stream and then converting it to a byte array so I can store it in an MS SQL file table.

I can't use TByteArray because most of the PDF's my client will deal with are far too large for the size limit of TByteArray.

What I have tried:

Pascal
var
  msDoc: TMemoryStream;
  baDoc: array of byte;

begin

     msDoc := TMemoryStream.Create;
     msDoc.LoadFromFile(fPath + fName + '.pdf');
     SetLength(baDoc, msDoc.Size);
     msDoc.Read(baDoc, Length(baDoc)); // crashes here with no useful information


SetLength seems to work fine. When I check the length of baDoc in a watch it's the same size as msDoc.


In the same batch of code I'm working on I'm also trying to pass baDoc to another form. I've set a public varibable in the other form to "array of byte" but that won't even compile. I get an "incompatible types" error.

In the other form:

Pascal
public
    ADocumentByteArray: array of byte;


And in the form that's doing the passing:

Pascal
ADocumentByteArray := baDoc;


I guess that's 2 questions but they are sort of related. When I use TByteArray I can pass the value just fine between the 2 forms but again it doesn't have the capacity for my needs.

Hope someone can help!

Thanks,

Keith
Posted
Updated 13-Apr-22 6:15am

1 solution

Well never mind I guess. On a whim I decided to just use TBytes and the whole solution works now.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900