|
Vishal Dave wrote: Please advice.
Well how about looking at the exception and trying to determine what exactly it is complaining about.
|
|
|
|
|
Hi,
I am using late binding when creating a word object to generate a MS Word document from my C# program. I have successfully created tables and paragraphs, but now I am trying to format the paragraphs (left, justified, etc.).I want to insert headings (center aligned) using late binding.so can you please help?
modified on Monday, November 16, 2009 12:00 AM
|
|
|
|
|
public Ts GetMany<t, ts="">(BasicBO BO) where T : BasicBO
{
List<basicbo> BOList = DataAccess.Get(tc, BO);
List<t> TList = new List<t>();
foreach (BasicBO bo in BOList)
TList.Add((T)bo);
// error occured in the following statement
object result = typeof(Ts).GetType()
.InvokeMember("ctor",BindingFlags.CreateInstance, null, null, null);
typeof(Ts).GetMethod("AddRangeFromDB", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(result, new object[] { TList });
return (Ts)result;
}
error message is : Constructor on type 'System.RuntimeType' not found
Ts is a generic list of basicBO.
please explain it.
|
|
|
|
|
I'm not at my dev machine so I can't test this, but try removing GetType() from the line so you just have
object result = typeof(Ts).InvokeMember("ctor", BindingFlags.CreateInstance, null, null, null); My bet is that the Type instance you want is from typeof(Ts) , not typeof(Ts).GetType() .
Dybs
The shout of progress is not "Eureka!" it's "Strange... that's not what i expected". - peterchen
|
|
|
|
|
Thank you very much.
You are right. I didnt care about recoding of the line Ts.GetType(). but it is already retrieved with typeof(Ts). Now it works fine.
thank you
|
|
|
|
|
If it's generic, you must have lost your generic parameters.
You may also want to specify New in the where clause so you can instantiate the class directly rather than use Reflection. But I think one of the main problems is that the constructor's name is ".ctor".
Also, when using Reflection, you may want to cache the MethodInfo rather than get it over and over again.
|
|
|
|
|
What is Application.Run();
What is its real use?
I have read the msdn but I couldn't understand. Please give me a different and easy answer
|
|
|
|
|
Application.Run(form) shows the form, runs a message pump, and waits until the form gets closed.
it exists in the Main() method of most WinForm applications.
I've never used Application.Run() without form.
Luc Pattyn [Forum Guidelines] [My Articles]
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
I'm guessing it tells an Application to Run, but some context might be helpful.
|
|
|
|
|
|
I'll wait for the OP to give context; it could be some wacky WidgetCo.Application.Run .
|
|
|
|
|
You're not the adventurous type then?
Luc Pattyn [Forum Guidelines] [My Articles]
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
Jumping to conclusions doesn't pay.
|
|
|
|
|
|
How do you know that's what the OP means?
|
|
|
|
|
|
|
Windows is basically a message-driven system. Unlike the programming model we get to play with, where we "receive events" when they occur, each application actually has to make system calls to get messages for the application from the system. These messages are generated by the OS and/or other programs and represent information such as a key changing state from up to down, the mouse moving, the program needs to redraw itself, and a gazillion other things.
So crudely put, and surely leaving out lots of detail, the Run() method displays the form passed to it, implements a loop that calls the Windows GetMessage() function and processes the messages in the queue. Messages received will be passed to relevant controls and the controls in turn raise events, providing us with a way of plugging our custom code into this loop. When the application receives a WM_CLOSE message or the form closes, the loop terminates and the Main method returns, terminating the program.
This is also why normal Windows Forms apps are terrible for implementing things like games. The GetMessage() function blocks when the message queue for an application is empty, which is very good when the application *is* event-driven and doesn't need to do anything other than in response to some external event - because it let's Windows allocate CPU to other programs that do have something in their message queue. Games however need to keep working and drawing and calculating object movements and so on even if there are no external events. They therefore implement the message loop a little differently, calling the system function PeekMessage() instead, which never blocks but returns immediately even if there are no messages. That's great for games, but it also explains why games are so unfriendly multi-taskers - they always take a lot of resources.
A digression if I may: Unfortunately this does make some seemingly simple things a bit tricky to implement in Windows Forms apps. For example, let's say you want to do something *while* a mouse button is pressed, as opposed to in response to the transition from up to down or down to up. You could do this with a timer (which is a WM_TIMER message - the lowest-priority message of all Windows Messages), but it wouldn't be very nice. You might have to start another thread doing the work when the button is pressed and cause it to stop when the button is released, but that's a bit complicated too, because the controls are not thread-safe so this other thread can't update anything in the UI, but instead has to marshal calls back to the UI thread to do the updating... Of course, if the control had an event that fired on every iteration of the program loop as long as the mouse button is pressed this would solve the problem, but generally the controls don't have any such events!
|
|
|
|
|
Hello.
Is it possible to create a program in c#, so when you log on with your username and password, to a forum, so can i create what the user can do.
Also make so he can write on forums and so on.
Also a "virtuel" browser in the program?
-Ahlm
|
|
|
|
|
The question is not clear to me. Are you talking about a keylogger ??
|
|
|
|
|
No i ain't.
Well. Let me tell you a bit detailed then
You know EX. The code prjects login bar?
I want to make a program, where i can login with my program, and be logged in, in the program.
So can i design something with messageboards and so on, in the program, if you are logged on.
I hope you can understand me now
|
|
|
|
|
Hey,
I think CodeProject puts an authentication cookie in the browser, so that whenever the user comes back to the site, it checks if auth cookie is there in the browser and tries to authenticate with it.
so in your case, I think you need to do something like this.
Use
Response.Cookies["uid"].Value = userid;
Response.Cookies["pwd"].Value = passkey;
And whenever the login page is requested, first check
Request.Cookies["uid"].Value
Request.Cookies["pwd"].Value
and try to authenticate with them. If not successful show the login screen, otherwise show the home screen for that user.
Note :
It is always better to have this optional, as you might have a checkbox for Remember Me, to put the cookie in the browser.
|
|
|
|
|
Are you really serious when you say that CodeProject puts the password in the Session ?
|
|
|
|
|
Have I ever told you about storing password in session ??
I used the term cookie rather than session.
Most of the sites even Yahoo / google stores Authkeys in cookie fields once you choose "Remember Me". A warning is also put below the Remember me checkbox telling you not to check if you are in a shared computer.
In case of mozilla, passwords gets stored in browser too, obviously if you choose so.
Just open Tools -> Options -> Security ->Show passwords
This is actually browser password storage.
For your solution, you can also generate an Auth key which remains in database, store it in cookie. When the user navigates to the page, just get the auth key from cookie and then check with the auth element in database. Based on this you make the user authenticate (so you dont need password)
Hope you got the trick.
|
|
|
|
|
To me it sounds like a spammer, not a keylogger.
A program that can log in to forums and post messages on behalf of the user... Of course, he could just mean "a browser", or user-agent as it's more formally called!
In any event, if this interpretation is correct then yes, surely it's possible, at least if the site has no mechanisms to prevent programs from accessing it, such as CATCHPAs. But it isn't *easy* because it's an interface designed for humans and not programs. And it's not reliable because the interface might change at any time, and making a program interpret and understand the changes isn't easy. A browser only needs to understand how to display pages and how to post forms (well, there's a bit more to it but leaving aside scripts and plugins for the time being it is conceptually like this) and can rely on the human user to understand how to use the interface. An automated client has to either be intelligent enough to work out how to do so or make assumptions about what the requests it generates should be like.
If the site doesn't have any anti-bot measures (some use tests that aim to see if the client is a real browser as a less intrusive alternative to CATCHPAs, such as testing DOM functionality or JavaScript execution) at all, the easiest is probably to use an HTTP request analyzer (such as Fiddler) to see what requests are actually sent when you use your browser, and write a program that sends the same requests. Obviously this is likely to break as the site in question changes, but there's no way around that unless you solve problems the AI community are nowhere near solving after 50+ years of research. (Perhaps Jeff Hawkins and Numenta are closer though; at least their approach to machine intelligence seems to hold a lot more promise.)
|
|
|
|
|