Jump to content
PeterPanettone

Delphi 12: Invalid class typecast

Recommended Posts

1 hour ago, PeterPanettone said:

image.thumb.png.743ae8dee488f91ed7bb2a3da2bffd58.png 

If i to read this right, then the exception was not here at all, and this one is a nested one, in other words this one is raised while handing a previous (and original) exception.

 

Also the stack is cut !, where is the rest of it ? does this dialog have more text without scroll bars ? or this is it ?

 

Also would you please try to track the actual disk operations with Process Monitor ? in other words, were there a successful/failure File Write operations right before this dialog ?

Share this post


Link to post
56 minutes ago, PeterPanettone said:

This faulty behavior occurs only if MMX is loaded AND with the "MainProgramWindowManager" unit! (If both conditions are NOT met, clicking the SAVE button turns the SAVE-ALL icon grey: Checked and re-checked just now).

That is probably caused by the IDE or whatever catching the failing assertion during save of that unit. While MMX logs such an assertion it should nevertheless popup.

 

1 hour ago, PeterPanettone said:

This points to the same error from the previous MMX error message dialog (EAssertionFailed in CustomPascalExplorer.pas), thus proving that MMX prevents the project from being compiled or built.

I have uploaded a new beta catching this assertion and writing it to CodeSite. So if you reproducibly get that exception now, you should get a CodeSite message with the new beta - unless the underlying object instance is no longer valid, which would move the spot to a completely different source location.

 

What puzzles me is that this assertion failure nor any other exception is not logged to CodeSite. After all the MMX beta hooks into AssertErrorProc as well as Application.OnException. Can you disable the JCL exception handler as well as any other ones interfering with MMX here - at least for the time needed to investigate this?

Share this post


Link to post
46 minutes ago, Uwe Raabe said:

I have uploaded a new beta catching this assertion and writing it to CodeSite.

Thank you. I downloaded and installed the new beta:

 

image.thumb.png.08ca5d0abb89b282808d816847dfbb08.png

 

When loading my project in the IDE, CodeSite Live Viewer received these messages:

 

image.thumb.png.28875f9e20de31ee92703c1b44f2bbaa.png 

 

What conclusions can you draw from this?

Share this post


Link to post
4 minutes ago, PeterPanettone said:

What conclusions can you draw from this?

At least that gives me a hint where I can look at now. Stay tuned...

Share this post


Link to post

@PeterPanettone

Can you please try again with the latest beta 2597? If that doesn't show the problem I will provide a new release.

Share this post


Link to post

After having closed the Obsidium unit still opened in the IDE from the Obsidium Sample folder, now, when SAVING the "MainProgramWindowManager" unit, these are the CodeSite messages:

 

image.thumb.png.2d3109958b29ec5a820321b817df450d.png

 

Please note the new "Invalid class typecast" message that occurs while saving.

Share this post


Link to post
2 minutes ago, Uwe Raabe said:

Can you please try again with the latest beta 2597? If that doesn't show the problem I will provide a new release.

I will download and install beta 2597 in a second.

Share this post


Link to post

Those are expected in the beta reminding me to create a test case for this.

 

The functionality (f.i. regarding the Save All) should be ok now.

Share this post


Link to post

May i suggest this alternated code from Remy (i hope with his permission) https://stackoverflow.com/questions/39584234/how-to-obtain-rtti-from-an-interface-reference-in-delphi

type
  ITest1 = interface
    ['{5AB029F5-31B0-4054-A70D-75BF8278716E}']
    procedure Test1;
  end;

  ITest2 = interface
    ['{AAC18D39-465B-4706-9DC8-7B1FBCC05B2B}']
    procedure Test1;
  end;

  TTest = class(TInterfacedObject, ITest1, ITest2)
  public
    procedure Test1;
    procedure Test2;
  end;

procedure TTest.Test1;
begin
  //...
end;

procedure TTest.Test2;
begin
  //...
end;


function GetInterfacesFromItsObj(AIntf: IInterface): string;
var
  obj: TObject;
  IntfType: TRttiInterfaceType;
  ctx: TRttiContext;
  tmpIntf: IInterface;
begin
  obj := AIntf as TObject;
  Result := 'Object: (' + obj.ClassName + ')_ -> : ';
  for IntfType in (ctx.GetType(obj.ClassType) as TRttiInstanceType).GetImplementedInterfaces do
  begin
    if obj.GetInterface(IntfType.GUID, tmpIntf) then
    begin
      Result := Result {+ 'Intf: '} + IntfType.Name + ', ';
      tmpIntf := nil;
    end;
  end;
end;

procedure TForm10.FormCreate(Sender: TObject);
var
  Intf1: ITest1;
  Intf2: ITest2;
begin
  Intf1 := TTest.Create as ITest1;
  Intf2 := TTest.Create as ITest2;

  ShowMessage(GetInterfacesFromItsObj(Intf1));
end;

The result

image.png.2561df262bc36e8a4d88f077dc8ced7f.png

Share this post


Link to post
11 minutes ago, Kas Ob. said:

May i suggest this alternated code from Remy

Wrong thread?

Share this post


Link to post
Just now, Uwe Raabe said:

Wrong thread?

I am sorry !

 

I thought putting such interfaces resolver in the exception handler for failed "as" casting could show log better information about the missed interface implementation hence the failed casting. 

Share this post


Link to post

Thanks, but interfaces are not even involved in the code in question.

  • Like 1

Share this post


Link to post
35 minutes ago, Uwe Raabe said:

The functionality (f.i. regarding the Save All) should be ok now.

You are right - there are no more error messages when saving MainProgramWindowManager in beta 2597 now, and the behavior of the save icons is OK now! And I can compile/build my project after changes now! Thank you!

 

Will you publish a new MMX release now (without the CodeSite debug messages)?

Share this post


Link to post
4 minutes ago, Uwe Raabe said:

A new version V15.1.9 is available.

Thanks! Sorry, my latest posting came one second too late.

Share this post


Link to post

Downloaded and installed V15.1.9 Release. Everything is fine now. Thanks again, Uwe!

 

MMX takes 47 seconds to load:

 

image.thumb.png.2e55c7255830b2545a45c4186f59c3f7.png

 

Is that normal?

Edited by PeterPanettone

Share this post


Link to post

BTW - when I ever get a living from the apps I create, I will donate to MMX, GExperts ... and all the other real benefactors of humanity.

Edited by PeterPanettone

Share this post


Link to post
3 hours ago, PeterPanettone said:

Is that normal?

Looks like a bit much. It depends on the number of design time packages. Anyway, it should not have changed unless you installed a bunch of new ones.

 

There already exists a feature request to move that into a thread.

  • Thanks 1

Share this post


Link to post
46 minutes ago, Uwe Raabe said:

There already exists a feature request to move that into a thread.

Good idea!

Share this post


Link to post

Well done to Uwe, Peter, & any others, for seeing this issue through.

 

Ian

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×