N00bR00T
چهارشنبه 16 اردیبهشت 1394, 09:16 صبح
سلام
من تازه شروع کردم به یادگیری دلفی
یجا گیر کردم
واسه شروع یه کد پیدا کردم که یه فایل رو دانلود میکنه و بعد اجرا میکنه :
unit Unit1;
interface
uses
URLMon, ShellApi, Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function DownloadFile(SourceFile, DestFile: string): Boolean;
begin
try
Result := UrlDownloadToFile(nil, PChar(SourceFile), PChar(DestFile), 0, nil) = 0;
except
Result := False;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
const
SourceFile = 'http://www.google.com/test.zip';
DestFile = 'test.zip';
begin
if DownloadFile(SourceFile, DestFile) then
begin
ShowMessage('Download succesful!');
ShellExecute(Application.Handle, PChar('open'), PChar(DestFile),
PChar(''), nil, SW_NORMAL)
end
else
ShowMessage('Error while Downloading' + SourceFile)
end;
end;
end.
2 تا سوال دارم
اول اینکه چطوری یک پروگرس بار به این دانلودر میشه اضافه کرد ؟
دوم اینکه وقتی فایل دانلود شده رو باز کرد خود دانلودر بسته بشه؟
ممنون میشم راهنمایی کنید
من تازه شروع کردم به یادگیری دلفی
یجا گیر کردم
واسه شروع یه کد پیدا کردم که یه فایل رو دانلود میکنه و بعد اجرا میکنه :
unit Unit1;
interface
uses
URLMon, ShellApi, Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function DownloadFile(SourceFile, DestFile: string): Boolean;
begin
try
Result := UrlDownloadToFile(nil, PChar(SourceFile), PChar(DestFile), 0, nil) = 0;
except
Result := False;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
const
SourceFile = 'http://www.google.com/test.zip';
DestFile = 'test.zip';
begin
if DownloadFile(SourceFile, DestFile) then
begin
ShowMessage('Download succesful!');
ShellExecute(Application.Handle, PChar('open'), PChar(DestFile),
PChar(''), nil, SW_NORMAL)
end
else
ShowMessage('Error while Downloading' + SourceFile)
end;
end;
end.
2 تا سوال دارم
اول اینکه چطوری یک پروگرس بار به این دانلودر میشه اضافه کرد ؟
دوم اینکه وقتی فایل دانلود شده رو باز کرد خود دانلودر بسته بشه؟
ممنون میشم راهنمایی کنید