错在哪?(35分)

松子

Unregistered / Unconfirmed
GUEST, unregistred user!
procedure screencap(leftpos,toppos,rightpos,bottompos:integer);
var
rectwidth,rectheight:integer;
sourcedc,destdc,bhandle:integer;
bitmap:Tbitmap;
jp:Tjpegimage;
begin
rectwidth:=rightpos-leftpos;
rectheight:=bottompos-toppos;
sourcedc:=createdc('DISPLAY','','',nil);
destdc:=createcompatibledc(sourcedc);
bhandle:=createcompatiblebitmap(sourcedc,rectwidth,rectheight);
selectobject(destdc,bhandle);
bitblt(destdc,0,0,rectwidth,rectheight,sourcedc,leftpos,toppos,srccopy);
bitmap:=Tbitmap.create;
bitmap.handle:=bhandle;
jp:=Tjpegimage.create;
jp.assign(bitmap);
bmpstream:=TMemoryStream.Create;
jp.SaveToStream(bmpstream); //报错
bmpstream.position:=0;
leftsize:=bmpstream.size;
bitmap.free;
jp.Free;
deletedc(destdc);
releasedc(bhandle,sourcedc);
end;
请问,错在哪?
 
请把错误代码一并给出
 
错误是这样的:

raised exception class EoutofResources with message '参数错误'.process stopped.
use step or run to continue.

这是什么原因造成的.我正在做一个远程截屏的程序,可我发现经常会报错,我认为可能是
bmp太大,所以想把它改为jpg,结果报这个错误,请大家帮忙.可惜我水平低,分不多,只有
最后35分了.
 
呵呵,占用资源过多导致的不定期错误。
尝试尽量使用动态创建窗体,用完后就关闭。
对于Query等,也需要尽量少用,用完就Close。
还有一些别的。。。。
反正是节约资源。
 
to yzhshi:
能告诉我上面的程序为什么会错,这不是占用资源过多导致的,而是每次运行都错!
 
噢?每次都出错?
呀,那应该是程序问题了,俺看看。。。
 
顶部