|
Thank u Mr. Gareth H
Nice solution...
.
.
thank u again
Genius.Boy
|
|
|
|
|
i made a error reporter and i want to display a "Debug" button on my form...
I want to only show this button if theirs a debugger installed...
basically i want to display the Just-In-Time debugger window.
Anyway to do this?
|
|
|
|
|
There is a precompiler option #if DEBUG that could work for you. Otherwise a series of if-statements is the only choice.
Need a C# Consultant? I'm available.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
|
|
|
|
|
FocusedWolf wrote: I want to only show this button if theirs a debugger installed...
Look at the Debugger class, specifically IsAttached , Attach() and Break() .
|
|
|
|
|
I have an database editing application. The tables in this application are sorted by ID (an autonumber field), so they are basically in FIFO order.
However, the editing part of the application consists of a DataGridView object to enable the user to view all the records in the table and some text boxes and comboboxes below the DataGridView to see the details of each individual record in the table.
The user edits or adds records through the text boxes and comboboxes that reflect the fields in the datatable, while the DataGridView is just for viewing (set to Edit Programmatically). The user, though, can sort records using the DataGridView to help him/her find records in the table by the order of some field other than the ID.
Well, when I add records to the table when the table is sorted according to, say, a serial number, I'm experiencing some problems. The record is added, but does not occupy the final position in the data table. Rather, it occupies the first position in the table because a new record consists of a blank serial number. Is there a way to keep from sorting the new record into the first position in the datatable? I would prefer to keep it as the last record in the table, and then sort it into its appropriate position.
Thanks.
|
|
|
|
|
Is there a way I can determine the name of the variable that is being accessed.
In the following example, when I call Item22.Description (or any other property of BigClass), I'd like to be able to find variablename (Item22 in this case).
class BigClass
{
public static Hashtable DescriptionsTable;
DataItem Item01;
....
DataItem Item64;
}
class DataItem
{
double _Value;
string Description
{ get { return BigClass.DescriptionsTable[variablename]; } }
}
If I don't have access to this name I figure I'll have to add a second property to BigClass for each Item (ex. Item22Description...), which seems like a waste. And I don't want to have the descriptions in each BigClass because they can get quite lengthy and there will be hundreds of BigClass instances at a time.
Any ideas?
If there's another option, how could I re-architect without wasting too much space?
|
|
|
|
|
The approach you are using is probably not ideal. The only thing I can think of is to eliminate the members and add an indexor.
Ideally, however, each property should access an individual member. It is the most logical method.
Need a C# Consultant? I'm available.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
|
|
|
|
|
You can't get the variable name from the object, as you are not accessing the variable. You are just accessing an object that the variable happens to be referencing. There is no backwards reference from the object to the variable.
If you want the DataItem object to know the name of the variable, you have to store the name in the object.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Hi
I am using reflection to write properties in some code. But, I don't need to fetch readonly properties. How can I check whether a property is readonly or not in .NET?
Please advise. Thanks
Pankaj
|
|
|
|
|
You can use the second line specifying the BindingFlags with a SetProperty which excludes all properties that don't include a set declaration on the property.
static IEnumerable<PropertyInfo> GetWritableProperties<T>()
{
Type type = typeof(T);
return type.GetProperties(BindingFlags.SetProperty);
}
I doubt it. If it isn't intuitive then we need to fix it. - Chris Maunder
|
|
|
|
|
Which is preferred, to pass a reference or use a return value
private DateTime SetToHour(DateTime timeCheck, int hours)
{
return timeCheck;
}
or
private void SetToHour(ref DateTime timeCheck, int hours)
{
}
I have done some searching online and asked around work, no definitive answer has come. Use ref for this and return for that. Mostly seems to personal choice. Thoughts???
this thing looks like it was written by an epileptic ferret
Dave Kreskowiak
|
|
|
|
|
Hi,
IMO a return value is the normal approach.
It has some drawbacks:
- you can return only one thing;
- if the return thingy is a reference type, then the API choice implies you must
create an object of that type, which you may or may not want to impose on the API users.
Hence, a ref parameter is acceptable and useful when:
- the function has to produce more than one thing;
- or the function is supposed to stuff some data in a pre-existing struct.
|
|
|
|
|
Thanks, answered my question succinctly.
this thing looks like it was written by an epileptic ferret
Dave Kreskowiak
|
|
|
|
|
In my opinion I'd use the non-ref method. The reason is, that many classes in the .NET framework are immutable, like string . Even more important, the DateTime class also uses return values (AddHours , AddMonths , etc.), which means that DateTime objects are immutable, too.
In C# 3.0 you could also use extension methods, for example like this:
public static class DateTimeExtensions
{
public static DateTime SetToHour(this DateTime source, int hours)
{
if ((hours < 0) || (hours > 23))
throw new ArgumentOutOfRangeException("Hours must be between 0 and 23");
return source.AddHours(hours - source.Hour);
}
}
and call it like that:
DateTime t = DateTime.Now;
Console.WriteLine(t);
t = t.SetToHour(24);
Console.WriteLine(t);
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
>>The reason is, that many classes in the .NET framework are immutable, like string.
Im not quite getting in what way you mean that would affect anything?
Its perfectly possible to pass a "ref string"
Even if the instance of a string is immutable doesnt mean that the variable reference to that instance is immutable...
Or do you just mean that the api would be more standard because other methods on immutable types work that way?
(In that case I agree , rule of least surprise)
|
|
|
|
|
Roger Alsing wrote:
Its perfectly possible to pass a "ref string"
Even if the instance of a string is immutable doesnt mean that the variable reference to that instance is immutable...
Absolutely correct - what I meant is that the .NET library methods for the string and DateTime objects (among others) do not modify the variable but rather return a new instance. So if you want to add another method to the DateTime class (by using extension methods or simply a utility class) I might be a good idea to do it in the same way like the original DateTime methods do, by returning a new instance.
modified 12-Sep-18 21:01pm.
|
|
|
|
|
I developed a C# console program to control a camera's PTZ, and I call remote procedures from a GUI to move left/right/up/down. As I have 2 WindowsXP computers my C# RPC's work great. QUESTION: I also need to drive this PTZ from a computer running Windows, but the coding environment is JAVA. What does the JAVA coder need to do in order to call my functions? thanks, xlthim
|
|
|
|
|
Couple ways to do this. A popular one seems to be utilizing Mono's IKVM[^].
Life, family, faith: Give me a visit.
From my latest post: "When Constantine severed the Hebrew origins of this faith in Messiah, a new religion was officially created. It is this religion that Orthodox Jews fear their relatives and friends becoming members of."
Judah Himango
|
|
|
|
|
I am trying to use a DLL which was originaly written in fortran. Allthough this DLL is suposed to be in C, a lot of its functions do not work in C# (some does). I believe it has fortran version as well as C version. Has anyone played with Fortran DLL in C#. I get the following errors during compilation.
AccessViolationException
BadImageFormatException
DllNotFoundException
YOu can go to this link http://www.originlab.com/index.aspx?s=8&lm=117&pid=251[^]
download the "examples in zip form". They have a simple DLL,FortranDLL, which contains basic functions such as double SUMFT(double, double), which returns the sum of two doubles. Can any one make it work? What do i need to make it work?
|
|
|
|
|
I believe you can P/Invoke into most (all?) Fortran calls. Have you tried this? The Numerical Algorithms Group shows how to call their Fortran dll from C#[^], perhaps that will get you off to a good start.
If this fails or doesn't work for certain calls, but you can access it via C++, you could write a C++/CLI (managed C++) dll that talks to the Fortran dll, then have your C# code talk to the C++/CLI dll. There are articles on this site that show you how to write simple C++/CLI dlls to call native code.
Life, family, faith: Give me a visit.
From my latest post: "When Constantine severed the Hebrew origins of this faith in Messiah, a new religion was officially created. It is this religion that Orthodox Jews fear their relatives and friends becoming members of."
Judah Himango
|
|
|
|
|
How may I stop a running method if it takes longer than 10 seconds. I want a procedure called hello() to be called 200 times in a loop & I want the method to be aborted & the loop to be broken if the hello() methods, fails to respond in 10 seconds. How may I do this?
|
|
|
|
|
semiramisContraA,
You've already asked that question Here[^]
Regards,
Gareth.
(FKA gareth111)
|
|
|
|
|
I know but unfortunately I didn't get any useful answers!
|
|
|
|
|
Do you want to break the loop if the total time is longer than 2000 seconds, or do you want each Hello call to time out after 10 seconds? Can your code handle some Hello calls running concurrently?
Semicolons: The number one seller of ostomy bags world wide. - dan neely
|
|
|
|
|
If you posted it somewhere already and you didn't get any un-useful answers, and you repost on the same site that exact same question then you will get the same un-useful answers and aggrivated codeprojectians as well.
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my homepage Oracle Studios
Discounted or Free Software for Students:
DreamSpark - downloads.channel8.msdn.com
MSDN Academic Alliance - www.msdnaa.com
|
|
|
|