1
votes

Someone managed to install InstantObjects in Delphi XE4?

I'm compiling the latest sources who are on svn repository. After correcting some issues as the compiler version, I am stuck in the following code snippet:

procedure TInstantAccessor.SetOnCompare(Value: TInstantCompareObjectsEvent);
begin
   if @Value <> @FOnCompare then
   begin
      FOnCompare := Value;
      RefreshView;
   end;
end;

Resulting in the error message "[dcc32 Error] InstantPresentation.pas (1580): E2008 Incompatible types" on the line:

if @Value <> @FOnCompare then

But they are the same type: TInstantCompareObjectsEvent

What's wrong?

2
Could this be a bug of Delphi XE4? - Flávio Oliveira E Santos
@TLama, the comparison is testing if the same function is being assigned again. If not using @, the compiler won't compile because it would expect the functions to be called. Flavio, have you double checked the {T} compiler directive? More info here: docwiki.embarcadero.com/RADStudio/XE4/en/… - Fabricio Araujo
I think the code is comparing whether objects occupy the same memory address... - Flávio Oliveira E Santos
@TLama: no problem, happens with everyone. ;-) - Fabricio Araujo
@FabricioAraujo, you meant {$T}? - Flávio Oliveira E Santos

2 Answers

1
votes

Maybe casting the procedural pointer to the generic Pointer type can solve:

procedure TInstantAccessor.SetOnCompare(Value: TInstantCompareObjectsEvent);
var 
  PValue, PFOnCompare: Pointer;
begin
   PValue := Pointer(@Value);           // Casting the original pointer to an generic pointer 
   PFOnCompare := Pointer(@FOnCompare);
   if @PValue <> @PFOnCompare then
   begin
      FOnCompare := Value;
      RefreshView;
   end;
end;
0
votes

What Fabricio wrote in the comments make sense. I surrounded the code with the directives {$T-} and {$T+} and the code compiled!

Now I'm in trouble in other parts of the code, but that's another story.

procedure TInstantAccessor.SetOnCompare(Value: TInstantCompareObjectsEvent);
begin
{$T-}
   if @Value <> @FOnCompare then
   begin
      FOnCompare := Value;
      RefreshView;
   end;
{$T+}
end;

Thank you all.