Link to home
Start Free TrialLog in
Avatar of jialiangchu
jialiangchu

asked on

a image stream problem with Com server in delphi 8

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;
     
 


     
Avatar of Lukasz Zielinski
Lukasz Zielinski
Flag of Poland image

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;


stream to widestring? what if there's #0 byte in stream?
pass memory stream to client instead of widestring.

ziolko.
ASKER CERTIFIED SOLUTION
Avatar of Lukasz Zielinski
Lukasz Zielinski
Flag of Poland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial