Solved

Event handler using BitBtns or Btns

Posted on 1998-04-14
23
317 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
  • 11
  • 11
23 Comments
 
LVL 2

Expert Comment

by:Waldek
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 8

Expert Comment

by:ZifNab
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 8

Expert Comment

by:ZifNab
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Ok, works fine now, please send your email, then I send you an answer...
0
 
LVL 8

Accepted Solution

by:
ZifNab earned 10 total points
Comment Utility
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
Comment Utility
Hi Zif
Thanks! the project is working at the moment, but I'm still having some problems
Thanks
guerra
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

763 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now