Can I create my own classes or units in Inno Setup?

断了今生、忘了曾经 提交于 2019-12-01 08:48:18

问题


I would like to know if it's possible in Inno Setup to define my own units or classes - with both fields (just like defining a record) and methods.


回答1:


No, you can define only:

  • structures (record keyword) - fields only, and
  • interfaces (interface keyword) - abstract methods only - for COM/ActiveX.

But you cannot implement classes (fields and methods).

The Pascal Script does not even recognize the class keyword.


Not even units. The Inno Setup Pascal Script is just a single block of code. There's no really any point trying to hide some implementation/code.


If you just want to organize the code somehow, you can use the #include directive of Inno Setup pre-processor to split the code into files.

You can have a header/interface-like file with prototypes/forward declarations of the "public" functions/procedures and implementation-like file with the implementation and "private" functions/procedures.

The interface-like file (say header.iss):

procedure PublicProc; forward;

The implementation-like file (say impl.iss):

procedure PrivateProc;
begin
  ...
end;

procedure PublicProc;
begin
  PrivateProc;
end;

And use it like:

[Code]

#include "header.iss"

function InitializeSetup: Boolean;
begin
  { Here we can use the PublicProc, but not PrivateProc }
end;

#include "impl.iss"


来源:https://stackoverflow.com/questions/36874096/can-i-create-my-own-classes-or-units-in-inno-setup

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!