Skip to content

How to fix from Delphi XE2 #509

Description

@Uefi1

Hello, the Delphi XE2 compiler shows errors in the code:

  // Fill the m_slots for multi-phase initialization
  FSlots := [PyModuleDef_Slot.Make(Py_mod_exec,
    GetCallBack(Self, @TPythonModule.Exec_Module, 1, DEFAULT_CALLBACK_TYPE))];

..

FSlots := FSlots + [PyModuleDef_Slot.Make(Py_mod_multiple_interpreters, P)];

FSlots := FSlots + [PyModuleDef_Slot.Make(0, nil)];

[DCC Error] PythonEngine.pas(7702): E2001 Ordinal type required

How to correct errors correctly ?

Activity

  1. pyscripter commented on Oct 20, 2025

    @pyscripter
    Collaborator

    You can try:

    FSlots := Concat(FSlots,  [PyModuleDef_Slot.Make(Py_mod_multiple_interpreters, P)]);
    FSlots := Concat(FSlots), [PyModuleDef_Slot.Make(0, nil)]);

    Please, let me know if it works.

  2. Uefi1 commented on Oct 20, 2025

    @Uefi1
    Author

    Hello, for some reason the error still remains the same =(

    FSlots := Concat(FSlots,  [PyModuleDef_Slot.Make(Py_mod_multiple_interpreters, P)]);
    
    [DCC Error] PythonEngine.pas(7712): E2001 Ordinal type required
    
  3. pyscripter commented on Oct 20, 2025

    @pyscripter
    Collaborator

    You can try:

    Insert(PyModuleDef_Slot.Make(Py_mod_multiple_interpreters, P), FSlots, Length(FSlots));

  4. Uefi1 commented on Oct 21, 2025

    @Uefi1
    Author

    You can try:

    Insert(PyModuleDef_Slot.Make(Py_mod_multiple_interpreters, P), FSlots, Length(FSlots));

      // Fill the m_slots for multi-phase initialization
      FSlots[0] := PyModuleDef_Slot.Make(Py_mod_exec,
        GetCallBack(Self, @TPythonModule.Exec_Module, 1, DEFAULT_CALLBACK_TYPE));
    ..
        Insert(PyModuleDef_Slot.Make(Py_mod_multiple_interpreters, P), FSlots, Length(FSlots));
    
    [DCC Error] PythonEngine.pas(7712): E2008 Incompatible types
    
  5. pyscripter commented on Oct 21, 2025

    @pyscripter
    Collaborator

    [DCC Error] PythonEngine.pas(7712): E2008 Incompatible types

    Damn. This works in Delphi 12.

    Then try:

        SetLength(FSLots, Length(FSlots) + 1);
        FSlots[High(FSlots)] := PyModuleDef_Slot.Make(Py_mod_multiple_interpreters, P);
  6. Uefi1 commented on Oct 21, 2025

    @Uefi1
    Author

    [DCC Error] PythonEngine.pas(7712): E2008 Incompatible types

    Damn. This works in Delphi 12.

    Then try:

    SetLength(FSLots, Length(FSlots) + 1);
    FSlots[High(FSlots)] := PyModuleDef_Slot.Make(Py_mod_multiple_interpreters, P);
    

    How to fix the full procedure correctly ?=)

    procedure TPythonModule.MakeModuleDef;
    var
      P: Pointer;
    begin
      FillChar(FModuleDef, SizeOf(FModuleDef), 0);
      FModuleDef.m_base.ob_refcnt := 1;
      FModuleDef.m_name := PAnsiChar(ModuleName);
      FModuleDef.m_methods := MethodsData;
      FModuleDef.m_size := 0;
    
      // Doc string
      if FDocString.Count > 0 then
      begin
        FEncodedDocString := UTF8Encode(CleanString(FDocString.Text, False));
        FModuleDef.m_doc := PAnsiChar(FEncodedDocString);
      end;
    
      // Fill the m_slots for multi-phase initialization
      FSlots := [PyModuleDef_Slot.Make(Py_mod_exec,
        GetCallBack(Self, @TPythonModule.Exec_Module, 1, DEFAULT_CALLBACK_TYPE))]; // E2001 Ordinal type required
    
      if (Engine.MajorVersion > 3) or (Engine.MinorVersion >= 12) then
      begin
        case FMultInterpretersSupport of
          mmiNotSupported: P := Py_MOD_MULTIPLE_INTERPRETERS_NOT_SUPPORTED;
          mmiPerInterpreterGIL: P := Py_MOD_PER_INTERPRETER_GIL_SUPPORTED;
        else
          P := Py_MOD_MULTIPLE_INTERPRETERS_SUPPORTED;
        end;
        FSlots := FSlots + [PyModuleDef_Slot.Make(Py_mod_multiple_interpreters, P)]; // E2001 Ordinal type required
      end;
      FSlots := FSlots + [PyModuleDef_Slot.Make(0, nil)]; // E2001 Ordinal type required
    
      FModuleDef.m_slots := @FSlots[0];
    end;
    
  7. pyscripter commented on Oct 21, 2025

    @pyscripter
    Collaborator

    Did my suggestion work? I don't have access to XE2. If yes you do the same for the other array concatenation and it should work.

  8. Uefi1 commented on Oct 21, 2025

    @Uefi1
    Author

    Did my suggestion work? I don't have access to XE2. If yes you do the same for the other array concatenation and it should work.

    Yes, there is no point in fixing them one by one. The binding is there. Maybe it would be better to reconsider/change the logic of the whole procedure.

  9. Uefi1 commented on Nov 4, 2025

    @Uefi1
    Author

    Hi, after the recent update the problem still hasn't been resolved:

    Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions