Re: Why is onclick event firing here?



"Brad Blanchard" <1122@xxxxxxxxxxxxxxxx> wrote in message
news:VA.00002f9b.020acc9b@xxxxxxxxxxxxx

There must be simple reason for this, but I can't see it. Why is the
onclick event firing here in the following code? How do I fix it? TIA.

function TMainForm.SetImgClicks(URLIndex : integer) : TNotifyEvent;
begin
Showmessage('img onclick');
end;

procedure TMainForm.SetImages;
var
num : integer;
begin
SetLength(imgarray,numItems);
for num := 0 to numItems -1 do
begin
imgarray[num]:= TImage.Create(self);
imgarray[num].Parent := MainForm;
imgarray[num].OnClick := SetImgClicks(num);
imgname := inttostr(num+1) +'.bmp';
end;
end;

You fix it by mentioning a method instead of using it. As Alan noted,
you are _calling_ SetImgClicks, not setting a property to it. The compiler
doesn't complain because the call returns the correct type to use at that
place: TNotifyEvent.

Turn on hints & warnings. The compiler will now (correctly) warn you
that SetImgClicks doesn't actually return any specific value.

Groetjes.
Maarten Wiltink


.



Relevant Pages

  • Re: STM32 ARM toolset advice?
    ... Compulsory car comparison: would you buy a car where the motor block is ... you yourself using a self-help book) can fix? ... compilers work better than a compiler vendor. ...
    (comp.arch.embedded)
  • Re: How many bytes per Italian character?
    ... There's a reason I don't use free open-source products: ... someone once said "Well, you should use gcc because that way, if you find a bug ... I used to work for a compiler company. ... *know* how hard it is to fix bugs in optimizing compilers. ...
    (microsoft.public.vc.mfc)
  • Re: "no variable or argument declarations are necessary."
    ... > say I write some Python code, using assert to validate datatypes. ... I fix the first error, ... I can often run 4 Python edit-debug cycles in the time it takes me to ... I'll spend more time making the compiler happy than the ...
    (comp.lang.python)
  • Re: size_t problems
    ... You really should bite the bullet and fix the code. ... Believe me, I know what porting means, what is important in code ... software package supplied by the vender is *full* of pre C89 crud. ... The compiler would yell at me. ...
    (comp.lang.c)
  • Re: Heres a good one...
    ... Fix it, recompile and follow ... Always look at the earliest diagnostic reported by the compiler. ... Anything following a syntax error can probably be ignored; ... Error messages up to and including the first reported syntax error are ...
    (comp.lang.c)