Einzelnen Beitrag anzeigen

Benutzerbild von Luckie
Luckie

Registriert seit: 29. Mai 2002
37.621 Beiträge
 
Delphi 2006 Professional
 
#5

Re: Eine Thread-Klasse verschiedene Aktionen

  Alt 13. Apr 2007, 12:51
Also, ich habe es jetzt so:
Delphi-Quellcode:
type
  { Thread operation: saveing or loading a template }
  TThreadOperation = (toSave, toLoad);

  TOnTemplateBegin = TNotifyEvent;
  TOnTemplateProgress = TNotifyEvent;
  TOnTemplateEnd = TNotifyEvent;

  TTemplate = class(TThread)
  private
    FFilename: WideString;
    FThreadOperation: TThreadOperation;
    procedure Save;
    procedure Load;
  protected
    procedure Execute; override;
  public
    procedure SaveToFile(Filename: WideString);
    procedure LoadFromFile(Filename: WideString);
  end;

implementation

{ TTemplate }

procedure TTemplate.Execute;
begin
  inherited;
  case FThreadOperation of
    toSave: Save;
    toLoad: Load;
  end;
end;

procedure TTemplate.Load;
begin

end;

procedure TTemplate.LoadFromFile(Filename: WideString);
begin
  FFilename := Filename;
  FThreadOperation := toLoad;
  Resume;
end;

procedure TTemplate.Save;
begin

end;

procedure TTemplate.SaveToFile(Filename: WideString);
begin
  FFilename := Filename;
  FThreadOperation := toSave;
  Resume;
end;
Delphi-Quellcode:
procedure TForm1.Button2Click(Sender: TObject);
var
  Template: TTemplate;
begin
  Template := TTemplate.Create(False);
  Template.FreeOnTerminate;
  Template.LoadFromFile('foobar');
end;
Michael
Ein Teil meines Codes würde euch verunsichern.
  Mit Zitat antworten Zitat