1
votes

Program use on touch screen Windows-tablet. Have a grid, where we need to select some cells in a row: target cursor over cell, click left button of mouse, holding it, pull the mouse to the side, and then release left button of mouse (at the same time code in OnDrawCell is drawing cells). By mouse or by touchpad of notebook works very well. But on tablet's touchscreen doesn't work at all.

I use TDrawGrid and OnMouseDown, OnMouseMove, OnMouseUp events. In Shift use all options: ssLeft, ssTouch, ssPen. Look at full code:

procedure TfmMain.GridMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
var
  ACol, ARow: Integer;
  ARect: TRect;
begin
  (Sender as TDrawGrid).MouseToCell(X, Y, ACol, ARow);
  ARect := (Sender as TDrawGrid).CellRect(ACol, ARow);

  pmIsLeft := X<(ARect.Left+((ARect.Right-ARect.Left) div 2));
  pmCol := ACol;
  pmRow := ARow;
  if (ssLeft in Shift) or (ssTouch in Shift) or (ssPen in Shift) then
  begin
    ChooseDaysInGridRowIndex := ARow;
SetLength(ChooseDays, 0);
  end;
end;

procedure TfmMain.GridMouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
var
  ACol, ARow: Integer;
begin
  if (ssLeft in Shift) or (ssTouch in Shift) or (ssPen in Shift) then
  begin
    (Sender as TDrawGrid).MouseToCell(X, Y, ACol, ARow);
    if (ChooseDaysInGridRowIndex>0) and
      (ChooseDaysInGridRowIndex<=(Sender as TDrawGrid).RowCount-1) and
  ((PagesDays[pagesBuildings.ActivePageIndex][ARow, ACol][0].ReservID<=0) or
        ((Length(ChooseDays)=0) and         ((PagesDays[pagesBuildings.ActivePageIndex][ARow, ACol][1].ReservID<=0)))) then
    begin
      SetLength(ChooseDays, Length(ChooseDays)+1);
      ChooseDays[High(ChooseDays)] := Point(ACol, ChooseDaysInGridRowIndex);

      InvalidateRect((Sender as TDrawGrid).Handle,
        (Sender as TDrawGrid).CellRect(ACol, ARow),
        True);
    end;
    ChooseDaysInGrid := True;
  end;
end;

procedure TfmMain.GridMouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
var
  ACol, ARow: Integer;
begin
  if ChooseDaysInGrid then
  begin
    (Sender as TDrawGrid).MouseToCell(X, Y, ACol, ARow);
    ChooseDaysInGrid := False;

    fmGuestArrival.roomID := GridRowTitles[(Sender as TDrawGrid).Tag]    [ARow].RoomID;
//      Integer((Sender as TDrawGrid).Objects[0, ARow]);

    if Length(ChooseDays)>0 then
    begin
      fmGuestArrival.dateArrival.DateTime :=
        IncDay(StartDatePeriod, ChooseDays[0].X-1);
      if Length(ChooseDays)>1 then
      begin
        fmGuestArrival.dateDeparture.DateTime :=
          IncDay(StartDatePeriod, ChooseDays[High(ChooseDays)].X - 1);
      end
      else
      begin
        fmGuestArrival.dateDeparture.DateTime :=
          IncDay(fmGuestArrival.dateArrival.DateTime, 1);
      end;
    end;

    fmGuestArrival.IsEditing := False;
    fmGuestArrival.cbStatus.ItemIndex := 0;
    fmGuestArrival.ShowModal;
  end;
end;
1

1 Answers

0
votes

Add Gesturing support by adding a TGestureManager (GestureManager1). Then assign GestureManager1 to the Touch.GestureManager property of the TDrawGrid. Open Touch.Gestures.Standard property of the TDrawGrid and select the gestures you want to be notified of. Create an OnGesture event and add code as needed.

The details are documented by Embarcadero