1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
| unit Signature_MainForm;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, System.Rtti,
FMX.Layouts, FMX.Grid,
System.Generics.Collections, FMX.Objects;
type
TForm1 = class(TForm)
StringGrid1: TStringGrid;
StringColumn1: TStringColumn;
StringColumn2: TStringColumn;
StringColumn3: TStringColumn;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure StringColumn2MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Single);
procedure StringColumn2MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Single);
procedure StringColumn2MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Single);
private
{ Déclarations privées }
FData: System.Generics.Collections.TObjectDictionary<Integer, FMX.Objects.TPath>;
FSignatureActive: Boolean;
FSignatureRow: Integer;
function GetCellData(Coord: TPointF; out ARow: Integer): FMX.Objects.TPath;
public
{ Déclarations publiques }
end;
var
Form1: TForm1;
implementation
{$R *.fmx}
procedure TForm1.FormCreate(Sender: TObject);
var
I: Integer;
begin
FData := System.Generics.Collections.TObjectDictionary<Integer, FMX.Objects.TPath>.Create([]); // StringGrid1 sera le Onwer
for I := 0 to StringGrid1.RowCount - 1 do
StringGrid1.Cells[0, I] := 'N°' + I.ToString();
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
FreeAndNil(FData);
end;
function TForm1.GetCellData(Coord: TPointF; out ARow: Integer): FMX.Objects.TPath;
var
Col: TStringColumn;
CellRect: TRectF;
begin
Result := nil;
ARow := -1;
Col := StringGrid1.ColumnByPoint(Coord.X, Coord.Y) as TStringColumn;
if Assigned(Col) and (Col.Index = 1) then
begin
ARow := StringGrid1.RowByPoint(Coord.X, Coord.Y);
if ARow >= 0 then
begin
if not FSignatureActive then
begin
if FData.TryGetValue(ARow, Result) then
begin
FData.Remove(ARow);
FreeAndNil(Result);
end;
end;
if not FData.TryGetValue(ARow, Result) then
begin
Result := FMX.Objects.TPath.Create(StringGrid1);
FData.Add(ARow, Result);
CellRect := TRectF.Create(0, ARow * StringGrid1.RowHeight, Col.Width, (ARow + 1) * StringGrid1.RowHeight - 1);
Result.HitTest := False;
Result.Locked := True;
Result.Fill.Kind := TBrushKind.None;
Result.WrapMode := TPathWrapMode.Original;
Result.Parent := StringColumn2;
Result.SetBounds(CellRect.Left, CellRect.Top, CellRect.Width, CellRect.Height);
end;
end;
end;
end;
procedure TForm1.StringColumn2MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Single);
var
CellData: FMX.Objects.TPath;
begin
CellData := GetCellData(StringGrid1.AbsoluteToLocal(StringColumn2.LocalToAbsolute(TPointF.Create(X, Y))), FSignatureRow);
if Assigned(CellData) then
begin
CellData.Data.MoveTo(CellData.AbsoluteToLocal(StringColumn2.LocalToAbsolute(TPointF.Create(X, Y))));
FSignatureActive := True;
end;
end;
procedure TForm1.StringColumn2MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Single);
var
CellData: FMX.Objects.TPath;
Row: Integer;
begin
if FSignatureActive then
begin
CellData := GetCellData(StringGrid1.AbsoluteToLocal(StringColumn2.LocalToAbsolute(TPointF.Create(X, Y))), Row);
if FSignatureRow = Row then
begin
if Assigned(CellData) then
CellData.Data.LineTo(CellData.AbsoluteToLocal(StringColumn2.LocalToAbsolute(TPointF.Create(X, Y))));
end
else
FSignatureActive := False;
end;
end;
procedure TForm1.StringColumn2MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Single);
begin
FSignatureActive := False;
FSignatureRow := -1;
end;
end. |
Partager