Solved

TImage and "DragOver"

Posted on 2003-11-22
6
736 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
Technology Partners: 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: 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

Suggested Solutions

Title # Comments Views Activity
Simple Delphi Question 9 106
error 1.1 400 Bad request idhttp delphi 18 208
DBGrid or StringGrid ? 6 120
File Downloader in Multi threading , Measure Download Speed and progress 9 29
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

730 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