Recent

Author Topic: Adding states to TShiftState for MouseInput.Click()  (Read 3563 times)

fatmonk

  • Sr. Member
  • ****
  • Posts: 252
Adding states to TShiftState for MouseInput.Click()
« on: July 25, 2016, 12:42:09 pm »
I must be having a stupid day today as I just can't get this to work...

I want to check the state of a couple of UI buttons to set the Shift or Ctrl state of a programmatic mouse button click.

Looking at MouseInput.Click() I can see that I need a TMouseButton, TShiftState and the coordinations to acheive what I want.

If I enter ssShift in as the TShiftState as follows:

Code: Pascal  [Select][+][-]
  1. MouseInput.Click(mbLeft,[ssShift],260,200);

or ssShift and ssCtrl:

Code: Pascal  [Select][+][-]
  1. MouseInput.Click(mbLeft,[ssShift,ssCtrl],260,200);

all works well.

Looking at these ssShift is a TShiftStateEnum so I assumed that TShiftState was an array of TShiftStateEnums.

I therefore tried the following:

Code: Pascal  [Select][+][-]
  1. var shiftStates: array of TShiftStateEnum;
  2.  
  3. if bControl.Down then shiftStates[Length(shiftStates)]:=ssCtrl;
  4. if bShift.Down then shiftStates[Length(shiftStates)]:=ssShift;
  5.  
  6. MouseInput.Click(mbLeft,shiftSates,Xpos,Ypos);
  7.  

but get the following error:

Error: Incompatible type for arg no. 2: Got "{Dynamic} Array Of TShiftStateEnum", expected "TShiftState"

So it seems that my array may not be the right way to go.

Where am I going wrong?

-FM

Thaddy

  • Hero Member
  • *****
  • Posts: 14393
  • Sensorship about opinions does not belong here.
Re: Adding states to TShiftState for MouseInput.Click()
« Reply #1 on: July 25, 2016, 12:46:13 pm »
These are sets. Look at the documentation for sets. Specifically include/exclude  and in ;) Your code is way over-complicated.
Should be something like:
Code: Pascal  [Select][+][-]
  1. var
  2.   ss:TShiftState =[];
  3. begin
  4. if bControl.Down then include(ss, ssCtrl);
  5. if bShift.Down then   include(ss, ssShift);
  6. ....
  7. end;
  8.  

Then you can use ss to pass the shiftstates. This is from memory, might have a little tweaking but about this should work.
« Last Edit: July 25, 2016, 12:57:21 pm by Thaddy »
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

Handoko

  • Hero Member
  • *****
  • Posts: 5159
  • My goal: build my own game engine using Lazarus
Re: Adding states to TShiftState for MouseInput.Click()
« Reply #2 on: July 25, 2016, 02:34:25 pm »
I prefer something like this:

Code: Pascal  [Select][+][-]
  1. ... ss := ss + [ssCtrl];
  2. ... ss := ss + [ssShift];

Mathematical notations are easier for my brain to digest.

Thaddy

  • Hero Member
  • *****
  • Posts: 14393
  • Sensorship about opinions does not belong here.
Re: Adding states to TShiftState for MouseInput.Click()
« Reply #3 on: July 25, 2016, 04:04:37 pm »
I prefer something like this:

Code: Pascal  [Select][+][-]
  1. ... ss := ss + [ssCtrl];
  2. ... ss := ss + [ssShift];

Mathematical notations are easier for my brain to digest.

Include, exclude and in actually are actually the correct mathematical notation for set operations given the limitations of ASCII7 (128 bit) .
There just not numerical notation. Just like Boolean mathematics differs in notation.

Plz reset your brain ;) 
Nah, but it is better to follow set notation: e.g. the whole concepts of "big data" and "nosql" are based on it.
The Pascal notation is verbose, but very close to the theory.
If you will look at the set operator documentation you will see there are more notational differences, like "><". 
« Last Edit: July 25, 2016, 04:18:45 pm by Thaddy »
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

fatmonk

  • Sr. Member
  • ****
  • Posts: 252
Re: Adding states to TShiftState for MouseInput.Click()
« Reply #4 on: July 25, 2016, 04:06:47 pm »
Thank Thaddy,

A bit of googling for set and include and exclude got me to exactly what you suggested.

If it looks like an array and quacks like an array... it might be an array or it might be a set  %)

-FM

 

TinyPortal © 2005-2018