?
Solved

On line creating TSppidbutton

Posted on 2009-12-21
5
Medium Priority
?
263 Views
Last Modified: 2012-05-08
I need app where can i online create TSppedbutton (height 20,width 20) from main menu.
And to move (drag and drop) TSppedbutton with left mouse click on sppedbutton.
Then also possibility to open popup menu from right
click of the mouse on sppedbutton to define tag of TSppedbutton and the option to delete it.
0
Comment
Question by:pr2501
  • 3
  • 2
5 Comments
 
LVL 25

Expert Comment

by:epasquier
ID: 26096381
by online you mean run-time ?
0
 
LVL 25

Expert Comment

by:epasquier
ID: 26096652
Here is the code to create dynamically a TSpeedButton, and to move it around when left-clickin. It will also display a popup menu with right click. You have to define its items. In this example I added only one item to delete the button first saved in the SpeedButtonMouseDown event.
unit DynamicButtons;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, Menus, StdCtrls;

type
  TForm1 = class(TForm)

// don't paste these lines, 
// add the popup menu component and define its items with IDE
   popMenu:TPopupMenu;
   mnuDelete: TMenuItem;
   
   procedure SpeedButtonMouseDown(Sender: TObject; Button: TMouseButton;
               Shift: TShiftState; X, Y: Integer);
   procedure SpeedButtonMouseUp(Sender: TObject; Button: TMouseButton;
               Shift: TShiftState; X, Y: Integer);
   procedure SpeedButtonMouseMove(Sender: TObject; Shift: TShiftState; 
               X, Y: Integer);
   procedure mnuDeleteClick(Sender: TObject);
  private
   _Pos:TPoint;
   _btn:TSpeedButton;   
  public
   Function AddSpeedButton(L:Integer=10;T:Integer=10):TSpeedButton;
  end;

var
  Form1: TForm1;

implementation

procedure TForm1.FormCreate(Sender: TObject);
begin
 AddSpeedButton(10,10);
 AddSpeedButton(40,10);
end;

Function TForm1.AddSpeedButton(L:Integer=10;T:Integer=10):TSpeedButton;
begin
 Result:=TSpeedButton.Create(Self);
 Result.Parent:=Self; // or a panel
 Result.Width:=20;
 Result.Height:=20;
 Result.Left:=L;
 Result.Top:=T;
 Result.onMouseDown:=SpeedButtonMouseDown;
 Result.onMouseUp:=SpeedButtonMouseUp;
 Result.onMouseMove:=SpeedButtonMouseMove;
end;

procedure TForm1.SpeedButtonMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
 _btn:=TSpeedButton(Sender); // Might be usefull for other treatments
 if ssRight in Shift Then popMenu.Popup(Mouse.CursorPos.X,Mouse.CursorPos.Y);
 if ssLeft in Shift then
  begin
  // set the last clicked shape with right button
  // get its start position relative to position of mouse when the click occurred
  _Pos.X:=_btn.Left-Mouse.CursorPos.X;
  _Pos.Y:=_btn.Top-Mouse.CursorPos.Y;
  end;
end;

procedure TForm1.SpeedButtonMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
 if ssLeft in Shift Then _btn:=nil;
end;

procedure TForm1.SpeedButtonMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
begin
 if Not (ssLeft in Shift) then _btn:=nil;
 if Not Assigned(_btn) then Exit;
// Don't use X & Y directly as they are relative to the object, which is moving
 _btn.Left:=_Pos.X+Mouse.CursorPos.X;
 _btn.Top:=_Pos.Y+Mouse.CursorPos.Y;
end;

procedure TForm1.mnuDeleteClick(Sender: TObject);
begin
 if Assigned(_btn) then
  begin
   _btn.Free;
   _btn:=nil;
  end;
end;

Open in new window

0
 

Author Comment

by:pr2501
ID: 26110718
With code below i have next error>
Why?
 
[Pascal Error] Unit1.pas(16): E2003 Undeclared identifier: 'TSpeedButton'

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, Menus, StdCtrls;


type
  TForm1 = class(TForm)
    PopupMenu1: TPopupMenu;
    delate1: TMenuItem;
  private
   _Pos:TPoint;
   _btn:TSpeedButton;
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

end.

Open in new window

0
 
LVL 25

Accepted Solution

by:
epasquier earned 2000 total points
ID: 26110819
Add the unit "Buttons" to the uses list
0
 

Author Comment

by:pr2501
ID: 26111000
thank you
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
This is an update to some code that someone else posted on Experts Exchange. It is an alternate approach, I think a little easier to use, & makes sure that things like the Task Bar will update.
This video tutorial shows you the steps to go through to set up what I believe to be the best email app on the android platform to read Exchange mail.  Get the app on your phone: The first step is to make sure you have the Samsung Email app on your …
Stellar Phoenix SQL Database Repair software easily fixes the suspect mode issue of SQL Server database. It is a simple process to bring the database from suspect mode to normal mode. Check out the video and fix the SQL database suspect mode problem.
Suggested Courses

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question