|
|
Hy everyone!
I do want to generalize some comparestatements or assignstatments in my C# proggy. I managed to do so when I had a sender object (casting it) but now there is none and I am stuck.
My datastructure looks like this:
ldata contains the data
this looks like this
ldata[]
||=> keys[]
|| ||=> keyID //id of the field to display the data in
|| ||=> telnumber //the data to being displayed
||=> telefonID //the telefonnumber for which to display data
the telefonID should not matter, you can switch the numbers but only one of those is displayed at once, meaning you select one and the data for this number is displayed. But this doesn't matter concering my problem because at this stage the number has already been selected and I do just have to display the data for the selected number or check for changes before either switching numbers or just to save them.
My code looks like this at the moment:
for(li=0;li<ldata[0].keys.Length;li++)<br />
{<br />
if(ldata[0].keys[li].keyId==1)<br />
{<br />
txtNameKey01.Text=ldata[0].keys[li].telephoneNo;<br />
}<br />
}<br />
<br />
for(li=0;li<lTelephone[0].keys.Length;li++)<br />
{<br />
if (lTelephone[0].keys[li].keyId==1)<br />
{<br />
if (lTelephone[0].keys[li].telephoneNo!=txtNameKey01.Text)<br />
}<br />
}
But well this isn't nice and even harder to change lets say to 24 TextBoxes, but well it works . What I do want to do now is change the thing above to something like
for(li=0;li<ldata[0].keys.Length;li++)<br />
{<br />
TextBox=ldata[0].keys[li].telnumber;<br />
}
The pseudocode above and beneeth should describe what I want to do. I do want to create a general object/variable/... whatever to just having to assign or compare in one statement. I do want the keyID to describe where the data should be sent to or which fielddata should be compared to.
With strings you are able to copy parts together like "hello"+"world"+year.ToString() => hello world 2004 but this doesn't work with assignments, does it?
for(li=0;li<lTelephone[0].keys.Length;li++)<br />
{<br />
if (lTelephone[0].keys[li].telephoneNo!=TextBox.Text)<br />
}
in the pseudocode above once again it should be using the keyID to decide which TextBox I am really doing the comparison with.
But at the moment I do wonder if this is really possible or if I have to live with this if-statements and with tons of code for comparison and assignments!
Thanks!
Stephan.
|
|
|
|
|
If I got it right, you can easily do it by creating an array and put references to your textboxes there:
<br />
TextBox []theArray = { TextBox1, TextBox2, TextBox3, ..., TextBox12 };<br />
Then your if becomes
<br />
if (lTelephone[0].keys[li].telephoneNo!=theArray[i].Text)<br />
If an Array is not enough, you can use a Hashtable, an ArrayList, and so on.
People often overlook the fact that controls are simply objects like any other object.
Yes, even I am blogging now!
|
|
|
|
|
Thanks, it works!
I could have thought about this (enumbering the elements) myself, especially after having read it when trying to find a solution but throwing it away thinking it doesn't fit in here!
Stephan.
|
|
|
|
|
Hi there,
One of you bright sparks will know this off the top of your head (any supporting links you have greatful!)
Question: Do MS Collection Class Enumerators use strong reference to keep collection alive?
Background: Want to create collection in delegate function and set IEnumerator references from the parameters of the function to collections created in the function. This is so the delegate can use whatever collection it likes internally - as long as I can enumerate through the results on the other side it doesn't matter.
If MS use Weak Reference in enumerators then that would mean the collection isn't guarnteed to still be there when I go to use the IEnumerators. If it's a normal strong reference then that should keep the collection safe from the clutches of the GC.
Thoughts and answers greatly appreciated!
/**********************************
Paul Evans, Dorset, UK.
**********************************/
|
|
|
|
|
|
Hi all,
i am writing a small custom windows forms application in c# which will ultiamtely be for sale - i hope
i am wondering...when i have created the application i want to control access to it via a license key which i could provide. the user could enter this and it will (validate) and allow them to legally use this software. i want it to be a one of license key validation.
as i am new to c# please excuse my lack of knowledge - can anyone give me any tips on how to handle the above? i have noticed the license manager and License Provider key words but i am unsure where to start
i would like to have some sort of initial entry window allowing my key i provide to be used only on that host pc...i.e. i want to somehow tie the license key to the host when they first install??...
any advice/code/tips no matter how small is appreciated
|
|
|
|
|
There are so many ways of doing this, but you really need to research the problem. Keep in mind that anything a user installs on their local machine is possible to crack. All you can do is make it hard for them. Unfortunately, due to the nature of .NET assemblies, they can be disassembled, changed, and reassembled. Even relying on a native executable (C/C++ DLL) can be gotten around by disassembling the .NET assembly into IL, removing the call(s) to your native executable, and reassembling it (all using tools provided even in the .NET Framework SDK).
The LicenseProvider and related classes are more for design-time components (although a runtime option exists, I'm not sure it's currently supported). You can read more about these in the .NET Framework SDK (just type "LicenseProvider" in the .NET Framework SDK documentation that is installed with the .NET Framework SDK, which is installed by default with VS.NET).
I wrote an article you might want to take a look at, entitled Using XML Digital Signatures for Application Licensing[^]. This is one way you can implement both design-time and runtime licensing (though the actual implementation is up to you, but I do discuss various methods).
There are many others.
For instance, there is a pretty good library we evaluated from XHEO[^] that does - for some types of licensing it supports - use a similar idea for what I wrote about above. It also supports going out to a server on the 'net and verifying a license (a little more secure, but once again that could be removed if disassembled).
Basically, what I'm trying to say is that .NET applications are nearly as secure as natively compiled applications (decompiling these is extremely difficult and can only be done with best-guest mechanisms that are a long way from complete). All you can do is make it hard for the user and keep in mind that most users won't have the slightest clue about how to circumvent your application (though one crafty person could post how or post cracked binaries).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hey,
This is my first post here, I am trying to find the name of a program given a .exe file.....I have been banging my head against this for the last few days and am alomst going insane.
Any help would be appreciated.
I have the full path of the file eg c:/windows/sample.exe and from this i am trying to get a program name that I can output for a user to see.
Cheers
|
|
|
|
|
The simple answer is that you cannot.
What you see in the Start Menu and on icons in the Quick Launch bar and Desktop are the result of shortcuts (.lnk files)
If you are the author of the programs then you can write a mechanism that will expose a user friendly name, otherwise there is no consistent or reliable way to do that for third party applications.
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell
Can't manage to P/Invoke that Win32 API in .NET? Why not do interop the wiki way!
|
|
|
|
|
Firstly, thanks for the quick response.
But surely, there must be a way.
I have retrived the icon using SHGetFileInfo() in shell32.dll, i have a full path name, etc...
Where and how, for instance, does XP get the description field in file properties when you right click on a file, or in this case executable? I know this information is only stored when running an NTFS, but even that would be a start.
Or where does the value for the registry entry in MUICache come from? I tried searching the registry for a reliable location, without any luck.
????
Thanks from,
Slowly going insane.....
|
|
|
|
|
There is a way, but keep in mind that it may not be the actual application title. That is set by the application at runtime only and it could be hard-coded into their source, grabbed from a resource string, or just about anything else.
Some of the information displayed in a file's properties (in the "Version" tab for an executable) can be obtained from the FileVersionInfo class like so:
FileVersionInfo info = FileVersionInfo.GetFileVersionInfo(
"%SystemRoot%\notepad.exe");
Console.WriteLine(info.ProductName); See the documentation for the FileVersionInfo class in the .NET Framework SDK for more information.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I need to serialize a COM object from the .NET environment. Can anyone help me?
|
|
|
|
|
That really depends on what interfaces the COM object implements. If it implements any of the IPersist * interfaces (IPersistFile , IPersistStream , IPersistStreamInit , etc.) then you need to declare those interfaces (the .NET BCLs already declare the IPersistFile and IStream interfaces as UCOMIPersistFile and UCOMIStream , respectively) where the methods are in the right order and the interfaces are attributed with the ComImportAttribute , the GuidAttribute (with the right IID of the interface), and the right InterfaceTypeAttribute (to declare it as an IUnknown , IDispatch , or dual interface).
You cast the COM object in managed code (assuming you have a reference to it in managed code) to one of those interfaces in order for the CLR to do a QueryInterface for that method. Then you call Load , Save , or whatever is appropriate and pass the filename, an IStream implementation, or anything else that is required by the IPersist * interface.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi,
Im trying to implement a function where a message will pop up, say a week before a particular expiry date and every day after that, until the expiry date..can anyone tell me whats the best way to go around this..and is there a namespace to make this function easier?
CODER
|
|
|
|
|
ASGill wrote:
Im trying to implement a function where a message will pop up, say a week before a particular expiry date and every day after that, until the expiry date
That is a bit vague. What is the mechanism for determining the expiry date. At what point is the message to pop-up? (Application start? Or is is supposed to sit in the background somewhere until it needs to display a reminder?)
ASGill wrote:
and is there a namespace to make this function easier?
What do you mean by this? Do you mean is there a class to make this easier? Perhaps the System.Threading.Timer[^] class would be helpful.
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell
Can't manage to P/Invoke that Win32 API in .NET? Why not do interop the wiki way!
|
|
|
|
|
well the message is supposed to sit in the background and pops up when it needs to display a reminder.
thx for the information abt the class...ill look into it.
CODER
|
|
|
|
|
Look up the System.PopupWindows.ExpiryDateNotifyBallon class
|
|
|
|
|
Hi,
I want to convert variables of type double to type float in my C# app.
I've read that casting from a double to float results in the double being rounded to the nearest float value. That is exactly what I need (as opposed to truncation).
However, I've also seen that the Convert.ToSingle(double) method uses rounding as well to convert the double to a float.
Is there any difference between these two techniques - casting and ToSingle? Are there scenarios in which one is preferable over the other? What about overhead?
Thanks!
|
|
|
|
|
I don't know technical point of this but from my personal expirience I ecourage everyone to use Convert.To... over casting because several times it happened to me that (casting) produced error and on contratry Convert.To... never made any trouble.
|
|
|
|
|
crushinghellhammer wrote:
Is there any difference between these two techniques - casting and ToSingle?
The basic difference is that a cast can thrown an exception which means anytime you cast something you should also wrap it in a try/catch block to handle any exception that is thrown. This in turn emits additional IL instructions, not much but it's there.
- Nick Parker My Blog | My Articles
|
|
|
|
|
I want to create a secure Access-Database from C#.
I want to create a Database and a Systemdatabase - I suppose this works only in the same time.
Why does the following code not work?
private void button1_Click(object sender, System.EventArgs e)<br />
{<br />
ADOX.Catalog catalog = new ADOX.Catalog();<br />
catalog.Create("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=e:\\new.mdb;Jet OLEDB:System Database=e:\\new.mdw;Jet OLEDB:Create System Database=true");<br />
}
- it creates the e:\new.mdb but fails to create the e:\new.mdw.
the e:\new.mdb is not accessible.
I use Visual Studio 2003 and I have tried this
- on W2K with installed Access97 and Access2000 and
- on WXP with installed Access2003
All with the same result.
|
|
|
|
|
Hi,
In Visual c# 2005 Express, the code below will throw the following exception when accessing www.amazon.com. This does not happen in older versions of the .NET Framework. Why is this happening? Not sure what the violation here is. Using a different program, I can see that the returned headers by amazon.com look like this:
HTTP/1.1 301 Moved Permanently
Date: Tue, 27 Jul 2004 18:54:05 GMT
Server: Stronghold/2.4.2 Apache/1.3.6 C2NetEU/2412 (Unix) amarewrite/0.1 mod_fastcgi/2.2.12
Set-Cookie: skin=; domain=.amazon.com; path=/; expires=Wed, 01-Aug-01 12:00:00 GMT
Location: http://www.amazon.com:80/exec/obidos/subst/home/home.html
Connection: close
Content-Type: text/plain
EXCEPTION:
at System.Net.HttpWebRequest.CheckFinalStatus(Boolean mustThrow)
at System.Net.HttpWebRequest.GetResponse()
at ProtocolViolation.ProtocolViolation.GetHTML(String url_) in c:\documents a
nd settings\administrator\local settings\application data\temporary projects\con
soleapplication1\program.cs:line 21
CODE:
using System;
using System.Net;
namespace ProtocolViolation
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class ProtocolViolation
{
public static string GetHTML(string url_)
{
HttpWebResponse response = null;
HttpWebRequest request = null;
try
{
request = (HttpWebRequest)(WebRequest.Create(url_));
response = (HttpWebResponse)request.GetResponse();
}
catch (Exception e)
{
Console.WriteLine(e);
}
finally
{
if (response != null)
{
response.Close();
}
request = null;
response = null;
}
return "";
}
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
while (true)
{
GetHTML("http://www.amazon.com:80/exec/obidos/subst/home/home.html");
}
}
}
}
Thanx, amir
|
|
|
|
|
Why don't you try something like this:
private string GetHtml(string url)
{
WebRequest wreq;
WebResponse wres;
StreamReader sr;
String content = string.Empty;
wreq = HttpWebRequest.Create(url);
wres = wreq.GetResponse();
sr = new StreamReader(wres.GetResponseStream());
content = sr.ReadToEnd();
sr.Close();
return content;
}
- Nick Parker My Blog | My Articles
|
|
|
|
|
That does not solve the problem. I still get an exception. It would solve it if casting the response would be the cause of the problem. It goes deeper than that into issues with GetResponse(). This is not happening in .NET Framework versions lower than 2.0
You need to DL the C# .NET 2005 Express to see this happening.
Amir
|
|
|
|