Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 7 of 7 total
Thread Duplicating an image, with events
Thu, Dec 5 2013 10:59 AMPermanent Link

Matthew Jones

I have a project that uses repeated images and panels and labels. I create them
based on a "master" set, so I can visually set them up, and then repeat them as
needed. This seems to work, but the TImage's are failing to copy the events, or
they are failing to work.

I've built a test project to show it. It has a panel which parents the new image.
The MouseDown for the original image is this:

procedure TForm1.Image1MouseDown(Sender: TObject; Button: Integer; ShiftKey,
CtrlKey, AltKey: Boolean; X,Y: Integer);
begin
   Report('MouseDown');
end;

A button click does the duplication:

procedure TForm1.Button1Click(Sender: TObject);
var
   xImage : TImage;
begin
   xImage := DuplicateImage(Image1, Panel1);
   xImage.Left := TestPos;
   Inc(TestPos, 20);
end;

Which calls the actual code:

procedure CopyImageDetails(xTargetImage: TImage; xReferenceImage : TImage);
begin
   xTargetImage.ImageName := xReferenceImage.ImageName;
   xTargetImage.Center := xReferenceImage.Center;
   xTargetImage.Stretch := xReferenceImage.Stretch;
   xTargetImage.Transparent := xReferenceImage.Transparent;
   xTargetImage.Left := xReferenceImage.Left;
   xTargetImage.Width := xReferenceImage.Width;
   xTargetImage.Height := xReferenceImage.Height;
   xTargetImage.Top := xReferenceImage.Top;
   xTargetImage.Visible := xReferenceImage.Visible;
   xTargetImage.BringToFront;

   xTargetImage.OnClick := xReferenceImage.OnClick;
   xTargetImage.OnMouseEnter := xReferenceImage.OnMouseEnter;
   xTargetImage.OnMouseLeave := xReferenceImage.OnMouseLeave;
   xTargetImage.OnMouseMove := xReferenceImage.OnMouseMove;
end;

function DuplicateImage(xReferenceImage : TImage; xParentPanel : TPanel) : TImage;
begin
   Result := TImage.Create(xParentPanel);
   Result.Parent := xParentPanel;
   CopyImageDetails(Result, xReferenceImage);
end;

At the end, the MouseDown works for the original, but not the copy. Anyone suggest
why not please?

Full source is available here:

http://www.matthew-jones.com/temp_xfer/ImageDuplicate.zip

/Matthew Jones/
Thu, Dec 5 2013 11:16 AMPermanent Link

Matthew Jones

If I add manual assignments after the call, it works:

xImage.OnMouseDown := frmVote.imgBlobLarge1MouseDown;
xImage.OnMouseUp := frmVote.imgBlobLarge1MouseUp;

(That won't compile as it is from my actual application, but shows the point.)
There must be something I'm missing.

/Matthew Jones/
Fri, Dec 13 2013 10:15 AMPermanent Link

Matthew Jones

This is a bit of a pain to do, so if anyone has a clue, please suggest anything.

   xTargetImage.OnMouseDown := xReferenceImage.OnMouseDown;

I can't understand why that isn't working.
   
/Matthew Jones/
Fri, Dec 13 2013 12:15 PMPermanent Link

Raul

Team Elevate Team Elevate

Your CopyImageDetails function does not actually assign the OnMousedown

Raul


On 12/13/2013 10:15 AM, (Matthew Jones) wrote:
> This is a bit of a pain to do, so if anyone has a clue, please suggest anything.
>
>      xTargetImage.OnMouseDown := xReferenceImage.OnMouseDown;
>
> I can't understand why that isn't working.
>
> /Matthew Jones/
>
Fri, Dec 13 2013 12:21 PMPermanent Link

Raul

Team Elevate Team Elevate

After i added the

xTargetImage.OnMouseDown := xReferenceImage.OnMouseDown;

to your CopyImageDetails function from original post the mousedown works
on copied images as well as original one

Raul

On 12/13/2013 12:15 PM, Raul wrote:
> Your CopyImageDetails function does not actually assign the OnMousedown
>
> Raul
>
>
> On 12/13/2013 10:15 AM, (Matthew Jones) wrote:
>> This is a bit of a pain to do, so if anyone has a clue, please suggest
>> anything.
>>
>>      xTargetImage.OnMouseDown := xReferenceImage.OnMouseDown;
>>
>> I can't understand why that isn't working.
>>
>> /Matthew Jones/
>>
>

Fri, Dec 13 2013 3:48 PMPermanent Link

Matthew Jones

> On 12/13/2013 12:15 PM, Raul wrote:
>> Your CopyImageDetails function does not actually assign the OnMousedown
>>
>> Raul

Hmm, that was just another that I'm wanting to use, but if it is working
for you, then I must have done something wrong. I will review. I wonder if
it is some sort of VAR thing where the routine is not changing the object
passed, or some such.

--
Matthew Jones
Fri, Dec 13 2013 7:12 PMPermanent Link

Raul

Team Elevate Team Elevate

On 12/13/2013 3:48 PM, Matthew Jones wrote:
> Hmm, that was just another that I'm wanting to use, but if it is working
> for you, then I must have done something wrong. I will review. I wonder if
> it is some sort of VAR thing where the routine is not changing the object
> passed, or some such.
>

I used your actual code (zip linked from 1st post) and it works in EWB
as well as Firefox and Chrome

When i say it works i pressed test button some 5 times to dupe 5 images
and then i get a "MouseDown" in the memo whever i click on any of them
(or on original image)

Raul
Image