Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2001-12

create and destroy

3 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Shifted Soul
Hello, I have two small questions, if you can give me a yes or no only.
Q1 : Can I call a method from the constructor of the same class. Example
:
TSample = CLASS
                  PUBLIC
                  CONSTRUCTOR Create;
                  DESTRUCTOR Destroy;Override;
                  PROCEDURE a;
END;
CONSTRUCTOR TSample.Create;
BEGIN
   a;
END;

Q2 : I know that the standard is to override the "destroy" destructor and to use the free method to dstroy the object. I know also that the standard "destroy" don't have any parameter. But I want to have a destructor with parameters, can I do it without being out of standard, don't tell me that I can call the destructor directly, because I gave a sample a time ago with a direct call to the destructor which made a great deal about standards, so I won't to make more troubles in this mailing list.

Thanx

Reply by email

Carlo Kok
to Shifted Soul

----- Original Message -----

Earlier message 36 lines
From: "Shifted Soul" To: "fpc mailing list" Sent: Monday, December 17, 2001 10:01 AM Subject: [fpc-pascal]create and destroy > Hello, I have two small questions, if you can give me a yes or no only. > Q1 : Can I call a method from the constructor of the same class. Example > : > TSample = CLASS > PUBLIC > CONSTRUCTOR Create; > DESTRUCTOR Destroy;Override; > PROCEDURE a; > END; > > CONSTRUCTOR TSample.Create; > BEGIN > a; > END; Yes, as far as I know, you can. > > Q2 : I know that the standard is to override the "destroy" destructor > and to use the free method to dstroy the object. I know also that the > standard "destroy" don't have any parameter. But I want to have a > destructor with parameters, can I do it without being out of standard, > don't tell me that I can call the destructor directly, because I gave a > sample a time ago with a direct call to the destructor which made a > great deal about standards, so I won't to make more troubles in this > mailing list. I don't know where you need it for, but why don't you create some properties or variables like: DoSomethingOnDestroy: Boolean;

Reply by email

Michael Van Canneyt
to Shifted Soul: Hello, I have two small questions, if you can give me a yes or no only. Q1 : Can I call a…
Shifted Soul wrote 14 lines
Hello, I have two small questions, if you can give me a yes or no only. Q1 : Can I call a method from the constructor of the same class. Example : TSample = CLASS PUBLIC CONSTRUCTOR Create; DESTRUCTOR Destroy;Override; PROCEDURE a; END; CONSTRUCTOR TSample.Create; BEGIN a; END;

Yes you can.

Show quoted text 9 lines
Q2 : I know that the standard is to override the "destroy" destructor and to use the free method to dstroy the object. I know also that the standard "destroy" don't have any parameter. But I want to have a destructor with parameters, can I do it without being out of standard, don't tell me that I can call the destructor directly, because I gave a sample a time ago with a direct call to the destructor which made a great deal about standards, so I won't to make more troubles in this mailing list.

You can perfectly do that, BUT:
- You cannot use the Free method (nowhere).
- Your top-level class destructor must always call 'Destroy' so TObject.Destroy is called as the last destructor.

Michael.

Reply by email