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;