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,heigh t) ;
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(Send er: TObject);
var
imgstrm:TmemoryStream;
buf:wideString;
begin
buf:=self.ImgSvr.Img[self. Image1.Wid th,self.Im age1.heigh t];
imgstrm:=TmemoryStream.Cre ate;
try
imgStrm.Write(buf[1],lengt h(buf));
imgstrm.seek(0, soFromBeginning);
self.Image1.Picture.Bitmap .LoadFromS tream(imgs trm);
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(Send er: TObject);
var
imgstrm:TmemoryStream;
buf:WideString;
begin
buf:=self.IMG.Img[self.Ima ge1.Width, self.Image 1.height];
imgstrm:=TmemoryStream.Cre ate;
try
imgstrm.Write(Buf[1],len);
imgstrm.Seek(0,soFromBegin ning);
self.Image1.Picture.Bitmap .LoadFromS tream(imgs trm);
finally
imgStrm.Free;
end;
end;
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,heigh
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(Send
var
imgstrm:TmemoryStream;
buf:wideString;
begin
buf:=self.ImgSvr.Img[self.
imgstrm:=TmemoryStream.Cre
try
imgStrm.Write(buf[1],lengt
imgstrm.seek(0, soFromBeginning);
self.Image1.Picture.Bitmap
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(Send
var
imgstrm:TmemoryStream;
buf:WideString;
begin
buf:=self.IMG.Img[self.Ima
imgstrm:=TmemoryStream.Cre
try
imgstrm.Write(Buf[1],len);
imgstrm.Seek(0,soFromBegin
self.Image1.Picture.Bitmap
finally
imgStrm.Free;
end;
end;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
var
i:integer;
buf:WideString;
imgstrm:TmemoryStream;
begin
gisfrm:=unit1.Form1;
imgStrm:= gisfrm.GetImag(width,heigh
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.