Recent

Author Topic: Procedure without an Object  (Read 7423 times)

jb007

  • Full Member
  • ***
  • Posts: 145
Procedure without an Object
« on: April 14, 2017, 09:50:02 pm »
Hi!

First some things I use and understand!

An Object is placed on a forum and this Object got its Properties and Events.
This all is working fine and I mostly use the "OnClick".

In that option you can open a list so you can chose a Event (Procedure).

This means that Button1-onClick can use an event from e.g. Button2 etc etc...


In my programm I'm using procedures WITHOUT atached to an Object;
These procedures I can easely 'call' from anny where in my code, for example


procedure myCode; forward;
.
.
procedure myCode;
begin
   // code
end;
.
.
procedure TFMain.Button1Click(Sender: TObject);  // start COM
begin
  // code
  myCode;
end;

THIS WORKS FINE!


But how do I call an event in myCode?

Like this:

procedure myCode;
begin
   tfmain.button4.onClick.button4click;  // how to?
end;

Tried different other things like:
button4.onclick
etc etc...

Or should I just easely use invisible Objects?
So I can always choose an event from the list by onClick (or whatever).

Thansk in advance! Macel.






to DIY or not to DIY

lainz

  • Hero Member
  • *****
  • Posts: 4460
    • https://lainz.github.io/
Re: Procedure without an Object
« Reply #1 on: April 14, 2017, 09:59:23 pm »
You can place new methods inside the class of TForm1 for example.
Then you can choose them from the list in the Object Inspector.

But answering your question, is like this:

Code: Pascal  [Select][+][-]
  1. procedure test();
  2. begin
  3.   Form1.Button1Click(nil);
  4. end;

But is not recommended, better add a new method in the class.

Go to here, private declarations:
Code: Pascal  [Select][+][-]
  1. TForm1 = class(TForm)
  2.     Button1: TButton;
  3.     procedure Button1Click(Sender: TObject);
  4.   private
  5.     { private declarations }
  6.   public
  7.     { public declarations }
  8.   end;

then type
procedure test();

and Ctrl + Shift + C

It will create automatically
Code: Pascal  [Select][+][-]
  1. procedure TForm1.test;
  2. begin
  3.  
  4. end;  


There you can call like this:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.test;
  2. begin
  3.   Button1Click(nil);
  4. end;
   

jb007

  • Full Member
  • ***
  • Posts: 145
Re: Procedure without an Object
« Reply #2 on: April 15, 2017, 11:49:40 am »
Thanks!

I was  a bit in the right direction but I deffinitly needed your help!

But somehow I have to use:

private
  { private declarations }
  procedure myCode;
           
implementation 

procedure TForm1.myCode;
begin
  button4click(nil);
end;



instead of:


private
  { private declarations }
  procedure TForm1.myCode;
           
implementation 

procedure TForm1.myCode;
begin
  button4click(nil);
end;







to DIY or not to DIY

lainz

  • Hero Member
  • *****
  • Posts: 4460
    • https://lainz.github.io/
Re: Procedure without an Object
« Reply #3 on: April 15, 2017, 07:09:16 pm »
That's because TForm1 is the name of the class. Then you need to specify only the method name, not the class name again. Different is in the body of the method that must have the class name on it always.

jb007

  • Full Member
  • ***
  • Posts: 145
Re: Procedure without an Object
« Reply #4 on: April 16, 2017, 07:31:08 pm »
Tnx, lainz!
to DIY or not to DIY

jb007

  • Full Member
  • ***
  • Posts: 145
Re: Procedure without an Object
« Reply #5 on: May 01, 2017, 08:27:38 pm »
Things improve rapidly!

Controlling an ArduinoMega's TimerCounter/PWM by RS232!

Oscilloscope Video: https://www.youtube.com/watch?v=Ho0_UuN-0nk

Screenshot Lazarus:
to DIY or not to DIY

sky_khan

  • Guest
Re: Procedure without an Object
« Reply #6 on: May 01, 2017, 11:03:44 pm »
Why dont you use actions ?

Use TActionList* to define your user actions then you can bind them to (multiple) menu items and/or buttons and/or other components which have "Action" property.
And you can manually call them as "myAction.Execute;" wherever you like.

*last item on standard tab

Remy Lebeau

  • Hero Member
  • *****
  • Posts: 1312
    • Lebeau Software
Re: Procedure without an Object
« Reply #7 on: May 02, 2017, 01:30:40 am »
But answering your question, is like this:

Code: Pascal  [Select][+][-]
  1. procedure test();
  2. begin
  3.   Form1.Button1Click(nil);
  4. end;

Alternatively, call the TButton.Click() method, and let it call the OnClick handler if one is assigned:

Code: Pascal  [Select][+][-]
  1. procedure test();
  2. begin
  3.   Form1.Button1.Click;
  4. end;

But is not recommended, better add a new method in the class.

It would be best to de-couple your business logic from your UI code, eg:

Code: Pascal  [Select][+][-]
  1. TForm1 = class(TForm)
  2.   Button1: TButton;
  3.   Button4: TButton;
  4.   procedure Button1Click(Sender: TObject);
  5.   procedure Button4Click(Sender: TObject);
  6. private
  7.   { private declarations }
  8. public
  9.   { public declarations }
  10.   procedure DoSomething;
  11. end;
  12.  
  13. procedure myCode;
  14. begin
  15.   Form1.DoSomething;
  16. end;
  17.  
  18. procedure TFMain.Button1Click(Sender: TObject);
  19. begin
  20.   myCode;
  21. end;
  22.  
  23. procedure TFMain.Button4Click(Sender: TObject);
  24. begin
  25.   DoSomething;
  26. end;
  27.  
  28. procedure TFMain.DoSomething;
  29. begin
  30.   // code here
  31. end;
  32.  
« Last Edit: May 24, 2017, 09:03:37 pm by Remy Lebeau »
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

jb007

  • Full Member
  • ***
  • Posts: 145
Re: Procedure without an Object
« Reply #8 on: May 02, 2017, 08:48:49 pm »
Thank y'all!

Sure, I will keep your suggestions that in mind.

At the moment busy coding mikroPascal. Lazarus proceed in a couple of day.

Marcel.



to DIY or not to DIY

jb007

  • Full Member
  • ***
  • Posts: 145
Re: Procedure without an Object
« Reply #9 on: May 24, 2017, 08:31:08 pm »
Still, a tough job for me that Lazarus...

Got my robotarm running in TurboPascal7.0 before!

The technical stuf ( steppercontrol, kinematics, curve-determination, interpolation etc is not the big deal...but to get it nice and smooth in Lazarus keeps me sweating...
( in TurboPascal it looked almost easy )

But things improve! Regards. Marcel.



PWM, first setup:
( I'm improving the code to get 1Hz acuratecy, etc)


https://www.youtube.com/watch?v=uT4BkUJiymc



Unfortunately, can't find a screenshot from robotprogramm in TturboPascal7.0, but is 'simulair'to the screenshot of my CNC/Mill program:



 
« Last Edit: May 24, 2017, 08:49:00 pm by jb007 »
to DIY or not to DIY

jb007

  • Full Member
  • ***
  • Posts: 145
Re: Procedure without an Object
« Reply #10 on: May 24, 2017, 08:52:14 pm »
And for those who areinterested in all of my project, just watch:

http://europakade.nl/motion-control-and-robots

All regards.
to DIY or not to DIY

avra

  • Hero Member
  • *****
  • Posts: 2514
    • Additional info
Re: Procedure without an Object
« Reply #11 on: May 26, 2017, 10:07:22 am »
If you want to achieve more natural robotic arm moves then you may consider Wiimote and/or Nanchuck instead of quadpad. You can integrate it on bluetooth level with PC, or on I2C level with your mikroPascal application. Besides live robotic arm control with it, you might also want to record your hand natural moves and then later replicate them on your robotic arm for some situations. Just search the net and you will find plenty of Wiimote projects online.
https://en.wikipedia.org/wiki/Wii_Remote
« Last Edit: May 26, 2017, 10:09:49 am by avra »
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

jb007

  • Full Member
  • ***
  • Posts: 145
Re: Procedure without an Object
« Reply #12 on: May 29, 2017, 08:55:39 pm »
Thanks!

For the moment I concentrate on the robot itself, have to improve the DATA-stream between pc-Lazarus and Arduino-mikroPascal. Gonna aproach it from another angle of view. Idea is:

Sending in 1 string a Command, a Selector(s) and Value(s);
The Arduino has to respond and/or execute the Comand etc...

And also to implement something like Mode, e.g. when the robot is running by pc controll only, I don't need to read/process the ADC/QuadSticks. Onward: in 'mode' of using Quadstick, the can be done in multiple ways, e.g. controlling a joint single, or move the robot-endeffector on x, y, z coordinates etc..

 


to DIY or not to DIY

jb007

  • Full Member
  • ***
  • Posts: 145
Re: Procedure without an Object
« Reply #13 on: May 30, 2017, 11:36:18 am »
Gonna aproach my Arduino from a different point ( "watching" from pc-Lazarus ) when it comes to RS232 communication! Maybe this will give me more clearness and understanding.

A bit in the same way as I'm allready  programing my Arduino itself and from there on I "communicate" with ADC-UNIT, PWM-UNIT etc.

I mean: I send COMMAND/UNITnumber/DATA to ADC-UNIT/PWM-UNIT  and they "proces" the command/unit/data on their own! later I can, by "command etc" read the registers/values etc etc.

Gotta to this in the same way at pc-Lazarus-side from/to Arduino-mikropAscal.
A command from pc-Lazarus can be a write(e.g: move a stepper OR read instructrion ( e.g: read ADC).

And give my Arduino some registers wich can be acces by pc-Lazarus!


Have to do this before contueing the "actual robot code", it will make thing more clear!
 




to DIY or not to DIY

jb007

  • Full Member
  • ***
  • Posts: 145
Re: Procedure without an Object
« Reply #14 on: May 30, 2017, 08:24:40 pm »
A part of the data is boolean, so I can send 8 booleans in 1 byte! Saves data and time.


At receive-side, I easely retract the desirered boolean ( bit out of byte ).
to DIY or not to DIY

 

TinyPortal © 2005-2018