Solved

TImage and "DragOver"

Posted on 2003-11-22
6
712 Views
Last Modified: 2010-04-05
Hello again...

A small problem appeared in my current project... I have a database-application with a grid
showing a few records. Now when the user will do something with these records he drags
them over diffrent TImages -> and the action triggered depends of the selected image. Now to
the problem:

I've been trying to make a "highlighted" image to appear when the record is dragged over the image,
one (lets say green highlighted) if the operation is accepted and one (lets say a red picture) when the
operation is not accepted.. But... all the dragdrop functions works well, not the changing of the image..

Anyway to solve this??

thanks,
hokki
0
Comment
Question by:hakanfa
  • 4
  • 2
6 Comments
 
LVL 5

Expert Comment

by:Darth_helge
ID: 9805597
first of all you have to modify your TDBGrid component.
u can do it by installing this component (this one has added on mousedown and mouseup events)
install this component:

unit Dbgrid;

interface

uses
  DBGrids, Controls, Classes;

type
  TEDBGrid = class(TDBGrid)
  private
    FOnMouseDown: TMouseEvent;
    FOnMouseUp: TMouseEvent;
  protected
    procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y:
Integer); override;
    procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y:
Integer); override;
  published
    Property OnMouseDown : TMouseEvent read FOnMouseDown write
FOnMouseDown ;
    Property OnMouseUp : TMouseEvent read FOnMouseUp write FOnMouseUp ;
end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('Data Controls',[TEDBGrid]);
end;

procedure TEDBGrid.MouseDown(Button: TMouseButton; Shift: TShiftState;
X, Y: Integer);
begin
  if Assigned(FOnMouseDown) then
    FOnMouseDown(Self,Button,Shift,X,Y);
  inherited MouseDown(Button,Shift,X,Y);
end;

procedure TEDBGrid.MouseUp(Button: TMouseButton; Shift: TShiftState; X,
Y: Integer);
begin
  if Assigned(FOnMouseUp) then
    FOnMouseUp(Self,Button,Shift,X,Y);
  inherited MouseUp(Button,Shift,X,Y);
end;

end.

////////////////////Then i tried a sample program, and this works fine for me.///////////////////7
The edbgrid1 component dragmode is dmManual and has rowselect = true:


unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls, jpeg, ExtCtrls, DB, ADODB, Grids, DBGrids, ExtDbGrid;

type
  TForm1 = class(TForm)
    Image1: TImage;
    ListView1: TListView;
    ADOConnection1: TADOConnection;
    DataSource1: TDataSource;
    ADOQuery1: TADOQuery;
    EDBGrid1: TEDBGrid;
    procedure Image1DragOver(Sender, Source: TObject; X, Y: Integer;
      State: TDragState; var Accept: Boolean);
    procedure Image1DragDrop(Sender, Source: TObject; X, Y: Integer);
    procedure EDBGrid1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure FormCreate(Sender: TObject);
  private
  pic1,pic2: TPicture;

  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Image1DragOver(Sender, Source: TObject; X, Y: Integer;
  State: TDragState; var Accept: Boolean);
begin
accept := true;
if Source is TEDBGrid then
  if (Source as TEDBGrid).DataSource.DataSet.FieldValues['id'] < 2 then
    Image1.Picture := pic1
  else
    Image1.Picture := pic2;

end;

procedure TForm1.Image1DragDrop(Sender, Source: TObject; X, Y: Integer);
begin
showmessage('you dropped id number: ' + IntToStr((Source as TDBGrid).DataSource.DataSet.FieldValues['id']));
end;

procedure TForm1.EDBGrid1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
edbgrid1.BeginDrag(false);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
pic1 := TPicture.Create;
pic2 := TPicture.Create;
pic1.LoadFromFile('c:\01.jpg');
pic2.LoadFromFile('c:\02.jpg');
Image1.Picture := pic1;
end;

end.


well, a lot of code, but it worked for me
0
 

Author Comment

by:hakanfa
ID: 9805811
Works fine! Greate! I know this is out of this questions scope but is there a way to "reset" (back to the original pic) the picture on the Image if the mouse pointer is outside the TImage
0
 
LVL 5

Accepted Solution

by:
Darth_helge earned 250 total points
ID: 9805975
well, it's not the best soloution but a quick one. if the image is on a panel, u can load the default picture when the onMouseMove on then panel occurs. like this:

TForm1.Panel1MouseMove(...........)
begin
if Image1.Picture <> defaultpic then
  Image1.Picture := defaultpic;
end;

//this code is not tested...

alternately u can modify the TImage component so that u add the onMouseLeave event on the image.
Then u can just do this:

TForm1.modifiedImage1MouseLeave(....)
begin
  Image1.Picture := defaultpic;
end;

//this code is not tested...

instructions how to add mouseleave event on a TImage is here

http://www.shagrouni.com/english/software/msleave.html

hope this helps
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 5

Expert Comment

by:Darth_helge
ID: 9805976
sorry... this is more right

TForm1.modifiedImage1MouseLeave(....)
begin
  modifiedImage1.Picture := defaultpic;
end;

0
 

Author Comment

by:hakanfa
ID: 9806063
GREAT! Thanks alot pal! Works fine!!
0
 
LVL 5

Expert Comment

by:Darth_helge
ID: 9806075
just glad to be of assistance.. :)
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

708 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now