[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

TImage and "DragOver"

Posted on 2003-11-22
6
Medium Priority
?
757 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
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

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.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

649 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