🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: pl.comp.lang.pascal
Article #92354

Re: [Lazarus] Jak zacząć pracę z LibCurl?

#92354
From: Terrmit
Date: Mon, 31 Dec 2007 10:57
38 lines
2060 bytes
Znalazłem procedurkę, która powinna zapisać stronę html do pliku:

w uses dodałem: LibCurl, unixtype

procedure TForm1.btPobierzClick(Sender: TObject);
var hCurl: pCurl;
     f : TFileStream;
     URL : Pchar = 'http://www.freepascal.org/';
function DoWrite(Ptr: Pointer; Size: size_t; nmemb: size_t; Data: 
Pointer): size_t; cdecl;
begin
   Result:=TStream(Data).Write(Ptr^,Size*nmemb); //błąd
end;

begin
   f:=TFileStream.Create('fpc.html',fmCreate);
   try
     hCurl:= curl_easy_init;
     if Assigned(hCurl) then begin
       curl_easy_setopt(hCurl,CURLOPT_VERBOSE, [True]);
       curl_easy_setopt(hCurl,CURLOPT_URL,[URL]);
       curl_easy_setopt(hCurl,CURLOPT_WRITEFUNCTION,[@DoWrite]);
       curl_easy_setopt(hCurl,CURLOPT_WRITEDATA,[Pointer(f)]);
       curl_easy_perform(hCurl);
       curl_easy_cleanup(hCurl);
     end;
   finally
     f.Free;
   end;
   memo1.Lines.LoadFromFile('fpc.html');
end;

Niestety, plik fpc.html się tworzy, ale nic się do niego nie
zapisuje. Do tego wywala mi błąd, bo Size i nmemb zawierają
chyba jakieś kosmiczne wartości. Nie chwytam, jak to ma działać :/
Pomocy!!!

Sławek
Technical Details
Message-ID: <flaih6$ihu$1@nemesis.news.tpi.pl>
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!newsfeed.gazeta.pl!newsfeed.tpinternet.pl!atlantis.news.tpi.pl!news.tpi.pl!not-for-mail
References: <fl98ib$42g$1@nemesis.news.tpi.pl>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!newsfeed.gazeta.pl!newsfeed.tpinternet.pl!atlantis.news.tpi.pl!news.tpi.pl!not-for-mail
From: Terrmit <terrmitv@poczta.onet.pl>
Newsgroups: pl.comp.lang.pascal
Subject: Re: [Lazarus] Jak zacząć pracę z LibCurl?
Date: Mon, 31 Dec 2007 11:57:51 +0100
Organization: tp.internet - http://www.tpi.pl/
Lines: 38
Message-ID: <flaih6$ihu$1@nemesis.news.tpi.pl>
References: <fl98ib$42g$1@nemesis.news.tpi.pl>
NNTP-Posting-Host: fge166.internetdsl.tpnet.pl
Mime-Version: 1.0
X-Trace: nemesis.news.tpi.pl 1199099238 19006 83.13.160.166 (31 Dec 2007 11:07:18 GMT)
X-Complaints-To: usenet@tpi.pl
NNTP-Posting-Date: Mon, 31 Dec 2007 11:07:18 +0000 (UTC)
User-Agent: Thunderbird 2.0.0.9 (X11/20071115)
In-Reply-To: <fl98ib$42g$1@nemesis.news.tpi.pl>
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit