I'm new to Delphi. I need a help for complete my code. I just drawing a path. Now i want to save it to Android local storage as an Image format.
This is my code
procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Single);
begin
if ssLeft in Shift then
Path1.Data.MoveTo(PointF(X,Y) - Path1.BoundsRect.TopLeft);
end;
procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Single);
begin
if ssLeft in Shift then
Path1.Data.LineTo(PointF(X,Y) - Path1.BoundsRect.TopLeft);
end;
procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
//save code goes here
end;
Related
Example without BalloonHint1 works as designed. No issues with the Hint refresh.
procedure TForm1.ControlList1MouseMove(Sender: TObject;
Shift: TShiftState; X, Y: Integer);
begin
ControlList1.ShowHint:=false;
//ControlList1.CustomHint <-------value is not set as it is not required.
ControlList1.Hint := IntToStr(ControlList1.HotItemIndex);
ControlList1.ShowHint:=true;
end;
When I add a TBalloonHint, the BalloonHint does not display properly.
procedure TForm1.ControlList1MouseMove(Sender: TObject;
Shift: TShiftState; X, Y: Integer);
begin
ControlList1.ShowHint:=false;
BalloonHint1.Delay:=0;
BalloonHint1.HideAfter:=-1;
ControlList1.CustomHint:=BalloonHint1;
ControlList1.Hint := IntToStr(ControlList1.HotItemIndex);
ControlList1.ShowHint:=true;
end;
When I move my mouse over the ControlList for the first time. A BalloonHint does not show.
If I move my mouse over again (for the 2nd time) then the HotItemIndex from the previous movement shows the index.
Is there a way to do a BalloonHint1.Refresh?
I have tested some of the following:
Application.CancelHint; ///something that I dont want to do... but i gave it a try
also
ControlList1.ShowHint:=false;
ControlList1.ShowHint:=true;
The following worked.
procedure TForm1.ControlList1MouseMove(Sender: TObject;
Shift: TShiftState; X, Y: Integer);
begin
BalloonHint1.HideHint;
BalloonHint1.Delay:=0;
BalloonHint1.HideAfter:=-1;
ControlList1.CustomHint:=BalloonHint1;
ControlList1.Hint := IntToStr(ControlList1.HotItemIndex);
BalloonHint1.ShowHint(ControlList1);
end;
I then found that the BalloonHint flickered. So I used advice from the following:
Delphi ListView hint flickers
Create a global variable in which I would store reference to last HotItemIndex for which the hint has been shown. Then verify if the current HotItemIndex is the same as the one we stored controlListHotItemIndex.
procedure TForm1.ControlList1MouseMove(Sender: TObject;
Shift: TShiftState; X, Y: Integer);
begin
if controlListHotItemIndex<>ControlList1.HotItemIndex then
begin
controlListHotItemIndex:=ControlList1.HotItemIndex;
BalloonHint1.HideHint;
BalloonHint1.Delay:=0;
BalloonHint1.HideAfter:=-1;
ControlList1.CustomHint:=BalloonHint1;
ControlList1.Hint := IntToStr(ControlList1.HotItemIndex);
BalloonHint1.ShowHint(ControlList1);
end;
end;
I'm developing a drag 'n drop application and i'm feeling troubled with the Default DragCursor when Drag and Dropping an item as the following list of the default DragCursors:
So i'm trying to develop a new way to the user see the Drag 'n Drop movement like GMAIL:
My question is:
Are there the possibility to use Drag 'n drop events together Mouse events in Delphi 7?
If i put dmAutomatic in DragMode the MouseDown event does not work and if I put dmManual in DragMode the MouseDown works fine, but the DragDrop event does not work.
Here is my code below:
type
TForm1 = class(TForm)
pnlInformacaoDragDrop: TPanel;
pnl1: TPanel;
pnl2: TPanel;
procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
procedure FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
procedure FormMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
procedure pnl1DragDrop(Sender, Source: TObject; X, Y: Integer);
procedure pnl2DragDrop(Sender, Source: TObject; X, Y: Integer);
procedure pnl2DragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
procedure pnl1DragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
procedure pnl1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure pnl1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
{ Private declarations }
public
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{ TForm1 }
procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
begin
if Assigned(Self) then
begin
if pnlInformacaoDragDrop.Visible then
begin
pnlInformacaoDragDrop.Left :=X + 10;
pnlInformacaoDragDrop.Top := Y + 10;
end;
end;
end;
procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
if Assigned(Self) then
begin
if not pnlInformacaoDragDrop.Visible then
pnlInformacaoDragDrop.Visible := True;
// img1.BeginDrag(True);
end;
end;
procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
if Assigned(Self) then
begin
if pnlInformacaoDragDrop.Visible then
pnlInformacaoDragDrop.Visible := False;
end;
end;
procedure TForm1.pnl1DragDrop(Sender, Source: TObject; X, Y: Integer);
begin
TPanel(Sender).Caption := TPanel(Sender).Caption + ' - ' + TPanel(Source).Caption;
end;
procedure TForm1.pnl2DragDrop(Sender, Source: TObject; X, Y: Integer);
begin
TPanel(Sender).Caption := TPanel(Sender).Caption + ' - ' + TPanel(Source).Caption;
end;
procedure TForm1.pnl2DragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
begin
Accept := true;
end;
procedure TForm1.pnl1DragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
begin
Accept := true;
end;
Sorry for my simple question, but I don't know how can i do it...
Thanks a lot!
You can use dmAutomatic and write a handler for the OnStartDrag event instead of the mouse events you tried to use.
From D7 documentation:
Description
Use the OnStartDrag event handler to implement special processing when
the user starts to drag the control or an object it contains.
OnStartDrag only occurs if DragKind is dkDrag.
...
The OnStartDrag event handler can create a TDragControlObjectEx
instance for the DragObject parameter to specify the drag cursor, or,
optionally, a drag image list.
Drag-n-drop is a modal operation. It necessarily will abscond with the mouse events while the button is down in order to service the drag operation.
In cmAutomatic, you're telling the component to automatically initiate a drag-n-drop operation on left button down. In dmManual, you are responsible for initiating the drag operation by calling BeginDrag from within the MouseDown event.
IOW, without grabbing the actual Windows mouse events (WM_LBUTTONDOWN, WM_MOUSEMOVE, WM_LBUTTONUP, etc..), the VCL drag-n-drop mechanism will obscure the higher-level mouse events. However, should you decide to process those messages directly, you will also break the drag-n-drop mechanism. Without carefully managing the events and the drag-n-drop subsystem, you can easily make things behave very badly.
In VCL forms I use WM_SYSCOMMAND, but in firemonkey it is undeclared.
I test this code:
procedure TForm4.dragPanelMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Single);
begin
isDraging := true;
X0 := X;
Y0 := Y;
end;
procedure TForm4.dragPanelMouseMove(Sender: TObject; Shift: TShiftState;
X, Y: Single);
begin
if isDraging then
begin
Form4.Left := Trunc(Form4.Left + X - X0);
Form4.Top := Trunc(Form4.Top + Y - Y0);
end;
end;
procedure TForm4.dragPanelMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Single);
begin
isDraging := False;
end;
this works, but just for slow moves!!!
How can I move form in Firemonkey?
What easier is just to use the StartWindowDrag method of the Form. This way it will work in both Windows and MacOS and its only 1 line of code. Like so:
procedure TForm4.dragPanelMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Single);
begin
Self.StartWindowDrag;
end;
If the VCL code that you want to replicate is:
SendMessage(MyForm.Handle, WM_SYSCOMMAND, SC_DRAGMOVE, 0);
then the equivalent for FMX would be:
SendMessage(FmxHandleToHWND(MyForm.Handle), WM_SYSCOMMAND, SC_DRAGMOVE, 0);
The reason is that MyForm.Handle is an FMX handle. That's not the same as a window handle. You convert to a window handle with FmxHandleToHWND().
You may need to declare a couple of constants:
const
WM_SYSCOMMAND = $0112;
SC_DRAGMOVE = $F012;
my application has 350 edit fields and all of them shall have an OnMouseMove event.
I have generated this code for all of them:
...
type
...
procedure Edit1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
procedure Edit2MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
...
implementation
{$R *.dfm}
...
procedure TForm1.Edit1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
Edit1.SetFocus();
end;
procedure TForm1.Edit2MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
Edit2.SetFocus();
end;
...
But I didn't go to the object inspector to doubleclick OnMouseMove.
Is there a way to make this work without the object inspector.
Do you have an example line of code that would make it work for the first edit field?
You can create it once and assign it in code yourself:
type
TForm1=class(TForm)
procedure EditMouseMove(Sender: TObject; Shift: TShiftState;
X, Y: Integer);
procedure FormCreate(Sender: TObject);
//...
end;
implementation
procedure TForm1.EditMouseMove(Sender: TObject; Shift: TShiftState;
X, Y: Integer);
var
CurrEdit: TEdit;
begin
if (Sender is TEdit) then
begin
CurrEdit := TEdit(Sender);
// Do whatever with CurrEdit
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Edit1.OnMouseMove := EditMouseMove;
Edit2.OnMouseMove := EditMouseMove;
Edit3.OnMouseMove := EditMouseMove;
end;
If you want to assign the same one to every TEdit on the form:
procedure TForm1.FormCreate(Sender: TObject);
var
i: Integer;
begin
for i := 0 to ControlCount - 1 do
if Controls[i] is TEdit then
TEdit(Controls[i]).OnMouseMove := EditMouseMove;
end;
I need to draw a line in delphi using the cursor, I already have created the line code, but I can't get what to do next? How can do that, I push the mouse, when the line needs to start and drag my mouse or simple I release mouse button and I draw the line.
procedure TForm1.Button1Click(Sender: TObject);
var
x0, y0, x1, y1: Integer;
begin
x0 := StrToInt(Edit1.Text);
y0 := StrToInt(Edit2.Text);
x1 := StrToInt(Edit3.Text);
y1 := StrToInt(Edit4.Text);
Brezenhems(x0 , Y0 , X1 , Y1);
end;
I hope that someone helps me
Thanks
Something like this:
unit Unit4;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
type
TForm4 = class(TForm)
procedure FormResize(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormPaint(Sender: TObject);
procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure FormMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
private
{ Private declarations }
FStartPoint, FEndPoint: TPoint;
FDrawingLine: boolean;
bm: TBitmap;
procedure AddLineToCanvas;
procedure SwapBuffers;
public
{ Public declarations }
end;
var
Form4: TForm4;
implementation
{$R *.dfm}
procedure TForm4.FormCreate(Sender: TObject);
begin
bm := TBitmap.Create;
FDrawingLine := false;
end;
procedure TForm4.FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
FStartPoint := Point(X, Y);
FDrawingLine := true;
end;
procedure TForm4.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if FDrawingLine then
begin
SwapBuffers;
Canvas.MoveTo(FStartPoint.X, FStartPoint.Y);
Canvas.LineTo(X, Y);
end;
end;
procedure TForm4.FormMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
FDrawingLine := false;
FEndPoint := Point(X, Y);
AddLineToCanvas;
SwapBuffers;
end;
procedure TForm4.AddLineToCanvas;
begin
bm.Canvas.MoveTo(FStartPoint.X, FStartPoint.Y);
bm.Canvas.LineTo(FEndPoint.X, FEndPoint.Y);
end;
procedure TForm4.FormPaint(Sender: TObject);
begin
SwapBuffers;
end;
procedure TForm4.SwapBuffers;
begin
BitBlt(Canvas.Handle, 0, 0, ClientWidth, ClientHeight,
bm.Canvas.Handle, 0, 0, SRCCOPY);
end;
procedure TForm4.FormResize(Sender: TObject);
begin
bm.SetSize(ClientWidth, ClientHeight);
end;
end.
Compiled sample EXE
Notice that this method is simple and robust, but not optimal in terms of performance. This will likely be an issue if you try to run this on a Windows 3.1-era computer.
Another technique that can be used, without the need to create a bitmap, is using the Pen.Mode property. Something like this:
TForm2 = class(TForm)
procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
procedure FormMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
PO,LP: TPoint;
draw: boolean;
public
{ Public declarations }
end;
procedure TForm2.FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
PO.X:= X;
PO.Y:= Y;
LP.X:= X;
LP.Y:= Y;
draw:= true;
Canvas.Pen.Mode:= pmNotXor;
end;
procedure TForm2.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if draw then
begin
if (LP.X <> PO.X) or (LP.Y <> PO.Y) then
begin
Canvas.MoveTo(PO.X,PO.Y);
Canvas.LineTo(LP.X,LP.Y);
end;
LP.X:= X;
LP.Y:= Y;
Canvas.MoveTo(PO.X,PO.Y);
Canvas.LineTo(LP.X,LP.Y);
end;
end;
procedure TForm2.FormMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if draw then draw:= false;
end;