Top.Mail.Ru
Мастера DELPHI, Delphi programming community Титульная страница Поиск, карта сайта Написать письмо 
| Новости | Поиск | FAQ | Статьи | Книги | Новости VCL |
| Форумы ЧАТ | Орешник | KOL и MCK |
Форумы -» Основная («Начинающим»)/ Базы / WinAPI / Компоненты / Сети / Media / Игры / Corba и COM / KOL / FreePascal / .Net / Прочее / RSDN.ORG

« предыдущая ветвь | форум | следующая ветвь »

Файл занят другим процессом. [D7, XP]


HF-Trade ©   (2009-04-19 14:45:00) 

Помогие мне а?=)

Function Recognize(FileName: string; APIkey: string; is_phrase: Boolean; is_regsense: Boolean; is_numeric: Boolean; min_len: integer; max_len: integer): string;
Var
Ftype,tmpstr,captcha_id: String;
I:Integer;
http: TIdHTTP;
multi: TIdMultiPartFormDataStream;
begin
if FileExists(filename)=false then begin result:='ERROR: file not found'; exit; end;

ftype:='image/pjpeg';
if strpos(Pchar(filename),'jpg')nil then ftype:='image/pjpeg';
if strpos(Pchar(filename),'gif')nil then ftype:='image/gif';
if strpos(Pchar(filename),'png')nil then ftype:='image/png';

multi:=Tidmultipartformdatastream.Create;
multi.AddFormField('method','post');
multi.AddFormField('key',apikey);
multi.AddFile('file',filename,ftype);
if is_phrase=true then multi.AddFormField('phrase','1');
if is_regsense=true then multi.AddFormField('regsense','1');
if is_numeric=true then multi.AddFormField('numeric','1');
if min_len>0 then multi.AddFormField('min_len',inttostr(min_len));
if max_len>0 then multi.AddFormField('max_len',inttostr(max_len));

http:=TIdHTTP.Create(nil);
tmpstr:=http.Post(' http://anti-captcha.com/in.php',multi);
http.Free;
captcha_id:='';
if strpos(Pchar(tmpstr),'ERROR_')nil then
begin
result:=tmpstr;
exit;
end;
if strpos(Pchar(tmpstr),'OK|')nil then
captcha_id:=AnsiReplaceStr(tmpstr,'OK|','');
if captcha_id='' then
result:='ERROR: bad captcha id';
for i:=0 to 20 do
 begin
 Application.ProcessMessages;
 sleep(5000);
 http:=TIdHttp.Create(nil);
 tmpstr:=http.Get(' http://anti-captcha.com/res.php?key='+apikey+'&action=get&id='+captcha_id);
 http.Free;
 if strpos(Pchar(tmpstr),'ERROR_')nil then
 begin result:=tmpstr; exit; end;
 if strpos(Pchar(tmpstr),'OK|')nil then
   begin
   result:=AnsiReplaceStr(tmpstr,'OK|','');
   exit;
   end;
 Application.ProcessMessages;
 end;
Result:='ERROR_TIMEOUT';

end;

procedure TForm1.Button1Click(Sender: TObject);
var
tmpParams:TStringList;
Captcha:TMemoryStream;
...........
...........
begin
rsltedit.Text:='recognizing...';
tmpList.Clear;
Button1.Enabled:=false;

tmpParams:=TStringList.Create;
tmpParams.Add('login='+Login);
tmpParams.Add('firstname='+FistName);
tmpParams.Add('lastname='+LastName);

tmpList.Items.Text:=IdHTTP1.Post(урл,tmpParams);

tmpParams.Add(еще параметры);

Captcha:= TMemoryStream.Create;
idHTTP1.Get('урл',Captcha);
Captcha.SaveToFile(MyDir+'image.jpg');
Captcha.Destroy;

token:=recognize(MyDir+'image.jpg',apikeyedit.Text,false,false,false,0,0);

mpParams.Add('kapcha'+Token);

tmpList.Items.Text:=IdHTTP1.Post('урл',tmpParams);

tmpList.Items.SaveToFile(MyDir+'tpm.htm');

tmpParams.Free;

Button1.Enabled:=true;
end;

Первый раз все норм, на второй, вот тут ошибка- говорит что файл занят -
idHTTP1.Get('урл',Captcha);
Captcha.SaveToFile(MyDir+'image.jpg');
^^^^^^^^^^^^


Anatoly Podgoretsky   (2009-04-19 17:53:00) [1]

> Palladin  (19.04.2009 14:49:01)  [1]

До увольнения.


HF-Trade   (2009-04-19 14:57:00) [2]

вопрос снят))
Не везде free вставил))))


HF-Trade   (2009-04-19 14:53:00) [3]


> безобразный код... уволен.

Функция взята как есть с сайта антикапчи....


HF-Trade   (2009-04-19 14:51:00) [4]

пробовал я и multi.free нифига...


Palladin   (2009-04-19 14:49:00) [5]

безобразный код... уволен.
а multi нужно все таки освободить. Пушкина на всех не хватит.


Наверх

Титульная страница Поиск, карта сайта Написать письмо