Einzelnen Beitrag anzeigen

Benutzerbild von himitsu
himitsu

Registriert seit: 11. Okt 2003
Ort: Elbflorenz
43.168 Beiträge
 
Delphi 12 Athens
 
#21

AW: Dateien verschlüssen mit Wolgang Ehrhardts Crypt-Units

  Alt 17. Dez 2020, 13:50
Ist es wirklich so schwer zu verstehen?

Entweder du reichts es einfach durch und kannst hier von außen z.B. deine Form/Self reingeben, oder sonsteine Instanz, wo dieses Interface enthalten ist.
Delphi-Quellcode:
type
  TDECCryptUtils = record
  private
    //
  public
    class function AESFileEncrypt(const FileName, Password: string; const Progress: IDECProgress = nil): string; static;
    class function AESFileDecrypt(const FileName, Password: string; const Progress: IDECProgress = nil): string; static;
  end;

class function TDECCryptUtils.AESFileDecrypt(const FileName, Password: string; const Progress: IDECProgress): string;
...
   Cipher.DecodeFile(FileName, FileName + '.decrypted.txt', Process);



type
  TForm1 = class(TForm, IDECProgress)
  ...

procedure TForm1.Button1Click(Sender: TObject);
begin
  TDECCryptUtils.AESFileDecrypt('Dat.ei', 'Pass', Self);
end;
Und im Notfalls kann man es auch immer kapseln, sich also Wrapper bauen, um zwischen den verschiedenen Möglichkeiten der Callbacks zu wechseln.
Delphi-Quellcode:
type
type
  TDECProgress = procedure(const Min, Max, Pos: Int64) of object; // oder ohne "of object" oder mit "reference to" und mit oder ohne "stdcall"

  TDECProgressWrapper = class(TInterfacedObject, IDECProgress);
  private
    FOnProcess: TDECProgress;
    procedure Process(const Min, Max, Pos: Int64); stdcall;
  public
    constructor Create(const OnProcess: TDECProgress);
  end;

  TDECCryptUtils = record
  private
    //
  public
    class function AESFileEncrypt(const FileName, Password: string; const OnProgress: TDECProgress = nil): string; static;
    class function AESFileDecrypt(const FileName, Password: string; const OnProgress: TDECProgress = nil): string; static;
  end;

procedure TDECProgress.Process(const Min, Max, Pos: Int64); stdcall;
begin
  FOnProcess(Min, Max, Pos);
end;

constructor TDECProgress.Create(const OnProcess: TDECProgress);
begin
  inherited;
  Assert(Assigned(AProcess));
  FOnProcess := OnProcess;
end;

class function TDECCryptUtils.AESFileDecrypt(const FileName, Password: string; const OnProgress: TDECProgress): string;
...
   Cipher.DecodeFile(FileName, FileName + '.decrypted.txt', TDECProgressWrapper.Create(OnProgress)); // nur wenn Assigned(OnProgress) ... oder oben das Assert entfernen (und if-Assigned in den Callback)



type
  TForm1 = class(TForm) // ohne IDECProgress
  ...

procedure TForm1.Button1Click(Sender: TObject);
begin
  TDECCryptUtils.AESFileDecrypt('Dat.ei', 'Pass', YourProcessMethod);
end;
Zitat:
Delphi-Quellcode:
  except
   //
  end;
Für sowas gehört man mindestens gevierteilt.
Garbage Collector ... Delphianer erzeugen keinen Müll, also brauchen sie auch keinen Müllsucher.
my Delphi wish list : BugReports/FeatureRequests

Geändert von himitsu (17. Dez 2020 um 13:58 Uhr)
  Mit Zitat antworten Zitat