472,971 Members | 2,224 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,971 software developers and data experts.

C# validating event problem for a super genius

I have an amazing problem which i think i have no hope of solving

Im working with a c# dot net module that is hosted by and runs under a
delphi form envrioment. Dont ask me how this insanity has prevailed
it just is :)

My problem is this

im trying to validate the contents of a textbox (it has to be a normal
textbox) and on a c# winforms and i am calling the textbox validating
event to check for bad data entry and in doing so causing the

eg test example
e.Cancel = nameTextBox.Text.Contains("!");

to be set to true, to halt focus at the textbox when bad data is
entered. On its own it works fine, but when hosted under the delphi
form application once the validating event has fired it will not
release focus away from the textbox at all

I desperatly need a way to be able to cancel the validating event so
that i can use other buttons that have become not clickable on other
parts of the winforms.

As i said it all works perfectly when run in the studio dev
enviroment, but when run as it needs to hosted by a delphi forms app
we have verified the validating events just wont seem to release focus

if anyone has any ideas or thoughts it would be appreciated

thanks

Peted
Jun 27 '08 #1
8 4065
Peted wrote:
I have an amazing problem which i think i have no hope of solving

Im working with a c# dot net module that is hosted by and runs under a
delphi form envrioment. Dont ask me how this insanity has prevailed
it just is :)

My problem is this

im trying to validate the contents of a textbox (it has to be a normal
textbox) and on a c# winforms and i am calling the textbox validating
event to check for bad data entry and in doing so causing the

eg test example
e.Cancel = nameTextBox.Text.Contains("!");

to be set to true, to halt focus at the textbox when bad data is
entered. On its own it works fine, but when hosted under the delphi
form application once the validating event has fired it will not
release focus away from the textbox at all

I desperatly need a way to be able to cancel the validating event so
that i can use other buttons that have become not clickable on other
parts of the winforms.

As i said it all works perfectly when run in the studio dev
enviroment, but when run as it needs to hosted by a delphi forms app
we have verified the validating events just wont seem to release focus

if anyone has any ideas or thoughts it would be appreciated
I would try creating the .NET controls from a separate thread which calls
Application.Run... that way you have an event loop independent of the Delphi
one and any non-standard behavior it implements.
>
thanks

Peted

Jun 27 '08 #2
On Apr 29, 4:51*am, Peted wrote:
I have an amazing problem which i think i have no hope of solving

Im working with a c# dot net module that is hosted by and runs under a
delphi form envrioment. Dont ask me how this insanity has prevailed
it just is :)

My problem is this

im trying to validate the contents of a textbox (it has to be a normal
textbox) and on a c# winforms and i am calling the textbox validating
event to check for bad data entry and in doing so causing the

eg test example
*e.Cancel = nameTextBox.Text.Contains("!");

to be set to true, to halt focus at the textbox when bad data is
entered. On its own it works fine, but when hosted under the delphi
form application once the validating event has fired it will not
release focus away from the textbox at all

I desperatly need a way to be able to cancel the validating event so
that i can use other buttons that have become not clickable on other
parts of the winforms.

As i said it all works perfectly when run in the studio dev
enviroment, but when run as it needs to hosted by a delphi forms app
we have verified the validating events just wont seem to release focus

if anyone has any ideas or thoughts it would be appreciated

thanks

Peted
I second Ben suggestion. It's possible that the Delphi form
environment is filtering or dispatching messages differently which is
what is actually causing the problem. This is one of those rare
situations where I think having multiple message loops running is
okay. If that doesn't fix your problem then you have something deeper
than the application message pump to contend with, which seems
unlikely to me.
Jun 27 '08 #3
thanks for the advice

any chance you could point me to an example of creating .net controls
from seperate threads as you have described ?

thanks

Peted
>
I would try creating the .NET controls from a separate thread which calls
Application.Run... that way you have an event loop independent of the Delphi
one and any non-standard behavior it implements.

Jun 27 '08 #4
On Apr 29, 7:47*pm, Peted wrote:
thanks for the advice

any chance you could point me to an example of creating .net controls
from seperate threads as you have described ?
Start a thread like you would any other thread and then immediately
call Application.Run. It accepts a Form parameter which will
automatically be shown up execution of the method. It's no different
than code Visual Studio generates for you when you Windows Forms
application except that another thread is involved.
Jun 27 '08 #5
Brian Gideon wrote:
On Apr 29, 7:47 pm, Peted wrote:
>thanks for the advice

any chance you could point me to an example of creating .net controls
from seperate threads as you have described ?

Start a thread like you would any other thread and then immediately
call Application.Run. It accepts a Form parameter which will
automatically be shown up execution of the method. It's no different
than code Visual Studio generates for you when you Windows Forms
application except that another thread is involved.
Or if you want just a few controls, not the whole Form shown from the other
thread, you can call
new TextBox() or whatever control type
and read the Handle property to make sure it is created from the new thread,
then call the parent form's Controls.Add method, passing in the newly
created control.
Jun 27 '08 #6
On Apr 30, 1:14*pm, "Ben Voigt [C++ MVP]" <r...@nospam.nospamwrote:
Or if you want just a few controls, not the whole Form shown from the other
thread, you can call
new TextBox() or whatever control type
and read the Handle property to make sure it is created from the new thread,
then call the parent form's Controls.Add method, passing in the newly
created control.
I hadn't thought about that before. I guess I've always been using
the assumption that this would cause chaos. How would the parent form
and the child control interact seeing as they are running on separate
threads? And from a developers perspective, writing code that
accesses the child control from the parent form would be cumbersome
and slow since everything would have to be marshaled between the
threads to maintain the thread affinity requirements right?

Jun 27 '08 #7
Brian Gideon wrote:
On Apr 30, 1:14 pm, "Ben Voigt [C++ MVP]" <r...@nospam.nospamwrote:
>Or if you want just a few controls, not the whole Form shown from
the other thread, you can call
new TextBox() or whatever control type
and read the Handle property to make sure it is created from the new
thread, then call the parent form's Controls.Add method, passing in
the newly created control.

I hadn't thought about that before. I guess I've always been using
the assumption that this would cause chaos. How would the parent form
Plugins are often hosted on another thread (embedded video player, acrobat
reader, that sort of thing).
and the child control interact seeing as they are running on separate
threads? And from a developers perspective, writing code that
Using windows messages SendMessage(WM_*, ...), often via a helper such as
GetWindowText or GetDlgItemText, same as they do from the same thread.
accesses the child control from the parent form would be cumbersome
and slow since everything would have to be marshaled between the
threads to maintain the thread affinity requirements right?
This "thread affinity" thing is an artificial creation of .NET.

The underlying windows calls work just fine across threads. And if your
control is hosted in a non-.NET form, then all the extra .NET baggage that
makes threading assumptions isn't present anyway.
Jun 27 '08 #8
On May 1, 8:45*am, "Ben Voigt [C++ MVP]" <r...@nospam.nospamwrote:
Brian Gideon wrote:
On Apr 30, 1:14 pm, "Ben Voigt [C++ MVP]" <r...@nospam.nospamwrote:
Or if you want just a few controls, not the whole Form shown from
the other thread, you can call
new TextBox() or whatever control type
and read the Handle property to make sure it is created from the new
thread, then call the parent form's Controls.Add method, passing in
the newly created control.
I hadn't thought about that before. *I guess I've always been using
the assumption that this would cause chaos. *How would the parent form

Plugins are often hosted on another thread (embedded video player, acrobat
reader, that sort of thing).
and the child control interact seeing as they are running on separate
threads? *And from a developers perspective, writing code that

Using windows messages SendMessage(WM_*, ...), often via a helper such as
GetWindowText or GetDlgItemText, same as they do from the same thread.
accesses the child control from the parent form would be cumbersome
and slow since everything would have to be marshaled between the
threads to maintain the thread affinity requirements right?

This "thread affinity" thing is an artificial creation of .NET.

The underlying windows calls work just fine across threads. *And if your
control is hosted in a non-.NET form, then all the extra .NET baggage that
makes threading assumptions isn't present anyway.
Excellent. Ya know...I've doing this for a long time so it just goes
to show that there will always be something to learn!
Jun 27 '08 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Alex Bink | last post by:
Hi, I have a validating event on a textbox in which I want to prevent the user to leave the textbox without entering the right data. Only if he clicks on another specific control he is allowed...
0
by: Joe | last post by:
Hi For a while now I have been finding postings of problems with the validating event not firing on controls properly. I too had this problem. The event would fire when clicking on another...
2
by: Chris Dunaway | last post by:
I have a form with a textbox and numerous panels, buttons and other controls. I have handled the textbox Validating and Validated events. The textbox will hold a filename. In the validating...
0
by: Matthew | last post by:
All, I have searched google and the newsgroups but can't find anything the same as what I am experiencing (though I may have missed something). I have controls (textboxes) within UserControls...
0
by: Gary Shell | last post by:
I am experiencing some strange behavior between a UserControl's validating event and a treeview control. Initially, I thought it was related to an issue in the Knowledgebase article 810852...
21
by: Darin | last post by:
I have a form w/ a textbox and Cancel button on it. I have a routine to handle textbox.validating, and I have the form setup so the Cancel button is the Cancel button. WHen the user clicks on...
6
by: Ryan | last post by:
I have a windows form that I want to force validation on controls (text boxes) when the user clicks a "Save" button. The only way I've found to do this is to cycle through every control and call...
16
by: Al Santino | last post by:
Hi, It appears displaying a messagebox in a validating event will cancel the subsequent event. In the program below, button 2's click event doesn't fire if you open a dialog box in button 1's...
3
by: TheSteph | last post by:
Hi Experts ! I have a Winform Program in C# / .NET 2.0 I would like to ensure that a value in a TextBox is a valid Int32 when user get out of it (TextBox loose focus)
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.