Recent

Author Topic: [SOLVED] Issues with EpikTimer control  (Read 11186 times)

Rayvenhaus

  • Jr. Member
  • **
  • Posts: 70
Re: Issues with EpikTimer control
« Reply #15 on: October 20, 2016, 06:03:05 pm »
Your problem has already been answerted before, but you obviously did not catch the point because now you are seeking for a "valid development enviroment"...

Let me rephrase it: You don't start the EpikTimer. There is an "ET.Start" in InitTimer(), but InitTimer is not called. Put it into FormCreate.

But InitTimer contains another problem: your screenshot shows that you already have an Epiktimer on the form, created at designtime in the form designer of Lazarus. This is fine - but then you must not create it again at runtime. Since both instances have the same variable name ("ET") - one is in the form's published section (above "private"), the other one is for a global variable - you will create a memory leak here because you will overwrite the designtime created instance by the one created at runtime in the InitTimer procedure; the global instance will never be created.

Is this what you mean?

Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. begin
  3.   ET := TEpikTimer.Create(Application);
  4.   ET.Start;
  5. end;          
  6.  

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: Issues with EpikTimer control
« Reply #16 on: October 20, 2016, 06:10:36 pm »
There's no ET.Create() call anywhere in the code you provided.
That is because visual components (visually designed and) placed on a form are created automatically for you (and destroyed as well).

Quote
Course I'm a newbie so I'm still learning but what you provided didn't work on my system.
Yes, i spotted the 'error'  :)

Quote
I've included the entire project as an earlier attachment if you want to look at it.
Sorry. I had the impression you know how events work but, apparently this is not entirely clear for you (yet).

Would i have know then i would have attached my complete example. My apologies for that and for any confusion that might have caused.

Your lfm file that is part of the project that you uploaded shows me that the form does not has the create event attached. That means you most probably manually added:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. begin
  3. ...
  4. end;
  5.  
To you form unit.

This is not correct.
(do note i am guessing there about the reason. It might as well be that you accidentally removed it after following described steps).


You should use the object inspector for that. If you click on the form in the object inspector you can press the tab where it reads events.

You will then presented with a list of events. You are looking for the vent named "OnCreate'. There is a editbox after that name. Double click on that to let the object inspector automatically create a) the event for you and b) connect the visual event to actually execute your procedure TForm1.FormCreate().
« Last Edit: October 20, 2016, 06:15:12 pm by molly »

Rayvenhaus

  • Jr. Member
  • **
  • Posts: 70
Re: Issues with EpikTimer control
« Reply #17 on: October 20, 2016, 06:20:23 pm »
Thank you SO much for the patience and understanding Molly. That did it! The counter now count up and I see a little better, how events work and what I can do. This has been a learning experience and I appreciate it very much./

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: Issues with EpikTimer control
« Reply #18 on: October 20, 2016, 06:31:24 pm »
Is this what you mean?

Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. begin
  3.   ET := TEpikTimer.Create(Application);
  4.   ET.Start;
  5. end;          
  6.  
Just to make sure, I was referring to the code in the very first post which did not have the ET.Start in FormCreate, but in InitTimer which was never called.

Rayvenhaus

  • Jr. Member
  • **
  • Posts: 70
Re: Issues with EpikTimer control
« Reply #19 on: October 20, 2016, 07:15:36 pm »
Is this what you mean?

Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. begin
  3.   ET := TEpikTimer.Create(Application);
  4.   ET.Start;
  5. end;          
  6.  
Just to make sure, I was referring to the code in the very first post which did not have the ET.Start in FormCreate, but in InitTimer which was never called.

I understand now and I thank you for your answers.  :D I didn't make the connection until Molly explained events. 

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: Issues with EpikTimer control
« Reply #20 on: October 20, 2016, 07:38:21 pm »
Thank you SO much for the patience and understanding Molly.
No problem. Thank you for your patience as well. It must have been more frustrating for you then for us.

Quote
That did it! The counter now count up and I see a little better, how events work and what I can do.
At least it is a good proof of why it is important to add your .lfm file in case of such 'problems'. A quick look at that contents of that file immediately exposed the culprit.

What you did with this specific example is visually designing your application. It relieves you from the manual job of creating and destroying components manually (and setting their properties to appropiate values).

The other example that you showed (in your reply #7) is what is called "on-the-fly" or 'runtime" component creation. Usually referred to as dynamic creation of components.

With dynamic component creation you have to have a variable to store an instance of the dynamically created component, create a new instance and assign all it's properties and events manually (as also shown in your example in reply #7).

Seems simple enough ?

Then please notice that components such as TTimer and TEpiktimer are actually refered to as being non-visual components (even though you created them visually by placing the components on your form).

There are many of such non-visual components for which it usually makes no sense to have them in a visual form, other than it is very convenient because you are then able to set the properties and events of the components at designtime using the object inspector. Such components do not have an actual visual representation for the user  (other then the squared button you see on your form during design-time). The squared button for non-visual components are not visible when a program is executed (runtime).

Components such as a TLabel or a TEdit are 'real' visual components in that they actually display a visual shape on your form (a text in case of a TLabel component and, an actual edit input box in case of a TEdit component).

Both visual and non-visual components can be created 'visually' using the form designer as well as created dynamically.

You usually choose what is most convenient for your situation.

And to get back to topic. In your first example you were trying to mix visual design with dynamic creation. There is nothing wrong with doing so, but in that case it is very advisable to not name the variables (that actually hold the instance of your component) the same. It causes a lot of confusion depending on the scope of your code.

So, taking a look at your very first post  it would have been better to name your variable to store the dynamic created version of the epiktimer component a bit differently.

Quote
This has been a learning experience and I appreciate it very much./
I have attached an example based on that from your first post, showing usage of both the visual designed epiktimer as well as a dynamic created epiktimer.

Well, all i can advise is to have some fun !  :)

Rayvenhaus

  • Jr. Member
  • **
  • Posts: 70
Re: Issues with EpikTimer control
« Reply #21 on: October 20, 2016, 08:09:15 pm »
Thank you Molly. That explanation did a lot for me in helping me understand how things work. And no, to be honest, it wasn't frustrating at all, I'm asking for, and getting free help. I know you guys do this because you want to, not because you're getting paid for it.  And the fact that you've provided me with an answer AND a learning experience is way more than I expected.

Thank you again!

RAW

  • Hero Member
  • *****
  • Posts: 868
Re: Issues with EpikTimer control
« Reply #22 on: October 20, 2016, 10:42:28 pm »
Quote
From that, it is pretty clear to me that it is a stopwatch timer component. Plus the fact that it has no events defined (eg: no OnTimer events).
Hi Graeme, maybe that's the fact why I used a second timer to periodically display the information from the first "Timer"... and yes I know that it is a good idea to take a look inside the unit...

The only thing that I forgot: Using three of these  :P  :P  :P  to make sure that this is a joke !!! I thought one is enough to point it out...


Of course the inventor of EpikTimer can name his component as he wishes... and of course it's very kind of him to let everybody use it ... btw. thanks to "I can't remember your Name (Inventor of EpikTimer)"... very nice....
Windows 7 Pro (x64 Sp1) & Windows XP Pro (x86 Sp3).

Graeme

  • Hero Member
  • *****
  • Posts: 1428
    • Graeme on the web
Re: Issues with EpikTimer control
« Reply #23 on: October 21, 2016, 12:31:21 am »

The only thing that I forgot: Using three of these  :P  :P  :P  to make sure that this is a joke !!!
I did see the first one, but just wanted to get the point across.   

[humour, sarcasm, emotions etc are often lost in emails]


Quote
btw. thanks to "I can't remember your Name (Inventor of EpikTimer)"... very nice....
Again, it is listed in the unit comment of the epiktimer.pas unit.  :P
--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

Graeme

  • Hero Member
  • *****
  • Posts: 1428
    • Graeme on the web
Re: Issues with EpikTimer control
« Reply #24 on: October 21, 2016, 12:47:07 am »
I've also been looking at that and can not find a way to subtract and format a TDateTime string. I really like the Format that EpikTimer uses of ddd.hh.mm.ss.

WP explained it pretty well already, but here is a simple example:

Code: Pascal  [Select][+][-]
  1. var
  2.   lStart: TDateTime;
  3.  
  4. { somewhere in the beginning of your application. eg: a OnCreate or OnShow event handler. }
  5.   lStart := Now;
  6.  
  7. { Now in your TTimer's OnTimer event handler do the following... }
  8.    SomeLabel.Caption := FormatDateTime('HH:nn:ss.zz', Now - lStart);
  9.  

That should output the hours, minutes, seconds and milliseconds that your application has been running. If your application is going to be running for longer than 24 hours, I suggest you look at the functions available in the dateutils unit. Use the DaysBetween() function. If you want more precision output, then take a look at EpikTimer's EllapsedDHMS() function (around line 523), and modify it slightly to suit your needs.
--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

RAW

  • Hero Member
  • *****
  • Posts: 868
Re: Issues with EpikTimer control
« Reply #25 on: October 21, 2016, 02:03:36 am »
 
Quote
Again, it is listed in the unit comment of the epiktimer.pas unit.  :P
:D
Windows 7 Pro (x64 Sp1) & Windows XP Pro (x86 Sp3).

 

TinyPortal © 2005-2018