Have you tried using a standard microsoft Istream interface,
(ActiveX.pas) with a TStreamAdapter object (classes.pas) designed for
in-process com.



-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] On
Behalf Of Vaughan, Benjamin Carl
Sent: Friday, 27 September 2002 11:48 a.m.
To: Multiple recipients of list delphi
Subject: [DUG]: A COM interface for a TStream object


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/

Reply via email to