troubleshooting Question

a image stream problem with Com server in delphi 8

Avatar of jialiangchu
jialiangchu asked on
Delphi
2 Comments1 Solution235 ViewsLast Modified:
i  have completed a com server in delphi 6 with provide a interface for bitmap image stream,the CoClass is

uses
  ComObj, ActiveX, GisSvr_TLB, StdVcl,unit1,Classes;

type
  TIImg = class(TAutoObject, IIImg)
  protected
    gisfrm:TForm1;
    function Get_Img(width, height: Integer): WideString; safecall;
    { Protected declarations }

  end;

implementation

uses ComServ;

function TIImg.Get_Img(width, height: Integer): WideString;
var
  i:integer;
  buf:WideString;
  imgstrm:TmemoryStream;
begin
   gisfrm:=unit1.Form1;
   imgStrm:= gisfrm.GetImag(width,height) ;
   i:=imgStrm.Size;
   setlength(Buf,i);
   imgstrm.seek(0, soFromBeginning);
   imgstrm.Read(buf[1],i);

   //Result:=buf;
   result:=buf;
end;

and i use a client to get image it works Ok,the code is
 
procedure TForm1.GetimgBtnClick(Sender: TObject);
var
  imgstrm:TmemoryStream;
  buf:wideString;
begin
   buf:=self.ImgSvr.Img[self.Image1.Width,self.Image1.height];
   imgstrm:=TmemoryStream.Create;
   try
     imgStrm.Write(buf[1],length(buf));
     imgstrm.seek(0, soFromBeginning);
     self.Image1.Picture.Bitmap.LoadFromStream(imgstrm);
   finally
     imgStrm.Free;
   end;
end;

when i use the com server in delphi 8 ,then Com server can Start ,but when I do
get image ,a error dialog appear ,it show "Invalid paramete used",  why???  thinks

my code in delphi 8 is  

procedure TForm1.GetImgBtnClick(Sender: TObject);
var
  imgstrm:TmemoryStream;
  buf:WideString;
 begin
    buf:=self.IMG.Img[self.Image1.Width,self.Image1.height];
    imgstrm:=TmemoryStream.Create;
  try
     imgstrm.Write(Buf[1],len);
     imgstrm.Seek(0,soFromBeginning);
      self.Image1.Picture.Bitmap.LoadFromStream(imgstrm);
   finally
     imgStrm.Free;
   end;
end;
     
 


     
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 2 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros