?
Solved

TImage and "DragOver"

Posted on 2003-11-22
6
Medium Priority
?
746 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 1000 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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 my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses
Course of the Month14 days, 8 hours left to enroll

770 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