Search code examples
delphiinno-setupdelphi-2009

Accessing new attributes/properties on building Inno-Setup from source?


I've got a little problem with building Inno Setup from source. I want to modify the TNewButton type to put a little more functionality into the setup-buttons. For example I changed the type-declaration from

TNewButton = class(TButton)
protected
  procedure CreateParams(var Params: TCreateParams); override;
end;

to

TNewButton = class(TButton)
  procedure CMDialogChar( var Msg: TCMDialogChar); message cm_DialogChar;
private
  FNoShortcut : Boolean;
protected
  procedure CreateParams(var Params: TCreateParams); override;
public
  property NoShortcut : Boolean read FNoShortcut write FNoShortcut;
end;

So I created a private attribute NoShort that is accessed via the public property NoShortcut and is used in the procedure CMDialogChar (I want to disable in a specific situation, that the buttons ca be activated via shortcuts). There are some other things I want to implement, but they result in the same problem:

I can compile Inno Setup with these modifications without any problems (I use Delphi 2009 to get unicode support) and am also able to create an installer. But when I try to access the new property NoShortcut in an .iss-file (e.g. "WizardForm.NextButton.NoShortcut := true;"), the Inno compiler stops with the error

Unknown Identifier 'NOSHORTCUT'

Do I have to register these new attributes and properties in a special way to use them in my iss-Files? Any help will be appreciated :D


Solution

  • As TLama pointed out, the new identifier has to be registered in both ScriptClasses_C.pas and ScriptClasses_R.pas. To be a little more specific in matters of the question:

    In ScriptClasses_C.pas I created a procedure RegisterTNewButton_C to let the compiler know about my new identifier for the button:

    procedure RegisterTNewButton_C(Cl: TPSPascalCompiler);
    begin
      with Cl.AddClassN(Cl.FindClass('TButton'), 'TNewButton') do
      begin
        RegisterProperty('NoShortcut', 'Boolean', iptrw);
      end;
    end;
    

    In ScriptClasses_R.pas I basically do the same, but I additionally had to implement to getter and setter for the new identifier:

    procedure TNewButtonNoShortcut_R(Self: TNewButton; var T: Boolean); 
    begin 
      T := Self.NoShortcut;
    end;
    
    procedure TNewButtonNoShortcut_W(Self: TNewButton; const T: Boolean); 
    begin 
      Self.NoShortcut := T; 
    end;
    
    procedure RegisterTNewButton_R(CL: TPSRuntimeClassImporter);
    begin
      with CL.Add(TNewButton) do
      begin
        RegisterPropertyHelper(@TNewButtonNoShortcut_R,@TNewButtonNoShortcut_W,'NoShortcut');
      end;
    end;
    

    To make it finally work RegisterTNewButton_C has to be called in the method ScriptClassesLibraryRegister_C and RegisterTNewButton_R in ScriptClassesLibraryRegister_R accordingly.

    In addition I deleted/commented the lines that registered TNewButton previously (in RegisterBidiCtrls_C and in RegisterBidiCtrls_R) to avoid errors that could evolve when a component is registered twice. But I don't know if this is necessary.