Recent

Author Topic: Generic type nil problem  (Read 592 times)

J-23

  • Full Member
  • ***
  • Posts: 106
Generic type nil problem
« on: September 30, 2020, 12:39:36 am »
Hello,
I wanted to present some code that shows some inconsistency in specifying type in generic classes.

Maybe it is worth considering improving this in the next FPC versions, but before I can report it, I wanted to know the opinions, hence the publication on the forum.

Having the code:
Code: Pascal  [Select][+][-]
  1. type
  2.  
  3.   { TBaseWizardDialogEditorClass }
  4.  
  5.   generic TBaseWizardDialogEditorClass<T; F: TBaseWizardForm> = class(TObject)
  6.   private
  7.     FOnActionClose: TCloseEvent;
  8.     FOnMasterDataSetField: TOnMasterDataSetField;
  9.     procedure SetOnActionClose(AValue: TCloseEvent);
  10.     procedure SetOnMasterDataSetField(AValue: TOnMasterDataSetField);
  11.   protected
  12.     FFormWizard: F;
  13.     procedure DoActionButton(Sender: TObject); virtual; abstract;
  14.     procedure EditObject(EditObject: T); virtual; abstract;
  15.   public
  16.     destructor Destroy; override;
  17.     procedure Show; virtual;
  18.     procedure Clear; virtual; abstract;
  19.     procedure DefaultValueComponent; virtual; abstract;
  20.     procedure DefaultValueComponent(DataSetValue: string); virtual; abstract;
  21.     property OnActionClose: TCloseEvent read FOnActionClose write SetOnActionClose;
  22.     property OnMasterDataSetField: TOnMasterDataSetField read FOnMasterDataSetField write SetOnMasterDataSetField;
  23.   end;
  24.  
  25. implementation
  26.  
  27. { TBaseEditorClass }
  28.  
  29. procedure TBaseEditorClass.DoActionClose(Sender: TObject;
  30.   var CloseAction: TCloseAction);
  31. begin
  32.   FActionTypeEditor := ateAdd;
  33. end;
  34.  
  35. procedure TBaseEditorClass.Edit(Item: T);
  36. begin
  37.   FActionTypeEditor := ateEdit;
  38. end;
  39.  
  40. procedure TBaseEditorClass.Show;
  41. begin
  42.   case FActionTypeEditor of
  43.     ateAdd: FWizardEditor.Show;
  44.     ateEdit: FWizardEditEditor.Show;
  45.   end;
  46. end;
  47.  
  48. { TBaseWizardDialogEditorClass }
  49.  
  50. procedure TBaseWizardDialogEditorClass.SetOnActionClose(AValue: TCloseEvent);
  51. begin
  52.   if FOnActionClose = AValue then Exit;
  53.   FOnActionClose := AValue;
  54. end;
  55.  
  56. procedure TBaseWizardDialogEditorClass.SetOnMasterDataSetField(
  57.   AValue: TOnMasterDataSetField);
  58. begin
  59.   if FOnMasterDataSetField = AValue then Exit;
  60.   FOnMasterDataSetField := AValue;
  61. end;
  62.  
  63. destructor TBaseWizardDialogEditorClass.Destroy;
  64. begin
  65.   if FFormWizard <> nil then
  66.     FreeAndNil(FFormWizard);
  67.   inherited Destroy;
  68. end;
  69.  
  70. procedure TBaseWizardDialogEditorClass.Show;
  71. begin
  72.   FFormWizard.ShowModal;
  73. end;
  74.  
  75. end.

Due to the fact that in line 65 there is:

Code: Pascal  [Select][+][-]
  1. if FFormWizard <> nil then

I get the message (during compilation):
Code: Pascal  [Select][+][-]
  1. WizardDialogEditorRBM.pas(119,21) Error: Incompatible types: got "Pointer" expected "$gendef1"

Which clearly indicates that I do not know if type is a pointer, hence the above message and it would be true if I declared my class like this:

Code: Pascal  [Select][+][-]
  1.  generic TBaseWizardDialogEditorClass<T; F> = class(TObject)

but my class declaration specifies the type so the above message shouldn't be. (According to me)

What do you think about it? Is it worth reporting it?


A few words on this topic https://forum.lazarus.freepascal.org/index.php?topic=42009.0 were mentioned in this thread that it is like Delphi is similar but I do not have how to check it now.


Even if it were, there would be no consequences for a notation like
Code: Pascal  [Select][+][-]
  1. <T; F: TBaseWizardForm>


Blaazen

  • Hero Member
  • *****
  • Posts: 2964
  • POKE 54296,15
    • Eye-Candy Controls
Re: Generic type nil problem
« Reply #1 on: September 30, 2020, 01:01:50 am »
I tried your code with 3.3.1 - yesterday trunk, {$mode objfpc} and I got no error message for both variants, i.e. both:
Code: Pascal  [Select][+][-]
  1. generic TBaseWizardDialogEditorClass<T; F: TBaseWizardForm> = class(TObject)
  2. and
  3. generic TBaseWizardDialogEditorClass<T; F> = class(TObject)
compiles well.
Lazarus 2.1.0 r64074 FPC 3.3.1 r40507 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

J-23

  • Full Member
  • ***
  • Posts: 106
Re: Generic type nil problem
« Reply #2 on: September 30, 2020, 01:13:21 am »
I tried your code with 3.3.1 - yesterday trunk, {$mode objfpc} and I got no error message for both variants, i.e. both:
Code: Pascal  [Select][+][-]
  1. generic TBaseWizardDialogEditorClass<T; F: TBaseWizardForm> = class(TObject)
  2. and
  3. generic TBaseWizardDialogEditorClass<T; F> = class(TObject)
compiles well.

Thanks for the information. I will try

PascalDragon

  • Hero Member
  • *****
  • Posts: 2268
  • Compiler Developer
Re: Generic type nil problem
« Reply #3 on: September 30, 2020, 10:16:19 am »
I tried your code with 3.3.1 - yesterday trunk, {$mode objfpc} and I got no error message for both variants, i.e. both:
Code: Pascal  [Select][+][-]
  1. generic TBaseWizardDialogEditorClass<T; F: TBaseWizardForm> = class(TObject)
  2. and
  3. generic TBaseWizardDialogEditorClass<T; F> = class(TObject)
compiles well.

Seems like I'll have to hunt for the revision that fixed that and have that merged to 3.2.1... :-[

J-23

  • Full Member
  • ***
  • Posts: 106
Re: Generic type nil problem
« Reply #4 on: September 30, 2020, 12:53:21 pm »
I confirm it works.

However, there is a new problem with FPC 3.3.1 not compiling FastReport when compiling I am getting a message:
Code: Pascal  [Select][+][-]
  1. frxXML.pas(475,22) Error: Asm: signed dword value exceeds bounds -4294967296

It concerns the procedure:
Code: Pascal  [Select][+][-]
  1. procedure TfrxXMLItem.SetOffset(const Value: Int64);
  2. begin
  3.   FHiOffset := Value div $100000000;
  4.   FLoOffset := Value mod $100000000; //this error
  5. end;
  6.  

Which will be in the file:
Code: Pascal  [Select][+][-]
  1. C:\Program Files (x86)\FastReport 5 VCL Professional\Source\frxXML.pas

This problem was not present in the previous FPC version, but there was a problem with the generics

I will only add that around the Lazarus 2.0.8 version, the generic code that I presented earlier, Lazarus compiled it

How do I get around the problem so that I can install FastReport?


PascalDragon

  • Hero Member
  • *****
  • Posts: 2268
  • Compiler Developer
Re: Generic type nil problem
« Reply #5 on: September 30, 2020, 01:36:06 pm »
However, there is a new problem with FPC 3.3.1 not compiling FastReport when compiling I am getting a message:
Code: Pascal  [Select][+][-]
  1. frxXML.pas(475,22) Error: Asm: signed dword value exceeds bounds -4294967296

Are you compiling with -al or any -Axxx option? Cause that message comes from the external assembler (though I can not reproduce it with the as I have, at least not with a simple example code).

J-23

  • Full Member
  • ***
  • Posts: 106
Re: Generic type nil problem
« Reply #6 on: September 30, 2020, 01:51:34 pm »
No, it compiles on standard options.

What information do you need to diagnose the problem?

PascalDragon

  • Hero Member
  • *****
  • Posts: 2268
  • Compiler Developer
Re: Generic type nil problem
« Reply #7 on: September 30, 2020, 10:26:35 pm »
As a first step your complete compiler commandline. Cause the error message is from the external assembler as it does not exist in the compiler.

J-23

  • Full Member
  • ***
  • Posts: 106
Re: Generic type nil problem
« Reply #8 on: October 01, 2020, 02:28:39 am »
As a first step your complete compiler commandline. Cause the error message is from the external assembler as it does not exist in the compiler.
OK, I'll check and give it, or even prepare a virtual machine that shows the problem.

I will add that the problem only occurs on 64 bits on 32 bits, everything is ok.

 

TinyPortal © 2005-2018