Solved

TImage and "DragOver"

Posted on 2003-11-22
6
743 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 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
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!

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

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 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 a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

726 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