473,406 Members | 2,259 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

question regarding use of delegates?


I want to build a Filter form that displays a list of values in a listbox
which the user selects from. The values in this listbox are passed to the
filterform. When the user closes this filter form it notifies the calling
form of the filter criteria selected from this listbox. Since any form can
call this filterform the return call address is not known until the filter
form is opened.

Could I setup a callback for this purpose? Is there a better way to do this?
Any advice appreciated. Air code follows............

MainForm:
============
sub openfinder()
dim frm as new FinderForm
dim mydelegate as FinderForm.thisone
mydelegate = addressof SenditHere
frm.show
end sub

sub SenditHere(astr as string)
msgbox ("here it is: " & astr)
end sub
FinderForm:
============
private sFilter as string
public Delegate sub thisOne(byval astr_ as string)
....
....
private sub closeForm (sender, e) handles btnOk.click
call thisOne (sFilter) << DOES NOT COMPILE - "thisOne is a type
and cannot be used as an expression"
end sub

Nov 21 '05 #1
3 1133
I think in this case you need to declare a variable of type thisOne, and set
it to a method.

However, I would suggest that you look into using events here. That way the
form opening the dialog can listen to the dialog's event that says that a
value was selected, and handle it appropriately.

"astro" <as***@mnrr.com> wrote in message
news:e8**************@tornado.rdc-kc.rr.com...

I want to build a Filter form that displays a list of values in a listbox
which the user selects from. The values in this listbox are passed to the
filterform. When the user closes this filter form it notifies the calling
form of the filter criteria selected from this listbox. Since any form
can call this filterform the return call address is not known until the
filter form is opened.

Could I setup a callback for this purpose? Is there a better way to do
this? Any advice appreciated. Air code follows............

MainForm:
============
sub openfinder()
dim frm as new FinderForm
dim mydelegate as FinderForm.thisone
mydelegate = addressof SenditHere
frm.show
end sub

sub SenditHere(astr as string)
msgbox ("here it is: " & astr)
end sub
FinderForm:
============
private sFilter as string
public Delegate sub thisOne(byval astr_ as string)
...
...
private sub closeForm (sender, e) handles btnOk.click
call thisOne (sFilter) << DOES NOT COMPILE - "thisOne is a type
and cannot be used as an expression"
end sub

Nov 21 '05 #2
woot! that worked (setting up event)

thanks

"Marina" <so*****@nospam.com> wrote in message
news:OQ**************@TK2MSFTNGP15.phx.gbl...
I think in this case you need to declare a variable of type thisOne, and
set it to a method.

However, I would suggest that you look into using events here. That way
the form opening the dialog can listen to the dialog's event that says
that a value was selected, and handle it appropriately.

"astro" <as***@mnrr.com> wrote in message
news:e8**************@tornado.rdc-kc.rr.com...

I want to build a Filter form that displays a list of values in a listbox
which the user selects from. The values in this listbox are passed to
the filterform. When the user closes this filter form it notifies the
calling form of the filter criteria selected from this listbox. Since
any form can call this filterform the return call address is not known
until the filter form is opened.

Could I setup a callback for this purpose? Is there a better way to do
this? Any advice appreciated. Air code follows............

MainForm:
============
sub openfinder()
dim frm as new FinderForm
dim mydelegate as FinderForm.thisone
mydelegate = addressof SenditHere
frm.show
end sub

sub SenditHere(astr as string)
msgbox ("here it is: " & astr)
end sub
FinderForm:
============
private sFilter as string
public Delegate sub thisOne(byval astr_ as string)
...
...
private sub closeForm (sender, e) handles btnOk.click
call thisOne (sFilter) << DOES NOT COMPILE - "thisOne is a type
and cannot be used as an expression"
end sub


Nov 21 '05 #3
astro wrote:
I want to build a Filter form <snip> When the user closes this filter form it notifies the calling
form <snip> Could I setup a callback for this purpose? Is there a better way to do this? <snip>
MainForm:
============
sub openfinder()
dim frm as new FinderForm
dim mydelegate as FinderForm.thisone
mydelegate = addressof SenditHere
frm.show
end sub

sub SenditHere(astr as string)
msgbox ("here it is: " & astr)
end sub
FinderForm:
============
private sFilter as string
public Delegate sub thisOne(byval astr_ as string)
...
...
private sub closeForm (sender, e) handles btnOk.click
call thisOne (sFilter) << DOES NOT COMPILE - "thisOne is a type
and cannot be used as an expression"
end sub


The compilation error exists because you are simply declaring a
delegate type, but not a varible of that type.

You must declare a variable of the delegate type in the filter form, so
interested partners may 'connect' to the form.

In FinderForm, you'd have something like this:

<code style="Air code">
Private mTarget AS ThisOne

Public Property OnThisOne As ThisOne
Get
Return mTarget
End Get
Set(Value As ThisOne)
mTarget = Value
End Set
End Property

</code>

The code above declares a *variable* of type ThisOne. The public
property allows a caller to asssign a value to the variable, Then at
the appropriate time (when the FormClose sub kicked in), you'd have:

If mTarget IsNot Nothing Then
Call mTarget(sFilter)
End If

Notice the test to see if your delegate reference (mTarget) IsNot(tm)
Nothing: If you'd just call it without testing first, you'd risk
getting a NullReference exception...

Given the complications involving the directly handling of Delegates, I
suggest, as Marina already did, that you use Events instead:

<code style="Air code">

'Inside the Filter form
Public Event OnFilter(Value As String)

'...
Private Sub CloseForm(Sender As Object, E As EventArgs) _
Handles Button1.Click
RaiseEvent OnFilter(sFilter)
End SUb

'Inside Main Form
Private WithEvents MyFinderForm As FinderForm

Sub OpenFinder()
MyFinderForm = New FinderForm
MyFinderForm.Show
End Sub

Private Sub OnFilter(Value As String) _
Handles MyFinderForm.OnFilter
MsgBox("here it is: " & Value)
End Sub
</code>

Hope this helps.

Regards,

Branco.

Nov 21 '05 #4

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

Similar topics

2
by: Marinos Christoforou | last post by:
Sorry if this has been asked before but as an inexperienced wanna-be C# programmer I wondering how to code classes to help build a standard Windows UI. For example to build a common toolbar. I...
1
by: Natalia DeBow | last post by:
Hi, I am working on a Windows-based client-server application. I am involved in the development of the remote client modules. I am using asynchronous delegates to obtain information from...
44
by: craig | last post by:
I am wondering if there are some best practices for determining a strategy for using try/catch blocks within an application. My current thoughts are: 1. The code the initiates any high-level...
2
by: Silent Ocean | last post by:
Hi All I have following questions regarding C# Assembly and Threading. Let me know the precise answer or lead me to the proper materials. 1. Is memory leakeage possible in .Net Manager...
4
by: ^MisterJingo^ | last post by:
Hi all, I've been trying to get my head around delegates. The book i'm using had a single example, not much explaination, and didn't show how to set up a delegate and pass variables in and out...
5
by: archana | last post by:
hi all, Can someone tell me why can't we modify UI element directly from worker thread. Why we need to write delete of call invoke to modify ui element? Thanks in advance.
4
by: Bob Cramer | last post by:
I don't have a copy of Reflector handy :-( so I'd appreciate if someone could confirm (or clarify) the following. In consideration of the following delegate declaration... delegate string...
6
by: damiensawyer | last post by:
Hi, Can someone please explain to me something about delegates? My understanding is as follows. A delegate is basically an object that can hold a reference to a "method" somewhere. That is,...
4
by: tshad | last post by:
I am just getting started with events and had a couple of questions on why they do what they do. If you have a textbox and you want to handle an event you can just do: ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.