I didn't miss any point.  There is no recursion.  As I said, changing 
the Text property programatically does not trigger the OnChange event. 
Only users manually entering text or selecting a new item from the pull 
down list triggers this event.

The problem is not recursion.  It appears the OnChange event is occuring 
before the new selected value is entered into the Text field, so 
changing it inside the OnChange procedure has no effect.

I've got around the problem now by posting a WM_USER message and 
handling that.

Ross.

----- Original Message ----- 
From: "Jon P. Grewer" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Saturday, January 27, 2007 3:28 AM
Subject: Re: Delay setting Text Property


Ross,

You missed the point that he was making.  The problem is that when you
change the Text property it retriggers the OnChange event.  So to 
prevent
the recursion, inside the on change event, detach the event, make your
change to the Text property, then reset your OnChange event. So,

procedure TForm1.ComboBox1Change(Sender: TObject);
var
  ComboBox : TComboBox;
  OldEvent : TNotifyEvent;
begin
  ComboBox := (Sender as TComboBox);
  OldEvent := ComboBox.OnChange;
  ComboBox.OnChange := nil; // disconnect event
  ComboBox.Text := 'New Value'; // Set new value
  ComboBox.OnChange := OldEvent; // reconnect event
end;

Kind regards,
--Jon Grewer



----- Original Message -----
Message: 4
Date: Fri, 26 Jan 2007 11:38:22 +1300
From: "Ross Levis" <[EMAIL PROTECTED]>
Subject: Re: Delay setting Text Property
To: "Borland's Delphi Discussion List" <[email protected]>
Message-ID: <[EMAIL PROTECTED]>
Content-Type: text/plain; charset="iso-8859-1"

I don't see how that will help.  Changing the text property 
programatically
doesn't fire the OnChange event.  It requires a manual selection in the
combobox.

Thanks anyway,
Ross.

----- Original Message -----
From: "Arjang Assadi" <[EMAIL PROTECTED]>
To: "Borland's Delphi Discussion List" <[email protected]>
Sent: Thursday, January 25, 2007 4:11 PM
Subject: Re: Delay setting Text Property


1)detach the on changeEven
2)Change Text
3)re attach the on change event

On 1/25/07, Ross Levis <[EMAIL PROTECTED]> wrote:
>
> I want to change the Text property of a ComboBox inside the OnChange
> event.  Setting it directly doesn't work presumeably because the
> OnChange event occurs before the change occurs rather than after.
>
> So I decided the best way to do this would be to send the WM_SETTEXT
> message using PostMessage with a global variable storing the text...
>
> PostMessage(ComboBox1.Handle,WM_SETTEXT,0,Integer(pChar(GlobalString)));
>
> But this doesn't work either.  I read somewhere that Windows doesn't
> allow PostMessage to work with string pointers because it's likely the
> string address on the stack is temporary and will not exist after
> PostMessage has been sent.  This may be correct in most cases but with
> a
> global string, the address of the string will be constant, so it would
> work.
>
> SendMessage works with string pointers, but SendMessage waits until
> the
> message has been delivered before the procedure continues execution,
> so
> that defeats my purpose.
>
> Is there anyway to fool Windows into sending a WM_SETTEXT message
> without waiting.  Or do I have to muck about with a timer or send my
> own
> user message to get this to work?
>
> Thanks,
> Ross.

_______________________________________________
Delphi mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi

_______________________________________________
Delphi mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi

Reply via email to