24-02-2022, Saat: 23:05
Size bir kolaylık.
* Indy kullanmadan SSL desteği : ( örnekte dolar kuru okunur ve ekrana mesaj olarak gösterilir )
* Parse örnek için el yordamıyla yapıldı. XML node name/value olarak okumak daha sağlıklı olur.
Kullanımı :
* Indy kullanmadan SSL desteği : ( örnekte dolar kuru okunur ve ekrana mesaj olarak gösterilir )
* Parse örnek için el yordamıyla yapıldı. XML node name/value olarak okumak daha sağlıklı olur.
Uses WinInet; function GetUrlSource( aUrl : String; aStream: TStringStream ): Boolean; var hService : HINTERNET; hSession : HINTERNET; lpBuffer : array[0..1023] of Byte; dwBytesRead : DWORD; dwBytesAvail : DWORD; dwTimeOut : DWORD; Sessionname : String; begin Result := False; if NOT Assigned(aStream) then exit; Sessionname := 'TCMB_Session_' + DateTimeToStr(now); hSession := InternetOpen( PChar(Sessionname), INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0 ); if not Assigned(hSession) then Exit; try hService := InternetOpenUrl(hSession, PChar(aUrl), nil, 0, INTERNET_FLAG_RELOAD, 0); if hService = nil then Exit; try dwTimeOut := 60000; // a minute InternetSetOption(hService, INTERNET_OPTION_RECEIVE_TIMEOUT, @dwTimeOut, SizeOf(dwTimeOut)); if InternetQueryDataAvailable(hService, dwBytesAvail, 0, 0) then while ( InternetReadFile(hService, @lpBuffer[0], SizeOf(lpBuffer), dwBytesRead) ) and ( dwBytesRead <> 0 ) do aStream.WriteBuffer(lpBuffer[0], dwBytesRead); aStream.Position := 0; // ready to use Result := aStream.Size > 0; finally InternetCloseHandle(hService); end; finally InternetCloseHandle(hSession); end; end;
Kullanımı :
procedure TForm1.Button1Click(Sender: TObject);
Const
LUrl = 'https://www.tcmb.gov.tr/kurlar/today.xml';
var
LContent : String;
LSS : TStringStream;
LSrc,
LBanknoteBuying,
LBanknoteSelling : String;
begin
LSS := TStringStream.Create('');
try
GetUrlSource( LUrl, LSS );
LContent := LSS.DataString;
LSrc := 'CurrencyCode="USD">';
if Pos(LSrc, LContent) > 0 then
begin
Delete(LContent, 1, Pos(LSrc, LContent) + Length(LSrc)-1);
LContent := Copy( LContent, 1, Pos('</Currency>', LContent)-1);
LSrc := '<BanknoteBuying>';
if Pos(LSrc, LContent) > 0 then
begin
Delete(LContent, 1, Pos(LSrc, LContent) + Length(LSrc)-1);
LBanknoteBuying := Copy(LContent, 1, Pos('<', LContent)-1 );
end;
LSrc := '<BanknoteSelling>';
if Pos(LSrc, LContent) > 0 then
begin
Delete(LContent, 1, Pos(LSrc, LContent) + Length(LSrc)-1);
LBanknoteSelling := Copy(LContent, 1, Pos('<', LContent)-1 );
end;
ShowmessageFmt('USD Alış : %s Satış : %s', [ LBanknoteBuying, LBanknoteSelling ]);
end;
finally
FreeAndNil(LSS);
end;
end;
Saygılarımla
Muharrem ARMAN

Muharrem ARMAN


