-7
Shape_class=class(tobject)

  Constructor create;
  Destructor Demolish;

Public
  Shape:tshape;
  Shape_width,
  Shape_height,
  Shape_left,
  Shape_top:integer;
End;

Function add_shape
  :Shape_class;
Begin
  Result:=shape_class.create;
End;

The code is simplified but illustrates what happens in my code. The call to the constructor is ignored by the debugger. If I hover the pointer over the class_name identifier in the call a hint informs me 'symbol eliminated by the linker'.

I have no idea what is causing this. I wondered if it has anything to do with the size of the stack, but increasing the stack makes no difference.

Sir Rufo
  • 18,395
  • 2
  • 39
  • 73
Muscipula
  • 55
  • 2
  • 10
  • 2
    Please add a [SSCCE](http://sscce.org) – Sir Rufo Feb 24 '14 at 08:29
  • 2
    Check your old questions if there is any valuable answer you can accept. – Sir Rufo Feb 24 '14 at 08:32
  • 3
    BTW your `Demolish` destructor will never called using `Free`. Destructor should be declared as `destructor Destroy; override;` – Sir Rufo Feb 24 '14 at 08:36
  • -1 you supplied incomplete code where it would have been simple to supply a complete program. Programming all about detail. – David Heffernan Feb 24 '14 at 08:58
  • None of you are being helpfull. In fact it seems to me that you people here want to demolish my credibility, which to me is curious because I do know not why. And for your information my demolish destructors ARE called when a class is freed. Supplying incomplete code? What does that really mean? I am trying to illustrate a situation that I have never seen before in Delphi where the linker completely bypasses the construction of a class that is neither empty or unused. So, please, what does the hint mean 'Symbol eliminated by linker'. The symbol itself being the name of the class. Muscipula. – Muscipula Feb 24 '14 at 17:36
  • `Demolish` will be called if you call it directly. It will not be called when you call `Free`. And you need to be able to use `Free` if you want code to handle exceptions raised during constructors. If you supply an SSCCE then we can help. Why won't you do that? – David Heffernan Feb 24 '14 at 19:17
  • My demolish destructors are invoked when I use free. But as for example code is concerned the situation is as above. The debugger simply steps over the class invocation, the constructor is not called and any subsequent attempts to access members of the class crash. – Muscipula Feb 24 '14 at 20:50
  • 1
    It's astonishing that you won't supply an SSCCE. If you did we could answer. And no, Demolish won't be called when you call Free. Free calls Destroy. The virtual Destroy declared in TObject. A large number people have told you that. If you think we are all ignorant and wrong, you perhaps are wasting your time asking us questions. – David Heffernan Feb 25 '14 at 07:22

1 Answers1

3

This is a self-destructive answer (because it is just a long comment)

Your question cannot be answered without a SSCCE

I build a small console app to test your code as shown so far

program so_21982168;

{$APPTYPE CONSOLE}
{$R *.res}

uses
  SysUtils;

type
  Shape_class = class( tobject )

    Constructor create;
    Destructor Demolish;

  Public
    Shape : tobject;
    Shape_width, Shape_height, Shape_left, Shape_top : integer;
  End;

Function add_shape : Shape_class;
Begin
  Result := Shape_class.create;
End;

{ Shape_class }

Constructor Shape_class.create;
Begin
  Writeln( 'shape_class.create called' );
  Shape := tobject.create;
End;

Destructor Shape_class.Demolish;
Begin
  Writeln( 'shape_class.Demolish called' );
  Shape.Free;
End;

procedure Test;
var
  LInstance : Shape_class;
Begin
  Writeln( 'Test ENTER' );
  LInstance := Shape_class.create;
  try
    Assert( Assigned( LInstance ) );
  finally
    LInstance.Free;
  End;
  Writeln( 'Test LEAVE' );
End;

Begin
  try

    Test;

  except
    on E : Exception do
      Writeln( E.ClassName, ': ', E.Message );
  End;

  Readln;

End.

The output is

Test ENTER
shape_class.create called
Test LEAVE
  • the destructor Demolish is not called by Free
  • there is a memory leak (Shape instance will not be freed)
  • there are no hints at all
Sir Rufo
  • 18,395
  • 2
  • 39
  • 73
  • First of all I wish to apologise. Yes you are correct about the destructor and knowing this now will certainly help later. Also, I worked out the solution for my problem by simplifying the code from p_class_pointer(generic_pointer):=@class_name.create; To class_instance:=class_name.create; p_class_pointer(generic_pointer):=@class_instance; And it works! TIA Andrew – Muscipula Feb 25 '14 at 14:59
  • 3
    @Muscipula This is exactly what happens when you post fake code. Nowhere in the question does `p_class_pointer(generic_pointer):=@class_name.create` appear. And FWIW, `p_class_pointer(generic_pointer)` is exceptionally unlikely to be the solution to any problem. You ask for advice and then ignore it. You've been told many many times about your destructors but you kept ignoring the advice. You have a lot to learn and you won't be able to learn until you recognise that you are lacking knowledge and need to learn. I hope you can adjust your mindset. – David Heffernan Feb 25 '14 at 15:13
  • 1
    @Muscipula If you edit your question and add the informations from your comment here, we can reopen the question and I guess all the down votes will disappear – Sir Rufo Feb 25 '14 at 15:24
  • FWIW, what you should have written is `generic_pointer:=Pointer(class_name.create)`, then you could access your class with `class_name(generic_pointer).--` or `p_class_pointer(@generic_pointer).--` – Sertac Akyuz Feb 25 '14 at 15:49