Recent

Author Topic: event property will not create  (Read 9306 times)

mangakissa

  • Hero Member
  • *****
  • Posts: 1131
event property will not create
« on: October 25, 2016, 04:51:45 pm »
The last few times a procedure will not put in unit when I dubbleclick on a event item in object inspector.

For my application I use a baseform. In that baseform some event properties like Oncreate, OnShow and Onclose are created and filled.
If I create a new form the baseform is inherited. Also the filled in procedures are showed in the object inspector.
Normally, when I dubbleclick on a event property like OnCreate, the inherited property will be placed to the property of the form itself. Then I have to dubbleclick again on the property for creating a procedure in the unit of the form. Nothings happens and the editor complains he can't jump to the desired procedure and wants to open the baseform for searching the procedure.

It's not good. The IDE has to create a new event procedure in the unit of the form like this:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Oncreate(sender : TObject);
  2. begin
  3.   inherited;
  4.   //own code
  5. end;
  6.  

Lazarus 1.6 / FPC 3.0 Windows Vista SP2 64 bits
« Last Edit: October 25, 2016, 04:56:29 pm by mangakissa »
Lazarus 2.06 (64b) / FPC 3.0.4 / Windows 10
stucked on Delphi 10.3.1

mangakissa

  • Hero Member
  • *****
  • Posts: 1131
Re: event property will not create
« Reply #1 on: October 31, 2016, 11:58:45 am »
No one?
Lazarus 2.06 (64b) / FPC 3.0.4 / Windows 10
stucked on Delphi 10.3.1

Thaddy

  • Hero Member
  • *****
  • Posts: 14382
  • Sensorship about opinions does not belong here.
Re: event property will not create
« Reply #2 on: October 31, 2016, 12:01:40 pm »
What?

The OnCreate is an event, not a constructor.
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

rvk

  • Hero Member
  • *****
  • Posts: 6169
Re: event property will not create
« Reply #3 on: October 31, 2016, 01:50:49 pm »
In that baseform some event properties like Oncreate, OnShow and Onclose are created and filled.
...
It's not good. The IDE has to create a new event procedure in the unit of the form like this:
The IDE won't create an event with "inherited;" in it because you can't/don't need to call inherited for an event. The inherited should be called for DoCreate which you should override in your base-form if you want to do something in that.

How did you declare the base?? You say you already filled in OnCreate but you shouldn't do that. You should override DoCreate in the baseclass to do what you want and calling inherited DoCreate will again call your FOnCreate in your child-forms.

totya

  • Hero Member
  • *****
  • Posts: 720
Re: event property will not create
« Reply #4 on: October 31, 2016, 03:00:24 pm »
If I create a new form the baseform is inherited. Also the filled in procedures are showed in the object inspector.

How do you create the new form? File/New Form? When you do this, new unit created of the new form, this is different from base form, so the events are differents too.

Can you show examples for your problem? (delete own code and insert only "//" etc). Can you show the .lpr file?

mangakissa

  • Hero Member
  • *****
  • Posts: 1131
Re: event property will not create
« Reply #5 on: October 31, 2016, 05:05:07 pm »
Small example included.
In the image you see Tfrmbase.Formshow from the baseform. If I click on property OnShow
Tfrmbase.Formshow will be replaced by Formshow. but there's no procedure created. When I click again on the property, the procedure can not be found (se in demo form frmbasedesc). But this must be local.
I created a second form to let you show what's happend (or not)
Lazarus 2.06 (64b) / FPC 3.0.4 / Windows 10
stucked on Delphi 10.3.1

totya

  • Hero Member
  • *****
  • Posts: 720
Re: event property will not create
« Reply #6 on: October 31, 2016, 05:25:48 pm »
Hi!

Okay, I understand your problem, but to tell the truth, I don't do it similar  in my life. I'm thinking on it.

Your problem: you create a form, and you create descendant form from this "base" form, and the forms event (via object inspector) doesn't work how you excepted.

Code: Pascal  [Select][+][-]
  1. type
  2.   { TFrmBase }
  3.   TFrmBase = class(TForm)
  4.     procedure FormShow(Sender: TObject);
  5.   private
  6.     { private declarations }
  7.   public
  8.     { public declarations }
  9.   end;

Code: Pascal  [Select][+][-]
  1. type
  2.   { TFrmBasedesc1 }
  3.   TFrmBasedesc1 = class(TFrmBase)
  4.   private
  5.     { private declarations }
  6.   public
  7.     { public declarations }
  8.   end;

edit: FrmBasedesc1 caption is same as FrmBase.
« Last Edit: October 31, 2016, 05:41:23 pm by totya »

rvk

  • Hero Member
  • *****
  • Posts: 6169
Re: event property will not create
« Reply #7 on: October 31, 2016, 05:38:13 pm »
In my opinion you should never use user-event-names in your baseform.
The IDE looks for a FormShow() in your hierarchy and will find that TFrmBase.ShowForm() and only get confused.

What is your purpose?
If you want something like this just override DoShow like this:
(but NEVER EVER use ShowForm() in the base-class)
Code: Pascal  [Select][+][-]
  1. type
  2.   TFrmBase = class(TForm)
  3.   protected
  4.     procedure DoShow; override;
  5. //..
  6. procedure TFrmBase.DoShow;
  7. begin
  8.   // inherited; DO NOT CALL INHERITED if you want to switch to either/either/
  9.   if Assigned(OnShow) then
  10.     OnShow(Self)
  11.   else
  12.     ShowMessage(self.name)
  13. end;

This will call the ShowMessage in the base-class if there is no OnShow assigned in the descendant.
Otherwise only the OnShow of the descendant is executed.
« Last Edit: October 31, 2016, 05:40:34 pm by rvk »

mangakissa

  • Hero Member
  • *****
  • Posts: 1131
Re: event property will not create
« Reply #8 on: October 31, 2016, 08:21:59 pm »
Okay I have to defend myself.

Normally the baseform has more components on form. When a new form is created (inherited from the baseform) all the GUI-components will be seen on form. But when code (Oncreate / onForm / onActivate / OnClose) on the baseform is put, the code will be used for all the inherited forms. This is very usefull when you use classes for all inherited forms. The baseform has the object and create / release it in memory. Every form calls the same code in baseform. Everybody knows that (I hope).

Now the inherited form does something more than using the objects. It can handle some other values for the form itself. Example.

baseform:
Code: Pascal  [Select][+][-]
  1. type TBaseform = class;
  2. begin
  3.   fFormname : string;
  4. end;
  5.  
  6. procedure TBaseform.Formcreate(Sender : TObject)
  7. begin
  8.   object1 := TObject.create;
  9.   object2 := TObject.create;
  10.   fFormname := name;
  11. end;
  12.  


inherited form:
Code: Pascal  [Select][+][-]
  1. procedure TInheritedform.Formcreate(Sender : TObject)
  2. begin
  3.   inherited;
  4.   object1.dosomething;
  5.   value := 'Hello';
  6. end;
  7.  
  8. procedure TInheritedform.showname;
  9. begin
  10.   //this is just an example of inheritence.
  11.   //I know that a formname can called directly
  12.   showmessage(fFormname)
  13. end;
  14.  

Now the real problem. Lazarus 1.6 doesn't create a local procedure when dubbleclick on the property in the objectinspector. I tested it in Lazaris 1.4 and that's working. The problem relies on 1.6. It's not a problem of the OS. Tested on Windows 10 gives the same results.
Lazarus 2.06 (64b) / FPC 3.0.4 / Windows 10
stucked on Delphi 10.3.1

totya

  • Hero Member
  • *****
  • Posts: 720
Re: event property will not create
« Reply #9 on: October 31, 2016, 08:32:40 pm »
I think everyone will be much happier, if you tell us, what is your concept. Many similar windows on the screen at once? What are the differents between these?

For example you can create form dinamically. Or you can use frames.

rvk

  • Hero Member
  • *****
  • Posts: 6169
Re: event property will not create
« Reply #10 on: October 31, 2016, 08:46:05 pm »
Okay I have to defend myself.
I do understand what you want now... (so you always want the FormShow of the base-class to execute.

But my stand remains... NEVER EVER use/create the OnCreate in the base-class. Use DoCreate for that. For OnCreate, use DoCreate. For OnShow, use DoShow. etc.
Then the descendant is free to assign a OnShow if it wants.

If you always want to execute the code in FormShow/FormDestroy you would use DoShow/DoDestroy.
Like this for you example:
Code: Pascal  [Select][+][-]
  1. type
  2.   TBaseform = class;
  3.   protected
  4.     procedure DoCreate; override;
  5.     procedure DoDestroy; override;
  6.   public
  7.     fFormname : string;
  8.   end;
  9.  
  10. procedure TBaseform.DoCreate;
  11. begin
  12.   object1 := TObject.create; // first create
  13.   object2 := TObject.create;
  14.   fFormname := name;
  15.   inherited; // then call inherited which in turn calls OnCreate for descendants
  16. end;
  17.  
  18. procedure TBaseform.DoDestroy;
  19. begin
  20.   object1.Free;
  21.   object2.Free;
  22.   inherited;
  23. end;

And in the descendant you can use the events:
Code: Pascal  [Select][+][-]
  1. procedure TInheritedform.Formcreate(Sender : TObject)
  2. begin
  3.   object1.dosomething;
  4.   value := 'Hello';
  5. end;
  6.  
  7. procedure TInheritedform.showname;
  8. begin
  9.   //this is just an example of inheritence.
  10.   //I know that a formname can called directly
  11.   showmessage(fFormname)
  12. end;

So the basic rule is don't mess with events (or assign them) in the base-class. Only use events in the last part on your form and in the IDE, not in base-classes. For base-classes you override the DoProcedures.
« Last Edit: October 31, 2016, 08:48:17 pm by rvk »

mangakissa

  • Hero Member
  • *****
  • Posts: 1131
Re: event property will not create
« Reply #11 on: October 31, 2016, 09:59:15 pm »
This discussion will not solve my problem.
Lazarus 2.06 (64b) / FPC 3.0.4 / Windows 10
stucked on Delphi 10.3.1

totya

  • Hero Member
  • *****
  • Posts: 720
Re: event property will not create
« Reply #12 on: October 31, 2016, 10:04:08 pm »
This discussion will not solve my problem.

and what is your problem? I asked this in reply #9. :)

rvk

  • Hero Member
  • *****
  • Posts: 6169
Re: event property will not create
« Reply #13 on: October 31, 2016, 10:46:40 pm »
This discussion will not solve my problem.
Ok. Solution: None (if you keep working with assigning events in base-classes).

Quote
When writing components, you should not use the event handlers to implement custom behaviour. Instead you should override the code calling these event handlers.
http://stackoverflow.com/questions/6020534/onclick-event-override
« Last Edit: October 31, 2016, 10:59:12 pm by rvk »

mangakissa

  • Hero Member
  • *****
  • Posts: 1131
Re: event property will not create
« Reply #14 on: November 01, 2016, 09:06:34 am »
I think everyone will be much happier, if you tell us, what is your concept. Many similar windows on the screen at once? What are the differents between these?

For example you can create form dinamically. Or you can use frames.
My example uploaded just tell my concept. All my forms are inherited from the baseform. Nothing is created dynamically but @designtime.
Frames are nice, but doesn't do inheritence of components.
 
But your all mistaking about the OnCreate event. I'm not talking about the constructor of the form, but of the property Oncreate of the object inspector. This is creating TForm1.formCreate(Sender : TObject) which will execute after the constructor. Many people thinks you override the constructor, but that's not true.  Constructor TForm1.Create(TheOwner: TComponent); is something different which I don't use (only with livebindings and objects in Delphi :D )

Something is broken in version 1.6. Version 1.4x is working fine.

I shall create a bug report.
« Last Edit: November 01, 2016, 09:08:30 am by mangakissa »
Lazarus 2.06 (64b) / FPC 3.0.4 / Windows 10
stucked on Delphi 10.3.1

 

TinyPortal © 2005-2018