Jump to content
Attila Kovacs

VCL error with caFree

Recommended Posts

Error happens when CM_RELEASE is sent to a form. The fix is to avoid calling VisualManager in that scenario. Instead in WndProc, you can also add check in VisualManager_AcceptMessage method before the code within tries to access FVisualManagerInitialized field.

 

 

procedure TCustomForm.WndProc(var Message: TMessage);
  ...

  inherited WndProc(Message);

  if (Message.Msg <> CM_RELEASE) and VisualManager_AcceptMessage(Message) then
    VisualManager_WndProc(Message);
end;

 

  • Thanks 1

Share this post


Link to post

@Dalija Prasnikar

Ok, I see now where the problem is. However, since VisualManager_AcceptMessage is not virtual, the only way to fix that without adding a patched Vcl.Forms to the project is to handle CM_RELEASE without calling the WndProc...

As I always use a common form, this should be manageable. I just have to examine what CM_RELEASE should do... let's see.

 

Thank you

Share this post


Link to post
1 minute ago, Attila Kovacs said:

@Dalija Prasnikar

Ok, I see now where the problem is. However, since VisualManager_AcceptMessage is not virtual, the only way to fix that without adding a patched Vcl.Forms to the project is to handle CM_RELEASE without calling the WndProc...

As I always use a common form, this should be manageable. I just have to examine what CM_RELEASE should do... let's see.

CM_RELEASE is simple

 

procedure TCustomForm.CMRelease;
begin
  Free;
end;

Yes, you can intercept it in your form.

Share this post


Link to post

Ok, CM_RELEASE has no job in form's wnd proc, I have to hop to TWinControls WndProc

Edited by Attila Kovacs

Share this post


Link to post
4 minutes ago, Attila Kovacs said:

Ok, CM_RELEASE has no job in form's wnd proc, I have to hop to TWinControls WndProc

It is directly dispatched in TCustomForm through procedure CMRelease(var Message: TMessage); message CM_RELEASE; 

Edited by Dalija Prasnikar
  • Thanks 1

Share this post


Link to post

I'll go with this, until it's fixed.

// D12 caFree patch
// https://www.delphipraxis.net/1530328-post10.html
// https://quality.embarcadero.com/browse/RSP-43547
procedure TCForm.WndProc(var Message: TMessage);
begin
  if message.Msg = CM_RELEASE then
    Dispatch(message)
  else
    inherited WndProc(message);
end;

Let this example stand as a sign of how beneficial it is to always use a common form.

 

  • Like 1

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

×