Ved ikke om det er kønt, men har selv bikset et eksempel sammen.
I er meget velkommenede til at komme med input og gode idér. :-)
<-------UNIT1 START------->
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, IniFiles, UrlMon, ComCtrls, Gauges, StdCtrls, ExtCtrls, ShellApi,
Buttons, jpeg;
type
TForm1 = class(TForm)
Button1: TButton;
Label1: TLabel;
procedure ChkNewz();
procedure FormCreate(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
winsc: TiniFile;
old: Integer;
vernfo: TIniFile;
end;
var
Form1: TForm1;
Sti, FileName, OldNewz, NewNewz : String;
IniFile : TIniFile;
implementation
Uses Unit2;
{$R *.dfm}
//Download funktion
Function DownloadFile(Source, Dest: string): Boolean;
begin
try
Result := UrlDownloadToFile(nil, PChar(Source), PChar(Dest), 0, nil) = 0;
except
Result := False;
end;
end;
//Tjekker for nye nyheder.
procedure TForm1.ChkNewz();
Var
S : TStringList;
begin
Sti := ExtractFilePath(Application.ExeName);
Form1.Label1.Caption := 'Skaber forbindelse til serveren...';
if DownloadFile('
www.MINHOST.dk/Test/NewNewz.ini', PChar(Sti) + '/NewNewz.ini') then
begin
Form1.Label1.Caption := 'Tjekker for ny version...';
Form1.vernfo.Free;
IniFile := TIniFile.Create(Sti + 'OldNewz.ini');
OldNewz := IntToStr(IniFile.ReadInteger('TJEK', 'OldNewzState', 0)); //Læser Fra Ini Fil.
IniFile := TIniFile.Create(Sti + 'NewNewz.ini');
NewNewz := IntToStr(IniFile.ReadInteger('TJEK', 'NewNewzState', 0)); //Læser Fra Ini Fil.
if (OldNewz = NewNewz) then
Begin
Form1.Label1.Caption := 'Intet Nyt!';
Form1.Button1.Enabled := False;
end
else
begin
Form1.Label1.Caption := 'Der er nyt fra producenten!';
Form1.Button1.Enabled := True;
end;
end
else
begin
Form1.Label1.Caption := 'Kunne ikke skabe forbindelse til serveren!';
Form1.Button1.Enabled := False;
end;
end;
//Form1 OnCreate
procedure TForm1.FormCreate(Sender: TObject);
begin
Form1.ChkNewz();
end;
//Form1 OnActivate
procedure TForm1.FormActivate(Sender: TObject);
begin
Form1.ChkNewz();
end;
//Læs Information - KNAP
procedure TForm1.Button1Click(Sender: TObject);
begin
Sti := ExtractFilePath(Application.ExeName);
Form1.Label1.Caption := 'Skaber forbindelse til serveren...';
if DownloadFile('
www.MINHOST.dk/Test/Newz.txt', PChar(Sti + 'Newz.txt')) then
begin
Form1.Label1.Caption := 'Nyheder hentes.....';
IniFile := TIniFile.Create(Sti + 'OldNewz.ini');
IniFile.WriteInteger('TJEK', 'OldNewzState', StrToInt(NewNewz)); //Skriver til Ini Fil
Form2.Show;
end
else
begin
Form1.Label1.Caption := 'Kunne ikke skabe forbindelse til serveren!';
end;
end;
end.
<-------UNIT1 SLUT------->
<-------UNIT2 START------->
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, IniFiles, UrlMon, ComCtrls, Gauges, StdCtrls, ExtCtrls, ShellApi,
Buttons, jpeg;
type
TForm2 = class(TForm)
Memo1: TMemo;
procedure FormActivate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
Sti : String;
implementation
{$R *.dfm}
//Form2 OnActivate
procedure TForm2.FormActivate(Sender: TObject);
begin
Sti := ExtractFilePath(Application.ExeName);
Memo1.Lines.LoadFromFile(Sti + 'Newz.txt');
end;
end.
<-------UNIT2 SLUT------->