<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Sinkro.net &#187; wsdl</title>
	<atom:link href="http://www.sinkro.net/tag/wsdl/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.sinkro.net</link>
	<description>Software e dintorni. ... soprattutto dintorni ;-)</description>
	<lastBuildDate>Mon, 26 Sep 2011 01:42:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Come utilizzare google da delphi</title>
		<link>http://www.sinkro.net/2006/07/23/usare-google-da-delphi/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=usare-google-da-delphi</link>
		<comments>http://www.sinkro.net/2006/07/23/usare-google-da-delphi/#comments</comments>
		<pubDate>Sun, 23 Jul 2006 14:02:58 +0000</pubDate>
		<dc:creator>Massimiliano</dc:creator>
				<category><![CDATA[Codice]]></category>
		<category><![CDATA[delphi]]></category>
		<category><![CDATA[gmap]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[maps]]></category>
		<category><![CDATA[wsdl]]></category>

		<guid isPermaLink="false">http://www.sinkro.net/2006/07/23/usare-google-da-delphi/</guid>
		<description><![CDATA[Come primo passo Ã¨ necessario ottenere una google api key per poter utilizzare il WebService che Google ci mette a disposizione. La si puÃ² ottenere qui http://google.com/apis/. Una volta registrati si otterra' la key via email. In delphi 7 e successivi c'e' un utile strumento, wsdl importer che importa i wsdl e ci crea un [...]


Altri articoli di interesse:<ol><li><a href='http://www.sinkro.net/2006/07/22/come-aggiungere-google-maps-in-una-pagina-web/' rel='bookmark' title='Come aggiungere google maps in una pagina web'>Come aggiungere google maps in una pagina web</a> <small>Questa cosa e' facile facile e di sicuro effetto. La...</small></li>
<li><a href='http://www.sinkro.net/2004/02/03/inviare-fax-tramite-microsoft-faxserver-con-delphi/' rel='bookmark' title='Inviare fax tramite Microsoft FaxServer con delphi'>Inviare fax tramite Microsoft FaxServer con delphi</a> <small>uses ComObj; procedure TForm1.Button1Click&#40;Sender: TObject&#41;; var &nbsp; mFax,mFaxDoc: Variant; begin...</small></li>
<li><a href='http://www.sinkro.net/2008/01/29/attenti-a-google-map/' rel='bookmark' title='Attenti a Google map'>Attenti a Google map</a> <small>Credo conosciate già la vista stradale delle maps di google....</small></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Come primo passo Ã¨ necessario ottenere una google api key per poter utilizzare il WebService che Google ci mette a disposizione.<br />
La si puÃ² ottenere qui <a href="http://www.google.com/apis/">http://google.com/apis/</a>.</p>
<p>Una volta registrati si otterra' la key via email.</p>
<p>In delphi 7 e successivi c'e' un utile strumento, wsdl importer che importa i wsdl e ci crea un file di interfaccia verso gli oggetti messi a disposizione dal webservice.</p>
<p>Usarlo Ã¨ piuttosto semplice:<br />
Entriamo in delphi e dal menu<br />
<em>file-&gt;new-&gt;other </em><br />
scegliamo<br />
<em>webservices-&gt;wsdl importer</em></p>
<p>Impostiamo l'url del wsdl in <em>http://api.google.com/GoogleSearch.wsdl</em></p>
<p>Clicchiamo Next e poi Finish.</p>
<p>Nell'editor si aprira' automaticamente il file GoogleSearch.pas.</p>
<p><span id="more-42"></span></p>
<p>In questo file troveremo, tra le altre cose, la definizione della classe <em>GoogleSearchPort</em></p>
<p>La definizione:</p>
<div class="syntax_hilite">
<div id="delphi-22">
<div class="delphi">GoogleSearchPort = <span style="color: #000000; font-weight: bold;">interface</span><span style="color: #66cc66;">&#40;</span>IInvokable<span style="color: #66cc66;">&#41;</span><br />
<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'{0B396A82-A4DD-69A7-A771-6D80F8831A71}'</span><span style="color: #66cc66;">&#93;</span><br />
<span style="color: #000000; font-weight: bold;">function</span> doGetCachedPage<span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">const</span> key: <span style="color: #993333;">WideString</span>; <span style="color: #000000; font-weight: bold;">const</span> url: <span style="color: #993333;">WideString</span><span style="color: #66cc66;">&#41;</span>: TByteDynArray; <span style="color: #000000; font-weight: bold;">stdcall</span>;<br />
<span style="color: #000000; font-weight: bold;">function</span> doSpellingSuggestion<span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">const</span> key: <span style="color: #993333;">WideString</span>; <span style="color: #000000; font-weight: bold;">const</span> phrase: <span style="color: #993333;">WideString</span><span style="color: #66cc66;">&#41;</span>: <span style="color: #993333;">WideString</span>; <span style="color: #000000; font-weight: bold;">stdcall</span>;<br />
<span style="color: #000000; font-weight: bold;">function</span> doGoogleSearch<span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">const</span> key: <span style="color: #993333;">WideString</span>; <span style="color: #000000; font-weight: bold;">const</span> q: <span style="color: #993333;">WideString</span>; <span style="color: #000000; font-weight: bold;">const</span> start: <span style="color: #993333;">Integer</span>; <span style="color: #000000; font-weight: bold;">const</span> maxResults: <span style="color: #993333;">Integer</span>; <span style="color: #000000; font-weight: bold;">const</span> filter: <span style="color: #993333;">Boolean</span>; <span style="color: #000000; font-weight: bold;">const</span> restrict: <span style="color: #993333;">WideString</span>; <span style="color: #000000; font-weight: bold;">const</span> safeSearch: <span style="color: #993333;">Boolean</span>; <span style="color: #000000; font-weight: bold;">const</span> lr: <span style="color: #993333;">WideString</span>; <span style="color: #000000; font-weight: bold;">const</span> ie: <span style="color: #993333;">WideString</span>; <span style="color: #000000; font-weight: bold;">const</span> oe: <span style="color: #993333;">WideString</span><br />
<span style="color: #66cc66;">&#41;</span>: GoogleSearchResult; <span style="color: #000000; font-weight: bold;">stdcall</span>;<br />
<span style="color: #000000; font-weight: bold;">end</span>;</div>
</div>
</div>
<p></p>
<p>Notare i tre metodi che Google ci mette a disposizione:</p>
<ul>
<li>doGetCachedPage</li>
<li>doSpellingSuggestion</li>
<li>doGoogleSearch</li>
</ul>
<p>Per testarli ho creato una form con un TEdit, un TMemo ed un TButton.<br />
APIKEY rappresenta la key che ci ha fornito Google per poter utilizzare il WebService.</p>
<p>Proviamo i metodi uno ad uno.</p>
<p><em><strong>doGetCachedPage</strong></em></p>
<p><em>doGetCachedPage</em> restituisce un TByteDynArray che troviamo nella unit types.</p>
<p>Quindi:</p>
<div class="syntax_hilite">
<div id="delphi-23">
<div class="delphi"><span style="color: #000000; font-weight: bold;">uses</span><br />
GoogleSearch<br />
, Types;</div>
</div>
</div>
<p></p>
<p>CiÃ² che segue Ã¨ come potrebbe essere una semplice funzione che usa il metodo <em>doGetCachedPage</em>:</p>
<div class="syntax_hilite">
<div id="delphi-24">
<div class="delphi"><span style="color: #000000; font-weight: bold;">var</span><br />
googleResult : TByteDynArray;<br />
google : GoogleSearchPort;<br />
mPage : <span style="color: #993333;">string</span>;<br />
i : <span style="color: #993333;">integer</span>;<br />
<span style="color: #000000; font-weight: bold;">begin</span><br />
google := GetGoogleSearchPort<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
googleResult := google.<span style="color: #006600;">doGetCachedPage</span><span style="color: #66cc66;">&#40;</span>APIKEY, edit1.<span style="color: #006600;">Text</span><span style="color: #66cc66;">&#41;</span>;</p>
<p>mPage := <span style="color: #ff0000;">''</span>;<br />
<span style="color: #000000; font-weight: bold;">for</span> i := <span style="color: #cc66cc;">0</span> <span style="color: #000000; font-weight: bold;">to</span> <span style="color: #000066;">length</span><span style="color: #66cc66;">&#40;</span>googleResult<span style="color: #66cc66;">&#41;</span> - <span style="color: #cc66cc;">1</span> <span style="color: #000000; font-weight: bold;">do</span><br />
<span style="color: #000000; font-weight: bold;">begin</span><br />
mPage := mPage + <span style="color: #993333;">char</span><span style="color: #66cc66;">&#40;</span>googleResult<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #000000; font-weight: bold;">end</span>;<br />
Memo1.<span style="color: #006600;">Lines</span>.<span style="color: #006600;">Text</span> := mPage;<br />
<span style="color: #000000; font-weight: bold;">end</span>;</div>
</div>
</div>
<p></p>
<p><em><strong>doSpellingSuggestion</strong></em></p>
<p><em>doSpellingSuggestion</em> Ã¨ il metodo piÃ¹ semplice dato che restituisce una semplice <em>widestring</em>.</p>
<div class="syntax_hilite">
<div id="delphi-25">
<div class="delphi"><span style="color: #000000; font-weight: bold;">var</span><br />
google : GoogleSearchPort;<br />
mWord : <span style="color: #993333;">string</span>;<br />
<span style="color: #000000; font-weight: bold;">begin</span><br />
google := GetGoogleSearchPort<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
mWord := google.<span style="color: #006600;">doSpellingSuggestion</span><span style="color: #66cc66;">&#40;</span>APIKEY, edit1.<span style="color: #006600;">Text</span><span style="color: #66cc66;">&#41;</span>;</p>
<p>Memo1.<span style="color: #006600;">Clear</span>;<br />
memo1.<span style="color: #006600;">Lines</span>.<span style="color: #006600;">Add</span><span style="color: #66cc66;">&#40;</span>mWord<span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #000000; font-weight: bold;">end</span>;</div>
</div>
</div>
<p></p>
<p><em><strong>doGoogleSearch</strong></em></p>
<p><em>doGoogleSearch</em> Ã¨ il metodo che ci permette di effettuare ricerche.</p>
<p>Richiede questi parametri:</p>
<ul>
<li><strong>key</strong> <em>Google Api key</em></li>
<li><strong>q</strong> <em>Il testo che stiamo cercando</em></li>
<li><strong>start</strong> <em>Da quale risultato partiamo</em></li>
<li><strong>maxResults</strong> <em>Quanti risultati volgiamo</em></li>
<li><strong>filter</strong> <em>Filtrare i risultati simili</em></li>
<li><strong>restrict</strong> <em>Restrizione di nazione o argomento</em></li>
<li><strong>safeSearch</strong> <em>filtro pornografia</em></li>
<li><strong>lr</strong> <em>restrizione di lingua</em></li>
<li><strong>ie</strong> <em>input encoding</em></li>
<li><strong>oe</strong> <em>output encoding</em></li>
</ul>
<p>nessuno dei quali e' opzionale.</p>
<p><em>doGoogleSearch</em> restituisce un oggetto di tipo <em>GoogleSearchResult</em> anch'esso definito nel wsdl e di conseguenza nel nostro GoogleSearch.pas generato automaticamente da <em>wsdl importer</em>.</p>
<p>Questa la dichiarazione:</p>
<div class="syntax_hilite">
<div id="delphi-26">
<div class="delphi">GoogleSearchResult = <span style="color: #000000; font-weight: bold;">class</span><span style="color: #66cc66;">&#40;</span>TRemotable<span style="color: #66cc66;">&#41;</span><br />
...<br />
<span style="color: #000000; font-weight: bold;">published</span><br />
<span style="color: #000000; font-weight: bold;">property</span> documentFiltering: <span style="color: #993333;">Boolean</span>;<br />
<span style="color: #000000; font-weight: bold;">property</span> searchComments: <span style="color: #993333;">WideString</span>;<br />
<span style="color: #000000; font-weight: bold;">property</span> estimatedTotalResultsCount: <span style="color: #993333;">Integer</span>;<br />
<span style="color: #000000; font-weight: bold;">property</span> estimateIsExact: <span style="color: #993333;">Boolean</span>;<br />
<span style="color: #000000; font-weight: bold;">property</span> resultElements: ResultElementArray;<br />
<span style="color: #000000; font-weight: bold;">property</span> searchQuery: <span style="color: #993333;">WideString</span>;<br />
<span style="color: #000000; font-weight: bold;">property</span> startIndex: <span style="color: #993333;">Integer</span>;<br />
<span style="color: #000000; font-weight: bold;">property</span> endIndex: <span style="color: #993333;">Integer</span>;<br />
<span style="color: #000000; font-weight: bold;">property</span> searchTips: <span style="color: #993333;">WideString</span>;<br />
<span style="color: #000000; font-weight: bold;">property</span> directoryCategories: DirectoryCategoryArray;<br />
<span style="color: #000000; font-weight: bold;">property</span> searchTime: <span style="color: #993333;">Double</span>;<br />
<span style="color: #000000; font-weight: bold;">end</span>;</div>
</div>
</div>
<p></p>
<p>Un altro oggetto importante Ã¨ <em>ResultElement</em>, ovvero ogni singolo risultato della ricerca. La dichiarazione:</p>
<div class="syntax_hilite">
<div id="delphi-27">
<div class="delphi">ResultElement = <span style="color: #000000; font-weight: bold;">class</span><span style="color: #66cc66;">&#40;</span>TRemotable<span style="color: #66cc66;">&#41;</span><br />
...<br />
<span style="color: #000000; font-weight: bold;">published</span><br />
<span style="color: #000000; font-weight: bold;">property</span> summary: <span style="color: #993333;">WideString</span>;<br />
<span style="color: #000000; font-weight: bold;">property</span> URL: <span style="color: #993333;">WideString</span>;<br />
<span style="color: #000000; font-weight: bold;">property</span> snippet: <span style="color: #993333;">WideString</span>;<br />
<span style="color: #000000; font-weight: bold;">property</span> title: <span style="color: #993333;">WideString</span>;<br />
<span style="color: #000000; font-weight: bold;">property</span> cachedSize: <span style="color: #993333;">WideString</span>;<br />
<span style="color: #000000; font-weight: bold;">property</span> relatedInformationPresent: <span style="color: #993333;">Boolean</span>;<br />
<span style="color: #000000; font-weight: bold;">property</span> hostName: <span style="color: #993333;">WideString</span>;<br />
<span style="color: #000000; font-weight: bold;">property</span> directoryCategory: DirectoryCategory;<br />
<span style="color: #000000; font-weight: bold;">property</span> directoryTitle: <span style="color: #993333;">WideString</span>;<br />
<span style="color: #000000; font-weight: bold;">end</span>;</div>
</div>
</div>
<p></p>
<p>Vediamo un po' come possiamo implementare una semplice ricerca:</p>
<div class="syntax_hilite">
<div id="delphi-28">
<div class="delphi"><span style="color: #000000; font-weight: bold;">var</span><br />
googleResult : GoogleSearchResult;<br />
google : GoogleSearchPort;<br />
i : <span style="color: #993333;">integer</span>;<br />
<span style="color: #000000; font-weight: bold;">begin</span><br />
google := GetGoogleSearchPort<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
googleResult := google.<span style="color: #006600;">doGoogleSearch</span><span style="color: #66cc66;">&#40;</span><br />
APIKEY, Edit1.<span style="color: #006600;">Text</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">10</span>, <span style="color: #000000; font-weight: bold;">False</span>, <span style="color: #ff0000;">''</span>, <span style="color: #000000; font-weight: bold;">False</span>, <span style="color: #ff0000;">''</span>, <span style="color: #ff0000;">''</span>, <span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span>;</p>
<p>Memo1.<span style="color: #006600;">Clear</span>;</p>
<p>Memo1.<span style="color: #006600;">Lines</span>.<span style="color: #006600;">Add</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Trovati '</span> + <span style="color: #000066;">IntToStr</span><span style="color: #66cc66;">&#40;</span>googleResult.<span style="color: #006600;">estimatedTotalResultsCount</span><span style="color: #66cc66;">&#41;</span> + <span style="color: #ff0000;">' risultati:'</span>;<br />
Memo1.<span style="color: #006600;">Lines</span>.<span style="color: #006600;">Add</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #000000; font-weight: bold;">for</span> i := <span style="color: #000066;">Low</span><span style="color: #66cc66;">&#40;</span>googleResult.<span style="color: #006600;">resultElements</span><span style="color: #66cc66;">&#41;</span> <span style="color: #000000; font-weight: bold;">to</span> <span style="color: #000066;">High</span><span style="color: #66cc66;">&#40;</span>googleResult.<span style="color: #006600;">resultElements</span><span style="color: #66cc66;">&#41;</span> <span style="color: #000000; font-weight: bold;">do</span><br />
<span style="color: #000000; font-weight: bold;">begin</span><br />
Memo1.<span style="color: #006600;">Lines</span>.<span style="color: #006600;">Add</span><span style="color: #66cc66;">&#40;</span><span style="color: #000066;">IntToStr</span><span style="color: #66cc66;">&#40;</span>i + <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;<br />
Memo1.<span style="color: #006600;">Lines</span>.<span style="color: #006600;">Add</span><span style="color: #66cc66;">&#40;</span>googleResult.<span style="color: #006600;">resultElements</span><span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">title</span><span style="color: #66cc66;">&#41;</span>;<br />
Memo1.<span style="color: #006600;">Lines</span>.<span style="color: #006600;">Add</span><span style="color: #66cc66;">&#40;</span>googleResult.<span style="color: #006600;">resultElements</span><span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">URL</span><span style="color: #66cc66;">&#41;</span>;<br />
Memo1.<span style="color: #006600;">Lines</span>.<span style="color: #006600;">Add</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #000000; font-weight: bold;">end</span>;<br />
<span style="color: #000000; font-weight: bold;">end</span>;</div>
</div>
</div>
<p></p>
<p>Allego un progettino di esempio dove ho cercato di utilizzare tutte le proprietÃ  disponibili di <em>GoogleSearchResult</em> e di <em>ResultElement</em>:<br />
<a id="p43" href="http://www.sinkro.net/wp-content/uploads/2006/07/TestGoogleSearch.zip">TestGoogleSearch</a></p>


<p>Altri articoli di interesse:<ol><li><a href='http://www.sinkro.net/2006/07/22/come-aggiungere-google-maps-in-una-pagina-web/' rel='bookmark' title='Come aggiungere google maps in una pagina web'>Come aggiungere google maps in una pagina web</a> <small>Questa cosa e' facile facile e di sicuro effetto. La...</small></li>
<li><a href='http://www.sinkro.net/2004/02/03/inviare-fax-tramite-microsoft-faxserver-con-delphi/' rel='bookmark' title='Inviare fax tramite Microsoft FaxServer con delphi'>Inviare fax tramite Microsoft FaxServer con delphi</a> <small>uses ComObj; procedure TForm1.Button1Click&#40;Sender: TObject&#41;; var &nbsp; mFax,mFaxDoc: Variant; begin...</small></li>
<li><a href='http://www.sinkro.net/2008/01/29/attenti-a-google-map/' rel='bookmark' title='Attenti a Google map'>Attenti a Google map</a> <small>Credo conosciate già la vista stradale delle maps di google....</small></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.sinkro.net/2006/07/23/usare-google-da-delphi/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

