Einzelnen Beitrag anzeigen

Admirandis
(Gast)

n/a Beiträge
 
#20

Re: Office-Objekte übers Internet verschicken

  Alt 22. Nov 2008, 14:33
Servus!

Ich hab jetzt nochmal versucht nach besten Gewissen die ganzen FTP Zugriffe in einen eignen Thread auszulagern. Blöderweise geht es immer noch nicht -.-

Hier mal der Code von der Main:
Delphi-Quellcode:
unit Office_Clipper;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, MyFTP, ExtCtrls, JvExControls, JvXPCore, JvXPButtons, JvLED, StdCtrls;

type
  TForm1 = class(TForm)
    ConnectButton: TJvXPButton;
    updatetimer: TTimer;
    Connectedled: TJvLED;
    FileBox: TListBox;
    procedure updatetimerTimer(Sender: TObject);
    procedure ConnectButtonClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;
   connected: boolean;
    ftp: TMyFTP;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
ftp := TMyFTP.create;

ftp.set_host('myserver.de');
ftp.set_user('myuser');
ftp.set_password('mypassword');

end;

procedure TForm1.ConnectButtonClick(Sender: TObject);
begin
if ftp.connect = false then
      showmessage('Fehler beim Erstellen der Verbindung!')
  else
    begin
      ftp.set_directory('mydirectory');
      updatetimer.Enabled := true;
    end;
end;

procedure TForm1.updatetimerTimer(Sender: TObject);
begin

connected := ftp.get_state;

if connected = true then
    begin
      ConnectedLED.Status := true;
      ConnectedLED.Active := false;
      ftp.get_list(FileBox);
    end
  else
    begin
      ConnectedLED.Status := false;
      ConnectedLED.Active := true;
    end;

end;

end.
und hier noch der Code von meinem FTP-Thread:
Delphi-Quellcode:

unit MyFTP;

interface

uses Windows, SysUtils, Classes, Dialogs, IdFTP, Variants, StdCtrls;

type
TMyFTP = class(TThread)
  private
    filename, host, user, password, directory: string;

  protected
    procedure execute; override;

  public
    constructor create; virtual;

    procedure upload;
    procedure download;

    procedure set_host(aHost: string);
    procedure set_user(aUser: string);
    procedure set_password(aPassword: string);
    procedure set_directory(aDirectory: string);

    function connect: boolean;
    function get_state: boolean;
    procedure get_list(aListbox: TListbox);

  end;

var
 ftp: TidFTP;

implementation

///////////////////// FTP - THREAD ////////////////////////

//Creation///
procedure TMyFTP.Execute;
begin
 while not Terminated do
        WaitFor;

 if Terminated then
    ftp.Free;
end;

constructor TMyFTP.create;
begin
  inherited create(true);
  freeOnTerminate := true;
  ftp := TIdFTP.Create(nil);
end;
///



//Up- and Download///
procedure TMyFTP.upload;
begin

end;

procedure TMyFTP.download;
begin

end;
///



//Settings///
procedure TMyFTP.set_host(aHost: string);
begin
ftp.Host := aHost;
host := aHost;
end;

procedure TMyFTP.set_user(aUser: string);
begin
ftp.Username := aUser;
user := aUser;
end;

procedure TMyFTP.set_password(aPassword: string);
begin
ftp.Password := aPassword;
password := aPassword;
end;

procedure TMyFTP.set_directory(aDirectory: string);
begin
ftp.ChangeDir(aDirectory);
directory := aDirectory;
end;
///



//Connection///
function TMyFTP.connect;
begin
  ftp.Connect;

if ftp.Connected = true then
    result := true
  else
    result := false;
end;

function TMyFTP.get_state;
begin
result := ftp.Connected;
end;
///



//Returns///
procedure TMyFTP.get_list(aListbox: TListbox);
begin
ftp.List(aListbox.Items, '', false);
end;
///

//////////////////////////////////////////////////////////////////

end.
Da das mein erstes Projekt ist, wo ich einen eigenen Thread benutze kann es sein, dass hier noch was falsch ist. Ich hoffe ihr könnt mir sagen, wo mein Fehler liegt!

Grüße Admirandis
  Mit Zitat antworten Zitat