C# - Preferred Techniques For Passing Objects Which Clients May Invalidate

Jan 31, 2012

I have adopted a technique where I pass existing objects to forms so that they can display the object's content and allow the user to alter it if necessary. The form is not bound to the object, so when it comes time to act, the form sweeps up the content of its controls and puts them into the object. The object is then validated and any issues reported to the user. If the object is valid, it may be handed back to the caller so the caller can refresh a view/list/etc.

So far, so good. However, if the form's content, or lack of, creates an invalid object and the user does not correct it, maybe cancelling the form, there's a chance the form will hand an invalid object back to the caller. This is not good.

Essentially I'm looking for an elegant and efficient way of either leaving the object as it was or rolling back if the user cancels the form/action.

I have considered a range of techniques, each with many pros and cons. I'm keen to consider some other views.

View 3 Replies


ADVERTISEMENT

Passing Objects Between Forms?

Aug 11, 2010

I'm translating a document management application from vb6. I want to program with good habits and technique, so I'm asking for your opinion really rather than just a solution.I have a decent understanding of OOP, but I'm not very experienced in VB at all. What I'm doing now is trying to figure out the best way to pass objects between forms.For example, in my initialization form, I have an object that stores a group of database connections. I need to pass this object around because reconnecting takes a significant amount of time. There are other objects such as user info and permissions.

Public Class Form 1
Dim DB = New DBobject
Public Sub Form1_Load

[code]......

View 5 Replies

Passing Objects Between WCFs?

May 20, 2011

I have an ASP application, which calls an HTTP WCF service, which calls a TCP WCF service (all on different servers). I'm ultimately trying to pass one class object between the three.I've discovered that I can't do this directly in the HTTP WCF, even though my class object is defined identically in BOTH WCFs. Like this:

Public Function CallOtherFunction(ByVal ThisClass as MyClass)
Dim RetVal as Boolean
RetVal = CallMyOtherWCFFunction(ThisClass)
End Function

Instead I have to:

Public Function CallOtherFunction(ByVal ThisClass as MyClass)
Dim RetVal as Boolean
Dim MyOutgoingClass as MyOtherWCF.MyClass

[code]....

My objects are rather large, to say they have a lot of properties. Any way to not have to declare a new variable in my calling function?

View 1 Replies

Passing Objects To Methods?

Jun 26, 2010

I always thought I understood how this works...but lately I have started really using interfaces and now things arent doing what I am expecting.

using entity framework, I have a service for each object that is responsible for interacting with the database and such....on my one service I am passing the collection of objects to my service as an icollection(of contactinfo) before I pass the object, the changetraker has the right states. however in my method, this is not the case and all states are set to unmodified.

Private Sub SaveExecute(ByVal param As Object)
Dim srv As Services.ContactInfoService = GetService(Of Services.IContactInfoService)()

[Code]....

As I said above the Me.contacInfoCollection has the right changetracking states. But Once its passed to the srv.savechanges it reverts to unmodified. I am sure its something silly I am missing...the whole EF thing can be confusing to me...

View 2 Replies

C# - Passing Objects Into Constructor Before Initialized?

Jun 12, 2011

I have the following problem. This is a simple example of some classes I have (each have dependencies on other classes).

public Class1()
{
public Class1(Class2 class2)[code].....

The problem I have is that the assert is always null, even though class1 has been initalized. One condition I do have is that I only want there to be one instance of each class created.

View 3 Replies

Passing An Arraylist Of Objects From One Class To Another?

Aug 19, 2011

I have the following code in Class B

FolderList.add(FolderCategory)

when i do a count it display a list of 25 items in the folderlist.Now i have a main class when i tried to use the following method

Dim MainClass as New ClassB

Console.writeline(MainClass.FolderList.count()) the value reflects as 0 items meaning is empty.i need to retrieve the arraylist from Class B using the MainClass to retrieve those items inside the arraylist.

View 7 Replies

Passing Serializable Objects Through Sockets?

Jul 16, 2009

I have no idea where to begin. I've looked online but haven't been able to find anything.

View 1 Replies

VS 2010 Passing Objects And Sessions?

Aug 21, 2011

I was wondering if someone could tell me if this is "bad practice" or is a perfectly acceptable way to pass an object to another form.I've cut out a lot of the code to summarise what im asking.

[Code]...

Dim myRetrievedObject as myObject = Module1.returnSavedObject()Is this a acceptable way of passing an object between forms or is it a completely bad idea?Ideally i would like to be able to "add" further objects to the initially created object in Form1 but then on reloading of Form1 , retrieve the new version of myObject with the newly added objects within the myObject class.My initial thinking is this creates an almost session like state for the initial object. So you can use the same object over all 3 forms or more and just simply add to it like a shopping cart type of functionality.

View 10 Replies

Control Not Redrawn On Me.Invalidate()

Apr 13, 2012

I call Me.Invalidate() in the property setter of a custom control (inherits from ProgressBar) but it only causes the control to paint on screen about 1 in every 10 times (or less) whereas there are far more times that the code enters the painting routines (i.e. only on some occassions do the painting routines cause on screen changes). I am using my own Painting routines, not using ProgressBarRenderer.

On the Inherited ProgressBar I set Minimum to 0 and Maximum to 1000 and use a timer to increment Value by 1 on each tick (100ms). Therefore Me.Invalidate() should be called after every tick and hence the 'progress' of the bar should be quite smooth - 1000 small increments as it fills the bar should be pretty small changes and hence appear fairly smooth.

However, what happens is that the control only changes on screen about 1 in 10 of the times that Value changes. The control also writes the progress as a % (integer) onto its surface and each change in the % text is accompanied by an increase in the visual progress. I think this apparent synchronisation is coincidence though, since using Console.WriteLine I can see many many calls to the Painting routine but a few of them actually cause a visual change on screen.

I have tried slowing the timer down to 1000ms but this hasn't changed anything other than there are far more than 10 calls to the painting routines between actual on screen changes.

I am using PointF, RectangleF and SizeF to avoid 'rounding errors' and hence blocky progress from using the Integer versions of those structures.

There's some stuff from the Output window (using Console.Writeline) near the bottom of this post that shows that at the beginning there is 1 OnPaint per Invalidate. Later on (somewhere around 1% and 5% progress) it changes to having several OnPaint calls between Invalidates. So I certainly don't appear to be short on calls to OnPaint. I only appear to be short of actual OnScreen changes.

The Painting routines use the RectangleF structures to create GraphicsPath objects, which are used to create a Region that is then filled by e.Graphics.FillRegion.

Possibilities I can think of:

1) The painting events are too frequent to allow screen udpating, but this doesn't seem likely since 1000ms timer ticks didn't help

2) GraphicsPath and / or Region objects aren't 'precise' and hence a range of similarly sized RectangleF objects create essentially identical GraphicsPath objects (or the same problem when moving from GraphicsPath to Region)

3) Erm, not sure...

Here's the Setter code:

Public Shadows Property Value As Integer
Get
Value = MyBase.Value

[Code].....

View 3 Replies

Generate A PaintEvent Without Calling An InValidate?

Apr 29, 2009

I am creating an application that is drawing different types of lines in a Panel called Panel1 and realized that everytime I call Panel1.Invalidate() alll the lines that are currently drawn on the display during runtime are cleared then redrawn every time.Is there anyway to generate a PaintEvent without calling an InValidate?

View 2 Replies

Asp.net - Invalidate A Single Data Item In The .net Cache In VB

Jun 3, 2010

I have the following VB.NET code to set and read objects in cache on a per user basis (i.e. a bit like session)

Public Shared Sub CacheSet(ByVal Key As String, ByVal Value As Object)
Dim userID As String = HttpContext.Current.User.Identity.Name
HttpContext.Current.Cache(Key & "_" & userID) = Value
End Sub

[Code]....

I use these functions to hold user data that I don't want to access the DB for all the time. However, when the data is updated, I want the cached item to be removed so it get created again.

How do I make an Item I set disappear or set it to NOTHING or NULL?

View 1 Replies

Call Method Base Class In Program Passing Sub Class Objects?

Apr 22, 2012

Base class has one field to hold numeric balance value. With 2 methods that accept arguments for adding and subtracting the new input calculating new balance. Sub class has four fields dates, transaction, memo and amount.I have a deposit form, and withdraw form. Each time one transaction is entered it creates an object with sub class fields, then adds to the account collection. My problem is not understanding how to call the deposit/withdraw method and pass the current transaction amount back to the base class to alculate the new balance. Does anyone have any links to information/tutorials on how to perform something like this? As you can see with my code I have tried various different approaches without any success.

[Code]...

View 5 Replies

How To Use Techniques To Encrypt And Decrypt

Aug 18, 2011

I just know it works. So as a personal project I'm trying to learn in VB/C# all about Cryptographic methods and how to use those techniques to encrypt and decrypt files. [code]

View 2 Replies

Preferred To Use New Date Or New DateTime?

Dec 6, 2010

why is it that we have a date and a datetime which are exactly the same thing, and is it preferred to use new Date or new DateTime?

View 4 Replies

Best Techniques For Fighting Software Piracy?

May 19, 2011

From what I understand, it is still impossible to prevent software piracy until a global Internet is established.

In the meantime, I'm looking for suggestions on how to protect any new projects I design.

View 9 Replies

Coding Techniques Could Use For Timed Keypress?

Apr 10, 2009

Ok heres my idea Start(button)> start timer1 countdown> keypress> start timer2 countdown> keypress2> if keypress2 happend twice> then keypress3> loop> end>I understand the science behind it but I fail to grasp the knowhow of the program lang if anyone knows how this could be done in VB Express.

View 9 Replies

Efficient / Preferred Way Of Using Session Variables?

Jan 28, 2011

I have an ASP DataGrid and I'm applying sorting to it. Well, as I was looking at an example, they had a function similar in function, different in name, to[code]...

View 3 Replies

Techniques To Control Stack Overflows?

Aug 20, 2011

Basically, my program will try to generate the list of all possible lowercase 5-letter words. Including all combinations that clearly are not real words like jshcc or mmdzq.

I do that by stacking up a massive amount of calls for a function, which does the word work.

But that's simply too much, and I get a stack overflow error.

View 3 Replies

.net - Preferred Serialization Method For Simple VB Project?

Jun 11, 2012

This is newbie VB question. My son is learning VB and I am learning with him. We have RichEdit control application (non WPF), where we input text, formatting its Style (bold, italic, underline, etc.). Our next task is to save the text together with its attributes into the file. The question is: what type of serialization is preferred at this case?

View 3 Replies

.NET Have Built-in Techniques For More Complicated Forms Of Iteration

Jun 11, 2011

Does .NET have built-in techniques for more complicated forms of iteration like the following:

1. Iterate over rearrangements of a list.

2. Iterate over subsets of a list.

3. Iterate over all indexes of a multidimensional list.

4. Iterate over all "combinations" of a list, i.e. all subsets of a list of a given length, where subsets that differs only in their ordering occur only once total.

I recently had cause to do (1) and my method was ugly, slow, tedious, and generalized poorly, which is why I ask. I can think of better ways, but it was garbage code anyway [brute force checking that there are precisely 576 seven-digit numbers made up of 1, 2, 3, 4, 5, 6, and 7 that are also divisible by 11]. The others are just for my own curiosity.

View 4 Replies

Development Techniques - Make A Program That Can Be Used With Plugins?

Aug 19, 2010

While I've mainly been developing small applications for personal use, I stumbled upon making a touchscreen application for a close friend. While he is not very good at programming, he is pretty well at drawing/etc... So, I thought about expanding my horizons some.I already have code that loads images from a folder, and made that folder changeable via the program, so in effect, probably a horribly coded way of skinning some parts of the program (the buttons). But then I though about it some more and really wanted to learn a better way to make my programs 'expandable'.I have begun searching about how to make a program that can be used with plugins, how to make plugins, and so on... I am researching about dynamically changing controls and other things, so that when resolutions change, I don't have to code each individual buttons new size/location, and, most importantly, a way to implement patching/app upgrades...

View 2 Replies

What Rounding Methods Need To Call To Get The Preferred Results

Apr 12, 2011

I have 4 rounding options: None, Standard, Up, Down If they choose None and the number is 108.7879, I just want to display 108.78 with no rounding. I know I probably can use Math.Ceil for Up and Math.Floor for Down, but I am not sure what to use for None or Standard.

[Code]....

View 4 Replies

Which Language Is Preferred By Most Developers Especially Targeting .NET & Silverlight?

Jan 25, 2010

Which language is preferred by most developers especially targeting .NET & silverlight? Is it C# or VB.NET?

Are there any advantages/disadvantages of both languages when compared with each other?

View 6 Replies

Preferred Method For Generating Locally Unique Identifiers?

Aug 31, 2010

I'm looking for a method of generating unique identifiers for a record class being created locally and then persisted in various formats (XML, SQL, etc.) I've seen people using DateTime and GetHashCode, but that seems to lend itself to duplicate identifiers depending upon the sample size. GUID is a bit overkill, as I don't need anything that unique (large) at the global level. I'm also aware of using GUIDs and GetHashCode to get the size down a bit, but duplicates tend to crop up here as well. Any best practice or method for generating simple unique identifiers?

View 3 Replies

Preferred Method To Catch Specific OleDB Error

Jan 4, 2010

I have a situation in which I must execute a dynamically built stored procedure against tables that may, or may not be in the database. The data retrieved is then shunted to a VB.Net backed ASP based report page. By design, if the tables are not present in the database, the relevant data is automatically hidden on the report page. Currently, I'm doing this by checking for the inevitable error, and hiding the div in the catch block. A bit kludgy, but it worked.I can't include the VB code-behind, but the relevant stored procedure is included below.However, a problem with this method was recently brought to my attention when, for no apparent reason, the div was being hidden even though the proper data was available. As it turned out, the user trying to select the table in the dynamic SQL call didn't have the proper select permissions, an easy enough fix once I could track it down.First and foremost - is there a better way to check for a missing table than through catching the error in the VB.Net codebehind? All things considered, I'd rather save the error checking for an actual error. Secondly, is there a preferred method to squirrel out a particular OLE DB error out of the general object caught by the try->catch block other than just checking the actual stack trace string?

SQL Query - The main gist of the code is that, due to the design of the database, I have to determine the name of the actual table being targeted manually. The database records jobs in a single table, but each job also gets its own table for processing data on the items processed in that job, and it's data from those tables I have to retrieve. Absolutely nothing I can do about this setup, unfortunately. [code]

View 1 Replies

What's Preferred Way In Visual Studio Designer To Add Attribute To Control

Aug 5, 2011

I need to add attributes to certain controls in a Windows Forms project. It needs to look something like this: [code] I can go in and edit the designer file to get more-or-less the desired effect, but those designer files sometimes come with the caveat that they are automatically-generated files. I'm worried that the designer might overwrite any changes that I make to the file. That said, is there a way to add attributes to controls using the designer or is there some way that I can add the attributes in a separate file?

View 1 Replies

List View Techniques - Populate The Corresponding Data Elements On Another Form?

Jul 18, 2011

I have the following "contact" data (exampled below) stored in an xml file.I've created a frmContacts windows form and placed a list box control inside it.I'm new to the list box but plan to have the users manage the list by letting them add, delete, and pick from it. For searching there should also be a sort function/button (by last name then first name).If the user deletes from the list the corresponding data in the file will be deleted.If the user picks from or adds to the list, I'd like to find the best way to populate the corresponding data elements on another form (i.e., in their respective text boxes). This will include the ability to edit/save from this other form too.

<?xml version="1.0" encoding="utf-8"?>
<Rows>
<Row>[code]......

View 1 Replies

Preferred Size Values For Forms While Taking Borders Into Account?

Jun 14, 2011

I'm modifying an existing form in Visual Basic 2010 Express and attempting to work out some small kinks I've noticed. The one that I'm having an issue with is getting the form to completely fill the screen without the border going off screen. When I set the form's Size values at W:1024,H:768 the page always opens a little off. I tried setting the size a little smaller, W:1020,H:764, and it still does not perfectly fill the screen. Does the Size value include the border pixels or are the border pixels added to the form's Size value? Is there another value somewhere that could be affecting this?

View 5 Replies

VS 2010 Any Tips Or Techniques For Debugging In Mouse Move Events / When Mouse Button Is Down / Has To Stay That Way?

Jun 6, 2011

I'm currently debugging a form that sets a flag when the mouse button is pressed, then clears the flag when the mouse button is released. As long as the mouse button is pressed, the user can move the mouse around and a few things happen depending on where they move. One of the things that happens is that a timer starts, or stops, and a few things change color depending on the mouse position. The timer starts when it should, then stops when it should, but once stopped, it is not re-starting when it should. I can verify that MouseMove events are getting through, because coloring changes as I move the mouse, as it should. This would be a simple thing to debug...except that it requires the darn mouse button to be down, and it uses the mouse move event. Anybody who has put a breakpoint in a mouse move event handler knows the issue: There are THOUSANDS of them. Worse yet, since the mouse button is necessary for switching to the IDE, as well as setting a breakpoint (technically, a keyboard shortcut could do this if I could shift focus), I can't wait for the problem to happen, then switch to the IDE and set a breakpoint to see what is happening then.Does anybody have any tips or techniques for debugging in mouse move events when the mouse button is down and has to stay that way? As it is, I'm going to have to write some funky code into the method just so that I have a place to get a breakpoint when I need it without breaking on every one of the mouse move events.

View 7 Replies

Visual Studio 2010 - Techniques For Not Allowing Program To Enter "Not Responding Mode"?

Jun 6, 2011

I have a program that runs a pretty long operation in the background once a user clicks the button. I have implemented a progress bar but if the window is touched or moved then it grays out and says (Not repsonding). Everything still works and when the operation finishes the program resumes function. (But a user would not know this

View 3 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved