Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Image disappears following drag drop

Status
Not open for further replies.

planix

Technical User
Dec 3, 2002
22
Hi,

I have a form with 2 squares(shape1 and shape2) and an image control. The picture in the image will be loaded at runtime in the end, but for the moment I have just put one in to try this out.

The idea is to drag the image to a shape. Once it is dropped there a range of other processing will follow. None of this is coded as yet as I am just starting the basic logic of this.

Anyway, I can drag the image on to shape1 with no problems. It appears there okay. But, if I try to drag the image to shape2 it disappears.

The code is as follows:

Code:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, jpeg;

type
  TForm1 = class(TForm)
    Shape1: TShape;
    Image1: TImage;
    Shape2: TShape;
    procedure Shape1DragDrop(Sender, Source: TObject; X, Y: Integer);
    procedure Shape1DragOver(Sender, Source: TObject; X, Y: Integer;
    State: TDragState; var Accept: Boolean);
    procedure Shape2DragOver(Sender, Source: TObject; X, Y: Integer;
      State: TDragState; var Accept: Boolean);
    procedure Shape2DragDrop(Sender, Source: TObject; X, Y: Integer);

  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

procedure PutDown(Sender, From : TObject);

implementation

{$R *.dfm}
 //PutDown Procedure
{* PutDown takes the TImage object and the Shape onto which it has been dropped
and processes the positioning of the image on the shape. It will also be used
to centralise the logic of processing the match of image to location.*}

procedure PutDown(Sender, From: TObject);
begin
  TImage(Sender).Left := TShape(From).Left;
  TImage(Sender).Top := TShape(From).Top;
end;

//Drag and Drop Processing for the Shapes that make up the 3 x 3 grid
procedure TForm1.Shape1DragDrop(Sender, Source: TObject; X, Y: Integer);
begin
if Source is TImage then
 begin
  PutDown(Source, Sender);
 end;
end;

procedure TForm1.Shape1DragOver(Sender, Source: TObject; X, Y: Integer;
  State: TDragState; var Accept: Boolean);
begin
  Accept := (Source is TImage);
end;

procedure TForm1.Shape2DragDrop(Sender, Source: TObject; X, Y: Integer);
begin
  PutDown(Source, Sender);
end;

procedure TForm1.Shape2DragOver(Sender, Source: TObject; X, Y: Integer;
  State: TDragState; var Accept: Boolean);
begin
  Accept := (Source is TImage);
end;

//End of Drag and Drop Processing for grid
end.

I am sure I am making a basic mistake here. Can anyone see what it is?

Thanks

Alistair
 
and the answer was simple and obvious.

Basically the image needs to be on top to start with. So, as shape2 was created after shape1 and the image object it was at the top. Thus, when I put the image on it, the image went behind the shape.

grrr.

Probably be something I'll have to pay attention to when I change the images dynamically at run time...

Alistair
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top