Ben, I don't play with OleVariants much but there seems to be something wrong with your handling of Buffer. It is defined as pointer to an OleVariant and then initialised as a pointer to BufSize bytes (which is fine). However you then pass Buffer^ into ReadBuffer so in effect you are passing in the first n (where n is the number of bytes in an OleVariant, probably about 4?) bytes of your buffer as an OleVariant. This is also fine if that is what you want to do but within ReadBuffer you use this parameter as though it is a pointer to a buffer. I think this is wrong as the memory you are playing with is actually the first n bytes of the buffer, not a pointer to the buffer.
However as I said OleVariants are a bit of a mystery to me and there may automatic dereferences happening here (such as with the Var parameter) which aren't apparent to me. HTH, David. > > Hi All, > > I am attempting to write a COM interface for the TStream object, but I am > currently running into a problem. The current issue that I am > facing is with > my CopyFrom method which I have pasted below. > > The problem that I have is that when the method completes it raises an > access violation (basically right on the 'end;' line). I can however > confirm that the copying of the stream does occur successfully. > > If anyone has any ideas on what is wrong with my CopyFrom method > any help is > appreciated. I also found if I don't call the > "Source.ReadBuffer(Buffer^, N);" line the error will not occur. > > Ben Vaughan > ================================ > Systems Architect > Business Education Online > University of Auckland > ================================ > Old Choral Hall, 7 Symonds St, Auckland > (P) +64 9 3737599 x2514 (F) +64 9 3737430 > > > function TMyStream.CopyFrom(const Source: IMyStream; Count: Integer): > Integer; > const > MaxBufSize = $F000; > var > BufSize, N: Integer; > Buffer: POleVariant1; > begin > if Count = 0 then > begin > Source.Position := 0; > Count := Source.Size; > end; > Result := Count; > if Count > MaxBufSize then BufSize := MaxBufSize else BufSize := Count; > GetMem(Buffer, BufSize); > try > while Count <> 0 do > begin > if Count > BufSize then N := BufSize else N := Count; > Source.ReadBuffer(Buffer^, N); > WriteBuffer(Buffer^, N); > Dec(Count, N); > end; > finally > FreeMem(Buffer, BufSize); > end; > end; > > procedure TMyStream.ReadBuffer(var Buffer: OleVariant; Count: Integer); > begin > fStream.ReadBuffer(Buffer,Count); > end; > > procedure TMyStream.WriteBuffer(var Buffer: OleVariant; Count: Integer); > begin > fStream.WriteBuffer(Buffer,Count); > end; > > ------------------------------------------------------------------ > --------- > New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED] > Website: http://www.delphi.org.nz > To UnSub, send email to: [EMAIL PROTECTED] > with body of "unsubscribe delphi" > Web Archive at: http://www.mail-archive.com/delphi%40delphi.org.nz/ --------------------------------------------------------------------------- New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED] Website: http://www.delphi.org.nz To UnSub, send email to: [EMAIL PROTECTED] with body of "unsubscribe delphi" Web Archive at: http://www.mail-archive.com/delphi%40delphi.org.nz/