Delphi RAR 组件请求存档密码

发布于 2024-11-13 08:29:19 字数 658 浏览 3 评论 0原文

我想要这个 RAR 组件: http://www.philippewechsler.ch/RARComponent.php
作者:菲利普·韦克斯勒。

但我不明白如何请求密码而不是存档中的文件而是存档?

文档中写的是我不明白如何使用:

OnPasswordRequired(Sender: TObject; const HeaderPassword: Boolean; 
const FileName: WideString;out NewPassword: Ansistring; out Cancel: Boolean);

如果需要密码才能继续,则会发生此事件。

HeaderPassword:如果为 true,则需要密码才能打开存档。 否则需要密码才能处理文件。

FileName:需要密码的文件的文件名(存档名 或存档内文件的文件名)

NewPassword:所需的密码

取消:如果您不知道正确的密码,请将此设置为 true

如何使用此代码?

I want to the this RAR component: http://www.philippewechsler.ch/RARComponent.php
By Philippe Wechsler.

But I don't understand how can I request a password NOT for files in an archive but for an ARCHIVE?

It is written in the documentation that I don't understand how to use:

OnPasswordRequired(Sender: TObject; const HeaderPassword: Boolean; 
const FileName: WideString;out NewPassword: Ansistring; out Cancel: Boolean);

This event occurs if a password is required to continue.

HeaderPassword: if this is true, the password is required to open the archive.
Otherwise the password is needed to process a file.

FileName: the filename of the file that requires a password (either the archivename
or the filename of the file inside the archive)

NewPassword: the required password

Cancel: set this to true if you don’t know the correct password

How do I use this code?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

安穩 2024-11-20 08:29:19
OnPasswordRequired(Sender: TObject; const HeaderPassword: Boolean; 
const FileName: WideString;out NewPassword: Ansistring; out Cancel: Boolean);

我不确定这里的问题是什么...这是一个事件处理程序,您可以像分配任何其他事件处理程序一样分配它:通过双击对象中的 OnPasswordRequired 事件检查器,或者通过代码连接它:

implementation

  procedure TForm1.FormCreate(Sender: TObject);
  begin
    RARComp.OnPasswordRequired := RARPasswordRequired;
  end;

  procedure TForm1.RARPasswordRequired(Sender: TObject; 
    const HeaderPassword: Boolean; 
    const FileName: WideString; 
    out NewPassword: Ansistring; out Cancel: Boolean);
  begin
    if HeaderPassword then  // need whole archive password
      NewPassword := YourWholeArchivePassword  // provide whole archive password
    else
      // Need individual file password. If you have a separate password for
      // each file, provide it as each file is provided in "filename" param.
      if FileName = TheFilenameYouHavePasswordFor then
        NewPassword := ThisFilesPassword
      else
        Cancel := True;
  end;

我不知道组件名称是什么(我使用了 RARComp,但我不熟悉这个组件);将其替换为正确的内容。 OnPasswordRequired 事件肯定有一个预定义的类型(例如 TPasswordRequiredEvent 或其他);再说一遍,我对这个组件不熟悉。

解释一下:传递给事件处理程序的 out 参数类似于 var 参数,只不过它们在由组件传递之前不必进行初始化。事实上,它们是out,这意味着它们是输出;您需要为它们分配值。另一方面,您无法更改两个 const 参数(HeaderPasswordFileName);它们是供您决定如何设置允许更改的两个参数的值。 Sender 将是 RARComp 或任何您调用的组件实例;如果需要使用 TRARComponent(Sender)(Sender as TRARComponent) 等语法访问其他信息,可以对其进行类型转换。

同样,我不知道该组件的正确类名是什么,也不知道您的实例将被命名为什么。如果 IDE 组件选项板上的组件类名是 TRARComponent,并且您将其拖放到表单上,则它将被声明为 RARComponent1: TRARComponent;,并且您将使用名称 RARComponent1TRARComponent(Sender)(如果适用)。

OnPasswordRequired(Sender: TObject; const HeaderPassword: Boolean; 
const FileName: WideString;out NewPassword: Ansistring; out Cancel: Boolean);

I'm not sure what the question is here... This is an event handler, and you assign it just as you would any other event handler: either by double-clicking the OnPasswordRequired event in the Object Inspector, or by connecting it via code:

implementation

  procedure TForm1.FormCreate(Sender: TObject);
  begin
    RARComp.OnPasswordRequired := RARPasswordRequired;
  end;

  procedure TForm1.RARPasswordRequired(Sender: TObject; 
    const HeaderPassword: Boolean; 
    const FileName: WideString; 
    out NewPassword: Ansistring; out Cancel: Boolean);
  begin
    if HeaderPassword then  // need whole archive password
      NewPassword := YourWholeArchivePassword  // provide whole archive password
    else
      // Need individual file password. If you have a separate password for
      // each file, provide it as each file is provided in "filename" param.
      if FileName = TheFilenameYouHavePasswordFor then
        NewPassword := ThisFilesPassword
      else
        Cancel := True;
  end;

I have no idea what the component name would be (I used RARComp, but I'm not familiar with this component); replace it with whatever is correct. There's surely a predefined type for the OnPasswordRequired event (like TPasswordRequiredEvent or something); again, I'm not familiar with the component.

To explain: The out parameters passed to the event handler are like var parameters, except they don't have to be initialized before being passed by the component. The fact they are out means they are output; you're expected to assign values to them. The two const parameters (HeaderPassword and FileName), on the other hand, can't be changed by you; they are values for your use in deciding how to set the two parameters you are allowed to change. The Sender will be the RARComp or whatever your component instance is called; it can be typecast if needed to access other information using syntax like TRARComponent(Sender) or (Sender as TRARComponent).

Again, I have no idea what the proper classname is for this component, or what your instance of it would be named. If the classname of the component is TRARComponent on the IDE's component palette, and you drop it on the form, it would be declared as RARComponent1: TRARComponent;, and you would use the name RARComponent1 and TRARComponent(Sender) where appropriate.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文