Recent

Author Topic: please make some procedures virtual; suggestion for a new tForm event/procedure  (Read 11561 times)

Martin V

  • Full Member
  • ***
  • Posts: 139
Hi,

I am a Lazarus beginner and have got only a few modifications for the LCL/FPC yet. Later, I will get part of the development community, but at the moment, I would prefer that someone takes a look at my proposals and makes the changes.


forms.pas

declaration of class tForm:
    procedure Close; -> should be virtual to enable overriding
    procedure Show;  -> should be virtual to enable overriding
   
controls.pas

declaration of class tControl

    move from private to protected:
      procedure SetFont(Value: TFont) -> should be virtual to enable overriding
   

classesh.inc (fpc rtl)
declaration of class tList:
    procedure Delete -> should be virtual to enable overriding
   
--------------------------

proposal for a new tForm event:

In WDsibyl, there's a useful Form procedure / Form event which is not part of Lazarus and Delphi: SetupShow/OnSetupShow

The SetupShow has to be executed the first time when the Form is shown. boolean "IsFirstShow" has to be set to true in Create.

procedure tSibylForm.Show;
  begin
    if IsFirstShow then SetupShow;
    IsFirstShow := false;
    inherited Show;
  end;
 
This would be a useful feature for lots of Lazarus (Delphi) users, because when overriding the Create constructor, a lot of stuff (e.g. Window handles) is not initialized yet and a lot of initialization stuff fails there. Lots of programmers have to override Show and need to write this simple code again and again...

In WDsibyl, there's also a SetupComponent procedure and an OnSetupComponent event which is more handy than overriding the constructor. Would be nice to have, but the OnSetupComponent is nearly the same as OnCreate.


Martin V. (Munich, Germany)

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1933
    procedure Close; -> should be virtual to enable overriding
    procedure Show;  -> should be virtual to enable overriding
   
I don't know exactly what you need, but are you aware that you can override DoClose and DoShow?

    move from private to protected:
      procedure SetFont(Value: TFont) -> should be virtual to enable overriding
   
Again, not sure about the purpose.
There is an event TFont.OnChange where you can get notified about changes.
   
classesh.inc (fpc rtl)
declaration of class tList:
    procedure Delete -> should be virtual to enable overriding
       
This is one for the Freepascal Mailinglist:
http://www.freepascal.org/maillist.var

SetupShow/OnSetupShow
       

Good idea imho.

Ñuño_Martínez

  • Hero Member
  • *****
  • Posts: 1216
    • Burdjia
Completely agree with Theo. But I must add: Why do you use the word should? I think it's a big word. May be you should use may, shouldn't you?

As for the TList modification:
Quote from: Martin V
classesh.inc (fpc rtl)
declaration of class tList:
    procedure Delete -> should be virtual to enable overriding

Why?
Are you interested in game programming? Join the Pascal Game Development community!
Also visit the Game Development Portal

Martin V

  • Full Member
  • ***
  • Posts: 139
 
I don't know exactly what you need, but are you aware that you can override DoClose and DoShow?

>procedure SetFont(Value: TFont) -> should be virtual to enable overriding
Again, not sure about the purpose.
There is an event TFont.OnChange where you can get notified about changes.

Thanks for your response. I indeed did not notice DoShow and DoClose, this should fit my purpose.

I thaught that the only purpose of On... Events is to use it in the object inspector for forms which are a visual resource. Can I overwrite On... in Lazarus when overriding a class?
   
classesh.inc (fpc rtl)
declaration of class tList:
    procedure Delete -> should be virtual to enable overriding

I have got a list of pointers pointing to heap objects. If the list item gets deleted, the pointer has to be freed. So I need to have a "FreeItem (Item : pointer)" where I can place my code to free the heap. But perhaps there's another way without modifying the RTL ?
       
Martin V. (Munich, Germany)

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1933
I thaught that the only purpose of On... Events is to use it in the object inspector for forms which are a visual resource. Can I overwrite On... in Lazarus when overriding a class?

You can use On.. in your code like:
MyObj.OnShow:=@Eventhandler;

Or you have something like DoShow which actually triggers OnShow if assigned and which you can override.
   
But perhaps there's another way without modifying the RTL ?

Maybe TObjectList. It has a property OwnsObjects. See
http://www.freepascal.org/docs-html/fcl/contnrs/tobjectlist.html

Ñuño_Martínez

  • Hero Member
  • *****
  • Posts: 1216
    • Burdjia
I have got a list of pointers pointing to heap objects. If the list item gets deleted, the pointer has to be freed. So I need to have a "FreeItem (Item : pointer)" where I can place my code to free the heap. But perhaps there's another way without modifying the RTL ?

If you need a list of Objects then use TObjectList or TFPObjectList instead. They're very similar than TList but they destroy the objects by default.
Are you interested in game programming? Join the Pascal Game Development community!
Also visit the Game Development Portal

 

TinyPortal © 2005-2018