Recent

Author Topic: Maybe I can't Do This or don't how?  (Read 2790 times)

JLWest

  • Hero Member
  • *****
  • Posts: 1293
Maybe I can't Do This or don't how?
« on: December 14, 2018, 06:42:09 am »
 
I have a listbox and I'm trying to code the dblclick event in the listbox to call another button on the screen as if the user clicked on the button. Needless to say neither call worked;

procedure TForm1.ListBox1DirDblClick(Sender: TObject);
 begin
 // lstbox2LoadClick;
  lstbox2LoadClick(Sender: TObject);

 end

procedure TForm1. btnloadClick (Sender: TObject);
 
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

balazsszekely

  • Guest
Re: Maybe I can't Do This or don't how?
« Reply #1 on: December 14, 2018, 06:48:07 am »
Try this:
Code: Pascal  [Select][+][-]
  1. type
  2.   TForm1 = class(TForm)
  3.     btnLoad: TButton;
  4.     ListBox1: TListBox;
  5.     procedure btnLoadClick(Sender: TObject);
  6.     procedure ListBox1DirDblClick(Sender: TObject);
  7.   private
  8.   public
  9.   end;
  10.  
  11. //...
  12.  
  13. procedure TForm1.btnLoadClick(Sender: TObject);
  14. begin
  15.   ShowMessage('OK');
  16. end;
  17.  
  18. procedure TForm1.ListBox1DirDblClick(Sender: TObject);
  19. begin
  20.   btnLoadClick(btnLoad);
  21. end;

JLWest

  • Hero Member
  • *****
  • Posts: 1293
Re: Maybe I can't Do This or don't how?
« Reply #2 on: December 14, 2018, 07:15:38 am »
Can't get this to work. Something I'm doing wrong.

Need to do a program to figure it out.

Get back to this tomorrow.late here.
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Maybe I can't Do This or don't how?
« Reply #3 on: December 14, 2018, 02:29:42 pm »
Another possible way, using TButton.Click:
Code: Pascal  [Select][+][-]
  1. type
  2.   TForm1 = class(TForm)
  3.     btnLoad: TButton;
  4.     ListBox1: TListBox;
  5.     procedure btnLoadClick(Sender: TObject);
  6.     procedure ListBox1DirDblClick(Sender: TObject);
  7.   private
  8.   public
  9.   end;
  10.  
  11. //...
  12.  
  13. procedure TForm1.btnLoadClick(Sender: TObject);
  14. begin
  15.   ShowMessage('OK');
  16. end;
  17.  
  18. procedure TForm1.ListBox1DirDblClick(Sender: TObject);
  19. begin
  20.   btnLoad.Click;
  21. end;
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

Zvoni

  • Hero Member
  • *****
  • Posts: 2315
Re: Maybe I can't Do This or don't how?
« Reply #4 on: December 14, 2018, 02:35:56 pm »
Why not just assign the btnloadclick-procedure as the event for the OnDblClickk-event in the events-list of the listbox?
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

HeavyUser

  • Sr. Member
  • ****
  • Posts: 397
Re: Maybe I can't Do This or don't how?
« Reply #5 on: December 14, 2018, 02:58:32 pm »

I have a listbox and I'm trying to code the dblclick event in the listbox to call another button on the screen as if the user clicked on the button. Needless to say neither call worked;

procedure TForm1.ListBox1DirDblClick(Sender: TObject);
 begin
 // lstbox2LoadClick;
  lstbox2LoadClick(Sender: TObject);

 end

procedure TForm1. btnloadClick (Sender: TObject);

Code: Pascal  [Select][+][-]
  1. procedure TForm1.ListBox1DirDblClick(Sender: TObject);
  2.  begin
  3. // lstbox2LoadClick(listbox1); // or better yet
  4.   lstbox2LoadClick(nil);        // this will give you a way check if the call comes from a control or it comes from your own code.
  5.  end
  6.  

JLWest

  • Hero Member
  • *****
  • Posts: 1293
Re: Maybe I can't Do This or don't how?
« Reply #6 on: December 14, 2018, 07:04:04 pm »
Got it.

I tried both and both work.

//   btnLoadFlightFilesClick( btnLoadFlightFiles);
      btnLoadFlightFilesClick( Nil);


I don't think I understand this one.

"Why not just assign the btnloadclick-procedure as the event for the OnDblClickk-event in the events-list of the listbox? "

 Would I put  btnLoadFlightFilesClick(Sender : TObject)

       
Thank You for the help.

Oh by the way, I just don't take the fix, install it and move on.

I have a CodeLib directory on my Storage Drive F: Under CodeLib I have 56 sub-directories with answers to question I have asked on the form.

Some of the sub-directories have example programs. If an example program is in a sub-directory its zipped but there is a text file of the code.

In this case I have a sub-directory of ListBox DblClick Event. And in the sub-directory I have ListBoxDblClickEvent.txt with the source code of the example file.

In addition I have a Pascal program that will locate, view and allow copying of code segment of the CodeLib system.

But they have books for all of that and it's all on the Web. Yep, but in my case I have it in 36 pt font. Which I can read. Ctl-Scrool wheel will enlarge some things but not every thing. MS Explorer is kind of a blur no matter what I do. The mouse icon, you know the tiny arrow can get lost. So I go to the lower left corner of the screen to find it.

 






FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: Maybe I can't Do This or don't how?
« Reply #7 on: December 15, 2018, 02:06:10 am »
The mouse icon, you know the tiny arrow can get lost. So I go to the lower left corner of the screen to find it.

If you go to Control Panel - Mouse - Pointer Options you will find at least two options to help you find the mouse pointer:
1-Show location of pointer when I press the CTRL key.
2-Display pointer trails.

The location of the these options might be slightly different on your Windows.

Zvoni

  • Hero Member
  • *****
  • Posts: 2315
Re: Maybe I can't Do This or don't how?
« Reply #8 on: December 15, 2018, 03:18:55 pm »
I don't think I understand this one.

"Why not just assign the btnloadclick-procedure as the event for the OnDblClickk-event in the events-list of the listbox? "

In Form-Designer design your Form (e.g. put a Button and a Listbox on it).
click on your Button for it to get the focus.
Go to the Properties-Panel, there on the Events-Tab, look for the OnClick-Event, mark it, then click on the Button with 3 dots "..." to create the default-Procedure for that event.
Write the code for the Button-Click-Event.
After that done, click on your Listbox, go to properties-panel, there on the Events-Tab, look for the OnDblClick-Event, but instead of clicking on the 3-dot-button you click on the dropdownlist there.
There now should be your Button-Click-Procedure to choose.
Choose it.
Done!
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

 

TinyPortal © 2005-2018