Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Event handler using BitBtns or Btns

Posted on 1998-04-14
23
Medium Priority
?
325 Views
Last Modified: 2010-04-06
Hi
I am using three inputBox with three btns and three labels, in the btns procedure
I put the " label1.Caption:=('Edit form','Enter the steps',''); and the result is a form
where I can put whatever I want that will be display in the label. And what I want is
to put in some integers in the inputbox and after using a bitbtn or a btn send
this integer  to somewhere in my case is the printer port. For example for the btn1
I put 132, for the btn2 I put 100, and for the btn3 i put10, and after clicking in the
 OkBtn(BitBtn) and all these values are going straight to the printer port.
For the Btn1 all the information will send to the pins 2 in the printer port, btn2 the
information is sending to the pin 4 and for the btn3 is sending to the pin5..
Any advice about this........
Thanks
Guerra
.
Any advice to this
Thanks
Guerra
0
Comment
Question by:guerra
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 11
  • 11
23 Comments
 
LVL 2

Expert Comment

by:Waldek
ID: 1361485
If I good understand You , You may set tag property for all components end in event handler test for
 if Sender as TBitBtn then
  case tag of
  1:
  2:
  3:
  end;
0
 

Author Comment

by:guerra
ID: 1361486
Hi Waldek
You say, that  using Tag property,can you specify more I don't know how can I put that in the form; 1:   whats mean?
              2:
              3:
0
 

Author Comment

by:guerra
ID: 1361487
Hi Waldek
I tried into the BitBtn procedure the next text;
if Sender as TbitBtn then   {in this line I've got and error; type of expression must be boolean}
case tag of
1:
2:
end;
Any idea how can I solve the problem or any other suggestions
Thanks
Guerra
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 8

Expert Comment

by:ZifNab
ID: 1361488
Hi guerra,

If you want to try Waldek's suggestion do this :

Case (Sender as TbitBtn).Tag of
1:
2:
end;

Or you can use
If Sender is TBitBtn then
 Case (Sender as TBitbtn).Tag of
 1:
 2:
 end;

Regards, Zif.
 
0
 

Author Comment

by:guerra
ID: 1361489
Hi  Zif
What you say it is working, but I want to know what' mean the numbers 1: and 2:,
they have any relationship with the button 1 and 2.
Thanks
Guerra
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1361490
Hi guerra,

sorry not answer you correctly, (it's because I haven't read the whole thread, sorry, but I want to read all the threads I've mist till know and that are quit a lot)

What Waldek proposes is that you enter some number in the tag property... Every component has a tag property and then you put in the case structure those numbers and next each number the proper code (like sending to pin 1 ...).

But, reading your question, I can't figure our what you really want... :

What can the user do and what has to happen when the user pushes on the OK button?

Regards, Zif.

 

0
 

Author Comment

by:guerra
ID: 1361491
Hi Zif
Sorry if you don't understand the question, What I am trying to do is; I put three number
into a inputBox for three differents btns, and when I press for example the OK Btn all
these values are going straight to the printer port,  I know how I can send some constants
to the printer port, I've already done the program, but what I am trying to do is to change those constants for other using the inputBox. ( I think this way looks nice).
Any suggestions about it, or other methods to do it
Thanks
Guerra
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1361492
Hi Guerra,

That's not so difficult :

1) You know your input boxes : Let's say you give them following names :

     InputBox1, InputBox2 and InputBox3

2) You push the OK button :

3) You can get the values of the inputboxes by the property Text (the normal Delphi components)
   So InputBox1.Text is the value entered by your user!
   InputBox1.Text is of type string! To get it to a float or integer do this

var
   Floatnr : Real;
   Integernr : LongInt;

  Floatnr := StrToFloat(InputBox1.Text);
  Integernr := StrToInt(InputBox1.Text);

That's all!

Regards, Zif.
0
 

Author Comment

by:guerra
ID: 1361493
Hi Zif
Thanks, I am trying your solution and I've got some error messages, I am doing  
the next program and the point is using the OkBtn send the values of the inputboxs to the OUT procedure;
If you can see some solution or any change, let me know.
I have to go
Thanks
Guerra
unit Unit2;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Buttons, StdCtrls;

type
  TForm2 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Label1: TLabel;
    Label2: TLabel;
    Button3: TButton;
    BitBtn1: TBitBtn;
    procedure Button3Click(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form2: TForm2;
   var
   Floatnr:Real;
   integernr:longint;
implementation
procedure Out(Portaddress:smallint;Value;smallint);stdcall;external 'unit1'
{$R *.DFM}

procedure TForm2.Button3Click(Sender: TObject);
begin
  close;
end;

procedure TForm2.BitBtn1Click(Sender: TObject);
   property text
   inputBox1.Text;
   inputbox2.Text;
   Floatnr:=StrToFloat(InputBox1.Text);
   Integernr:=StrToInt(inputbox2.Text);
begin

end;

procedure TForm2.Button1Click(Sender: TObject);
begin
  label1:=inputbox1('Enter form','Enter value','');
end;

procedure TForm2.Button2Click(Sender: TObject);
begin
  label2:=inputbox2('enter form','Enter value','');
end;

end.
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1361494
Mmmm. I can't get out of you code, but let me give you an example :

Put following on the form, three Tbuttons, two TEdits (InputBox1, InputBox2)

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    InputBox1: TEdit;
    InputBox2: TEdit;
    OkButton: TButton;
    procedure OkButtonClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.OkButtonClick(Sender: TObject);
begin
 // here you normally use your out procedure.
 Showmessage('Text in inputbox1 :'+InputBox1.Text);
 Showmessage('Text in inputbox2 :'+InputBox2.Text);
end;

end.

Euhm, why do you need the buttons next to the editboxes?

Regards, Zif.

0
 

Author Comment

by:guerra
ID: 1361495
hi Zif
Thanks for your solution, really I don't need the buttons near the edit, only I use them because I want to separate the two different input boxes (It isn't important), for two diferents motors or movement(clokwise and counterclockwise);
this is my principal program and what I am trying to do in change the input values, put some edit boxes where i can put new values in the program .
Please have a look of the program below:
Thanks
Guerra
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    front: TButton;
    rear: TButton;
    Close: TButton;
    procedure CloseClick(Sender: TObject);
    procedure frontClick(Sender: TObject);
    procedure rearClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  const
  front=12;
  rear=10;
implementation
 procedure Out1(portaddress:smallint;Value:smallint)Stdcall;external 'output1'
{$R *.DFM}

procedure TForm1.CloseClick(Sender: TObject);
begin
  close;
end;

procedure TForm1.frontClick(Sender: TObject);
begin
  Output1($378,front);
end;

procedure TForm1.rearClick(Sender: TObject);
begin
 Output1($378,rear); {Iwant to substitute the rear for some input
                      values from an edit box }

end.
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1361496
Hi guerra,

 Ok then do this :

 Add an editbox for your rear value : name it EditRear
 Add an editbox for your front value : name it EditFront



       procedure TForm1.frontClick(Sender: TObject);
       begin
         Output1($378, StrToInt(Editfront.Text));
       end;

       procedure TForm1.rearClick(Sender: TObject);
       begin
        Output1($378,StrToInt(Editrear.text));
       end;

PS. Doesn't Output1 has to be Out1?

PPS. Look out the program expects numbers! in input boxes. If you enter chars you will get an error! And only integer values!
But this you can change when you want it to change....

Regards, ZiF.
0
 

Author Comment

by:guerra
ID: 1361497
Hi Zif
Thanks again, I want to send some bytes, so I put in the var (Tedit:byte), and another thing, if a use only one btn to handle the two edit boxs, how can i do that?
Thanks
Guerra
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1361498
Hi Guerra,

One button :

         procedure TForm1.buttonClick(Sender: TObject);
              begin
                Output1($378, StrToInt(Editfront.Text));
                Output1($378, StrToInt(Editrear.text));
              end;

Regards, Zif.

0
 

Author Comment

by:guerra
ID: 1361499
hI ZIF
I did that, thanks, but I runned the program and Ive got some error ( I think) how you can see in the program I send the information to a procedure output1,this procedure is specified in a program done in DLL in this program I am sending a var (ByteValue:Byte)
......is this var interfering with the editbox in some way?.................
What  do you think about it?
Regards
Guerra
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1361500
Hi guerra, I guess yes.

Because we are sending an integer value... not a byte... And integer is bigger then byte...

So try it this way ....

procedure TForm1.buttonClick(Sender: TObject);
var DummyByte : Byte;
  begin
   DummyByte :=StrToInt(Editfront.Text);
   Output1($378, DummyByte);
   DummyByte :=StrToInt(Editrear.Text);
   Output1($378, DummyByte);
  end;

regards, zif.
0
 

Author Comment

by:guerra
ID: 1361501
Hi Zif
The program is working.I am sending bytes to the printer port. I connected the PC with an oscilloscope and efectively some signal is coming up, but in my case I am trying to drive
three stepper motors which are connected in differents position in the printer port, and my problem now is how i can put some delay in the signals, I mean, send the bytes in different time..
Any suggestion to this
Regards
Guerra
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1361502
Q : You get all information for driving the motors at once
      You push Ok button
      Three motors have to be driven?
 
A : To make a pause between sending the commands use this piece of source :

Delay, pause, wait


How do you get your Delphi app to do nothing for a period of time?
A:
Uses
     ....
     Winprocs
     ....;

Procedure delay(millisecs : longint);   { delay for given milliseconds }
var
     endtime   : longint;
begin
     endtime := gettickcount + millisecs;
     while endtime - gettickcount < 0 do
          Application.ProcessMessages;
     end; { delay }

A:
procedure Wait;
var oldTime: LongInt;
begin
  oldTime := GetCurrentTime;
  repeat
   { whatever}
  until GetCurrentTime - oldTime >= yourDelay;
end;

To which I would add:

As current Windows does not have pre-emptive multi-tasking,
it's normally good event-handling manners to allow Windows
to jump in to the gap, so the { whatever } above should
usually read:

          Application.ProcessMessages;


A:
Procedure Delay(DTime : LongInt);
Var
  L : LongInt;
Begin
  L := GetTickCount;
  While (Abs(L-GetTickCount) < DTime) do;
End;

The usage is "Delay(1000'th of a second)", for example
Delay(5000) will wait 5 seconds.

Regards, Zif.
0
 

Author Comment

by:guerra
ID: 1361503
Hi Zif
The procedures Delay will be in the implementation app isn't? For the three motors I need to set the direction of movement(clockwise or counterclockwise) and the clock which is defined for the delay procedure, I thought to put 2 radiobtns for the direction, but I've got problem in handle'm, how can I do that?
Another thing; for the motors I need to put the number of steps(1.8 degr for step) which they will move,then I want to move the motor the number os steps put in the box).So using edit boxes to enter the values and after in the clickBtn put some loop like( for i=1 to value in the editbox do Out1(&378,byte which put some voltage out,e.g.125), I've done that but nothing happen, only I've got voltage out.I am right or not?
Thanks
Guerra
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1361504
Am I helping you with a work for school? Looks like a thing I've done when I was in colluege....

I've problems to give answers, so I'll try to post this one first. If everything works out fine, I'll help you further....

PS. I'm not the only one who has problems with Exp-Exch (so is inter) this day can you leave a message at the webmasters? I can't even make a connection with there mail server....

Regards, Zif.
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1361505
Ok, works fine now, please send your email, then I send you an answer...
0
 
LVL 8

Accepted Solution

by:
ZifNab earned 40 total points
ID: 1361506
Hey Guerra, I'm waiting! I can send source to here, but then we've maybe problems understanding each other... If I send you a project you have everything at once...

I'm also answering this one, because the initial question is solved, I guess..

ZiF.
0
 

Author Comment

by:guerra
ID: 1361507
Hi Zif
Thanks! the project is working at the moment, but I'm still having some problems
Thanks
guerra
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question