
06.12.2010, 15:07
|
 |
Местный
|
|
Регистрация: 04.04.2008
Адрес: Минск
Сообщения: 596
Версия Delphi: 2007 & JAVA EE
Репутация: 10670
|
|
Genry, вроде местный а такую простую программку сделать не можешь...не стыдно?
На форму кидаешь лабел, idhttp(закладка indy client) и кнопку
Код:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, IdBaseComponent, IdComponent, IdTCPConnection,
IdTCPClient, IdHTTP;
type
TForm1 = class(TForm)
IdHTTP1: TIdHTTP;
Button1: TButton;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function GetBefore(substr, str:string):string; //процедура для парсинга
begin
if pos(substr,str)>0 then
result:=copy(str,1,pos(substr,str)-1)
else
result:='';
end;
function GetAfter(substr, str:string):string; //процедура для парсинга
begin
if pos(substr,str)>0 then
result:=copy(str,pos(substr,str)+length(substr),length(str))
else
result:='';
end;
procedure TForm1.Button1Click(Sender: TObject);
var text:string;
time:string;
ST : _SYSTEMTIME;
begin
text:=IdHTTP1.Get('http://www.zln.ru/time/'); //сайт откуда получам время
//парсим страницу
time:=GetBefore('</div>',GetAfter('<div id="servertime" style="margin-top:40px; margin-bottom:30px; height:44px; padding:6px; width:148px; border:2px dotted #990000; font-size:36px; font-weight:bold;">', text));
// убираем всякую хрень
time:=StringReplace(time,#$D#$A#9,'',[rfReplaceAll]);
time:=StringReplace(time,#9,'',[rfReplaceAll]);
label1.Caption:=time;
GetSystemTime(ST); //получаем текущие показатели
st.wHour:= strtoint(copy(time,1,2)); //часы
st.wMinute:=strtoint(copy(time,4,2)); //минуты
st.wSecond:=strtoint(copy(time,7,2)); //секунды
SetSystemTime(ST); //устанавлеваем
end;
end.
__________________
Последний раз редактировалось Admin, Сегодня в 10:32.
|