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:
type
{ TBaseWizardDialogEditorClass }
generic TBaseWizardDialogEditorClass<T; F: TBaseWizardForm> = class(TObject)
private
FOnActionClose: TCloseEvent;
FOnMasterDataSetField: TOnMasterDataSetField;
procedure SetOnActionClose(AValue: TCloseEvent);
procedure SetOnMasterDataSetField(AValue: TOnMasterDataSetField);
protected
FFormWizard: F;
procedure DoActionButton(Sender: TObject); virtual; abstract;
procedure EditObject(EditObject: T); virtual; abstract;
public
destructor Destroy; override;
procedure Show; virtual;
procedure Clear; virtual; abstract;
procedure DefaultValueComponent; virtual; abstract;
procedure DefaultValueComponent(DataSetValue: string); virtual; abstract;
property OnActionClose: TCloseEvent read FOnActionClose write SetOnActionClose;
property OnMasterDataSetField: TOnMasterDataSetField read FOnMasterDataSetField write SetOnMasterDataSetField;
end;
implementation
{ TBaseEditorClass }
procedure TBaseEditorClass.DoActionClose(Sender: TObject;
var CloseAction: TCloseAction);
begin
FActionTypeEditor := ateAdd;
end;
procedure TBaseEditorClass.Edit(Item: T);
begin
FActionTypeEditor := ateEdit;
end;
procedure TBaseEditorClass.Show;
begin
case FActionTypeEditor of
ateAdd: FWizardEditor.Show;
ateEdit: FWizardEditEditor.Show;
end;
end;
{ TBaseWizardDialogEditorClass }
procedure TBaseWizardDialogEditorClass.SetOnActionClose(AValue: TCloseEvent);
begin
if FOnActionClose = AValue then Exit;
FOnActionClose := AValue;
end;
procedure TBaseWizardDialogEditorClass.SetOnMasterDataSetField(
AValue: TOnMasterDataSetField);
begin
if FOnMasterDataSetField = AValue then Exit;
FOnMasterDataSetField := AValue;
end;
destructor TBaseWizardDialogEditorClass.Destroy;
begin
if FFormWizard <> nil then
FreeAndNil(FFormWizard);
inherited Destroy;
end;
procedure TBaseWizardDialogEditorClass.Show;
begin
FFormWizard.ShowModal;
end;
end.
Due to the fact that in line 65 there is:
if FFormWizard <> nil then
I get the message (during compilation):
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:
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