|
Hmm. Getting replies today that I just don't understand. Guess I picked a bad day to stop smoking crack.
led mike
|
|
|
|
|
We've discussed this before...."Hook up!" is yelled when a big game fish
(tuna, yellowtail, wahoo, etc.) grabs a lure while trolling from a sportfishing
boat.
Judging by the OP's reply above, you've been hooked
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark Salsbery wrote: We've discussed this before...."Hook up!"
Ah yes, now I remember. At least now I understand your reply.
led mike
|
|
|
|
|
A simple newbie question about interfaces if I may.. Should I be able to do the following:
ClassA classA = new ClassA();
IClass iclass = (IClass)classA;
ClassB classB = (ClassB)iclass;
Assuming both ClassA and ClassB implement IClass. I get an InvalidCastException (which may answer my question) but thought I should be able to do it? Thanks
|
|
|
|
|
Hi,
well I think this is not working because the iclass-reference points to an ClassA object and not to an ClassB object. So it's correct that you get an InvalidCastException.
Was this helpful?
Regards
Sebastian
|
|
|
|
|
No you shouldn't.
I'll go through your code line by line and explain what is happening.
This line creates a new object of type ClassA and assigns it to the classA variable
ClassA classA = new ClassA();
This line takes that ClassA object and casts it into a IClass type variable. Note that the object itself is still a ClassA object, it's just being stored in a variable that is IClass
IClass iclass = (IClass)classA; Now you have an IClass object, you can only call methods on it that are part of that interface. You can't call ClassA specific methods on it, but it is still a ClassA object, so when you call those IClass methods, they are routed to the ClassA definitions for execution.
What you are trying to do here is cast an IClass object as a ClassB object. but the object isn't of type ClassB, it's of type ClassA, so the cast fails
ClassB classB = (ClassB)iclass;
This would work, because the object is a ClassA object, so can be cast as such.
ClassA aAgain = (ClassA)iclass; What your doing is like taking an apple, putting it in a box that is labelled "fruit", then trying to take the apple back out of the box and claim it is now an orange. Casting doesn't ever actually change the underlying type.
By the way, you don't actually need the first cast. because ClassA already inherits from IClass, you can just do the assignment without casting
IClass iclass = classA;
Simon
|
|
|
|
|
I like this one:
Simon Stevens wrote: What your doing is like taking an apple, putting it in a box that is labelled "fruit", then trying to take the apple back out of the box and claim it is now an orange.
Should remember this for next time explaining casts...
|
|
|
|
|
how to edit appconfig in windows application(C#)??
i am using this code but not getting success please help me
Code:-
Properties.Settings.Default.DestinationDrives = "ppc";
Properties.Settings.Default.Save();
Piyush Vardhan Singh
p_vardhan14@rediffmail.com
http://holyschoolofvaranasi.blogspot.com
http://holytravelsofvaranasi.blogspot.com
|
|
|
|
|
That code looks correct. What is the problem?
(Note that when you save user scope settings they aren't saved back to the app.config file, they are saved in the users local settings directory. If you close and reopen your app, you will find when you load the settings they will load correctly with the changed values)
Simon
|
|
|
|
|
...
Blog link to be reinstated at a later date.
|
|
|
|
|
How can i check in Run Time if in current machine that execute my application (exe file) has an active microphone ?
|
|
|
|
|
You can't detect if a microphone is physically connected or not. What you could do is monitor the sound levels and see if there is something coming in on the input.
Simon
|
|
|
|
|
Good Afternoon All
I dont know if am asking this in a Correct way Purdon me if i dont. I have a Help file that gets opened with "Windows Winhlp32 Stub. i need to Call this in C#, in my Menu, when a User Clicks Help it should Show this Menu. I have attached the Examples. How can i call this Files in C#.
http://www.vbforums.com/attachment.php?attachmentid=67180&stc=1&d=1224678042[^]"> Example
Thank you
Vuyiswa Maseko,
Sorrow is Better than Laughter, it may Sadden your Face, but It sharpens your Understanding
VB.NET/SQL7/2000/2005
http://vuyiswamb.007ihost.com
http://Ecadre.007ihost.com
vuyiswam@tshwane.gov.za
|
|
|
|
|
I have a foreach loop i want to write on one line of code. does anyone know a "one-Liner" for this. This must be fairly common but i havent found any.
List<animals> animals = (Fill list somehow...)
List<int> teeths = new List<int>();
foreach(Animal a in animals)
{
teeths.Add(a.TeethCount);
}
//i want Something like this:
List<int> teeths = animals.ExtractPropertyList(delegate(Animal ani){"return all Teeths"});
Anyone?
|
|
|
|
|
List<int> teeths = animals.ConvertAll<int>(delegate(Animal animal) { return animal.TeethCount; });
|
|
|
|
|
good stuff.
Exactly what i wanted.
|
|
|
|
|
If you use .Net 3.5 you can also do a LINQ query like this:
List<int> teeths = (from animal in animals select animal.TeethCount).ToList();
or (the behavior is the same):
List<int> teeths = animals.Select(animal => animal.TeethCount).ToList();
modified on Wednesday, October 22, 2008 8:21 AM
|
|
|
|
|
Hi all,
I have create data reports for my application.I want print report when user click print button on entry form(Not on report viewer) rather than it's shown through report viewer.If possible please send any sample code for that.
Thanks.
|
|
|
|
|
Hi,
I am executing a PowerPoint slide show file (.pps) from my C# source code using:
System.Diagnostics.Process extProcess = System.Diagnostics.Process.Start("xdsfr.pps");
extProcess.WaitForExit();
The problem here is my source code immediately continues to execute and does wait for PowerPoint to exit.
It seems that somehow extProcess receives "Exit" event from PowerPoint (although PowerPoint is still operating.) Because when I check for "HasExited" property of extProcess while debugging I can see it as "true".
Googling about the issue gave me nothing. If you guys can give me a hint, it is appreciated.
Thank you for your time,
Regards,
Always keep the Murphy Rules in mind!
|
|
|
|
|
I guess that when new process is started it calls another executable file and passes xdsfr.pps as an argument to it and the process itself exits so that's why your code doesn't stop. If my assumption is correct then you can try to find out which executable is being called and call it yourself or you can try if this helps: Using WMI to monitor process creation, deletion and modification in .NET[^]
|
|
|
|
|
I suspect its because you are not really executing xdsfr.pps, under the hood you are executing POWERPNT.EXE and passing the file name to it. Try executing POWERPNT.EXE and passing the file name as a parameter.
Bob
Ashfield Consultants Ltd
|
|
|
|
|
Thanx for the suggestion Bob,
Tried:
extProcess = System.Diagnostics.Process.Start("POWERPNT.EXE", filename);
and result is the same.
I will go with Giorgi's suggestion and see if it helps.
Thank you both guys.
Always keep the Murphy Rules in mind!
modified on Wednesday, October 22, 2008 6:48 AM
|
|
|
|
|
You need to use the proper command line arguments: http://pptfaq.com/FAQ00528.htm[^]
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 Blog
|
|
|
|
|
Thomas, thank you for your suggestion, I have tried the command line arguments but still my code does not wait for PowerPoint to exit.
Giorgi, I have modified and used the code that you have linked. But the Process that executes the pps file exits in no time, I could not catch any of the events through POWERPNT.exe when I added to ProcessWatcher.
I also tried to watch my own executable but it did not fire events too. I am not sure if I did all correctly I will keep trying for while.
Funny (or should I say sad for me) I am using the same method with Visio, but the code executes just as I have expected. When I call "xdsfr.vsd" (which I have exported in previous operations) my executable hangs up operation and waits until Visio exits...
Always keep the Murphy Rules in mind!
modified on Wednesday, October 22, 2008 10:18 AM
|
|
|
|
|
I have found the error.
And it is not related to the code that I have given.
For anyone who encounters the same mistake, here is my experience:
Since I use the POWERPNT.EXE in my previous operations, the Process for this executable is not properly disposed thats why I can still see the POWERPNT.EXE in my TaskManager/Processes tab. (This happens before the code in above posts is executed.)
Thats why when my code executes it seems that it cannot attach itself to POWERPNT.EXE.
When I managed to dispose POWERPNT.EXE process before executing the code, everything worked just fine.
Thanks for help guys,
Regards
Always keep the Murphy Rules in mind!
|
|
|
|