How can you create button dynamically with event handler in Visual C++? - visual-c++-2013

I have this:
btn->Click += gcnew EventHandler(this->dynamic);
but it says that a delegate constructor expects 2 arguments. What is wrong?

According to https://msdn.microsoft.com/en-us/library/system.eventhandler(v=vs.110).aspx
The constructor for EventHandler is:
EventHandler(
object sender,
EventArgs e
)
In your code you have provided this->dynamic which I would assume is your object sender. So you are missing EventArgs e.

Related

How can I use the ItemHeaderTapped event of the devexpress.maui.controls tabview?

The goal is to load/reload data for a tab when it is selected.
However for some reason I can't get it to run.
The code in xaml file looks like this:
...
<dxco:TabView ItemHeaderTapped="LoadTab">
<dxco:TabViewItem HeaderText="Tab1">
...
</dxco:TabViewItem>
...
</dxco:TabView>
On the SampleViewModel file I tried this:
private void LoadTab(Object sender, ItemHeaderTappedEventArgs e)
{
...
}
I also tried EventArgs instead of ItemHeaderTappedEventArgs.
But in both cases I get the error:
"EventHandler 'LoadTab' with correct signature not found in type Project.View.SamplePage"
Documentation to this Event is found here:
https://docs.devexpress.com/MAUI/DevExpress.Maui.Controls.TabView.ItemHeaderTapped
What am I doing wrong? Any help appreciated as I could not find any further information using google.

I'm making a Roblox exploit using WeAreDevs and I have this error. What is the problem with my text? (CS1061)

public partial class Form1 : Form {
WeAreDevs_API.ExploitAPI aPI = new WeAreDevs_API.ExploitAPI();
public Form1() {
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e) {
aPI.LaunchExploit();
}
private void button2_Click(object sender, EventArgs e) {
fastColoredTextBox1.Clear();
}
private void button3_Click(object sender, EventArgs e) {
aPI.SendFullLuaScript(fastColoredTextBox1.Text);
}
}
This is my problem something close to the ExploitApi Area.
According to Microsoft's docs around the compiler error, CS1061, this is caused by trying to call a function or access a property on an object that does not have that field.
Looking at the documentation for the WeAreDevs API, it looks like SendFullLuaScript() isn't a real function. It looks like you want SendScript() instead.
Be aware that exploits are explicitly disallowed in Roblox's Terms of Service and you will likely be banned if you are caught using them.
In WeAreDevs API (V1), there isn't any function named SendFullLuaScript(). You must replace the SendFullLuaScript() fuction to SendLimitedLuaScript() function.
Using these exploit are violating Roblox's Terms of Service. And WeAreDevs API is not a good exploit to exploiting secure. Yeah, if you continue exploiting, it is very high quality to will be get banned from Roblox.
Goodluck ^^
Replace
aPI.SendFullLuaScript(fastColoredTextBox1.Text);
with
aPI.SendLuaScript(fastColoredTextBox1.Text);
Viewing the documenation: https://wearedevs.net/d/Exploit%20API, SendFullLuaScript is not a method of the latest version of the API. The previous method name was SendLimitedLuaScript, but that is now deprecated in favor of SendLuaScript.

Exception when using static dbcontext with entitydatasource with onContextCreating

I want to share a single dbcontext across a session. I understand there are a number of issues with using shared, cached Dbcontexts.
So I create a global dbcontext and save it in a static class variable.
I am able create select, create new entities, do inserts and updates via the dbcontext in code behind calls without a problem
I want to use the same dbcontext in my entitydatasource controls within my webforms, for concurrency reasons. I do this by using the OnContextCreating and ONContextdisposing Events. This works fine for reading data but when I try and do an update via a entitydatasource (from a dataview, gridview etc) I get the following exception
AcceptChanges cannot continue because the object's key values conflict with
another object in the ObjectStateManager. Make sure that the key values are unique
before calling AcceptChanges.
I have reduced the system producing the error to a ef5.0 datamodel, using a single table and a single webform page with a single enitydatasource. I have reproduced the code below
public partial class _Default : Page
{
static QuantumDataEntities dbcontext = null;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void OnContextCreating(object sender, EntityDataSourceContextCreatingEventArgs e)
{
if (dbcontext == null)
dbcontext = new QuantumDataEntities();
e.Context = (dbcontext as IObjectContextAdapter).ObjectContext;
}
protected void OnContextDisposing(object sender, EntityDataSourceContextDisposingEventArgs e)
{
e.Cancel = true;
}
}
As you can see it is very simple. Whenever the Entitydatasource needs an objectcontext to read,update etc, it calls OnContextCreating. I am creating the dbcontext on the first OnContextCreating call, caching in a static class variable and reusing for future OnContextCreating calls. The OnContextCreating event is call a few times, first for page load, next for the post back when the edit button is pressed and finally (I think) for the actually dbsave.
If I get ride of the caching and just create a new dbcontext for each call it works fine. i.e
replace
if (dbcontext == null)
dbcontext = new QuantumDataEntities();
e.Context = (dbcontext as IObjectContextAdapter).ObjectContext;
with
dbcontext = new QuantumDataEntities();
e.Context = (dbcontext as IObjectContextAdapter).ObjectContext;
There is some other weirdness with this error. If I set up a OnUpdating event, that is supposed to get called before any updates are performed by the entitydataosource, it never gets called.
I have included the stack trace for the exception and the end of this text.
I would have like to test this with EF 6.0 Alpha 3, but the designers have moved the object context
into another assembly making it non compatible with entitydatasouce
This is a major roadblock to further development of our site. The only choice we have now is to move to a non shared dbcontext, which will cause a extreme performance issues (i.e loading the same 20K data set mutliple times on a page load - yes we can re-architect, we it will take weeks/months, which we dont have right now)
Questions ?
What is going on ?
Am I doing something wrong ? ( as opposed to poor architecture)
exception stack trace
[InvalidOperationException: AcceptChanges cannot continue because the object's key values conflict with another object in the ObjectStateManager. Make sure that the key values are unique before calling AcceptChanges.]
System.Data.Objects.ObjectStateManager.FixupKey(EntityEntry entry) +2518309
System.Data.Objects.EntityEntry.AcceptChanges() +159
System.Data.Objects.ObjectContext.AcceptAllChanges() +356
System.Web.UI.WebControls.EntityDataSourceView.ExecuteUpdate(IDictionary keys, IDictionary values, IDictionary oldValues) +376
System.Web.UI.DataSourceView.Update(IDictionary keys, IDictionary values, IDictionary oldValues, DataSourceViewOperationCallback callback) +87
System.Web.UI.WebControls.DetailsView.HandleUpdate(String commandArg, Boolean causesValidation) +1091
System.Web.UI.WebControls.DetailsView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) +425
System.Web.UI.WebControls.DetailsView.OnBubbleEvent(Object source, EventArgs e) +89
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
System.Web.UI.WebControls.DetailsViewRow.OnBubbleEvent(Object source, EventArgs e) +80
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) +121
System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) +156
System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +9642898
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1724

Calling a class from another form

I am trying to call to class from form2 in C# for, example below is code from "Form2".
private void button17_Click(object sender, EventArgs e)
{
Form1 frontmain = new Form1();
frontmain.buttonchange();
this.Hide();
}
This will not excute the class in "Form1" called "buttonchange." Below is the code for the "buttonchange" class:
public void buttonchange()
{
button1.Text = workshop1;
button2.Text = workshop2;
button3.Text = workshop3;
button4.Text = workshop4;
button5.Text = workshop5;
{
I assume it has something to do with privacy settings between form1 and form2 however I have never found the solution. I have always worked around it somehow. Does anyone know what the issue is here?
I would set up events on form2 and set up form1 to capture the form1 events.
Here is a link to setting up events:
http://msdn.microsoft.com/en-us/library/awbftdfh.aspx
You're creating a new instance of Form1 and calling code upon that, which is probably not what you actually intend to do.
If you're trying to refer to an existing instance of Form1, then you'll need to refer to that (rather than create a new instance).
If an instance of Form1 spawns the form that your click handler is in, you can refer to it like this:
Form1 frontmain = this.Owner as Form1;
If an instance of Form1 doesn't spawn your second form with the click handler, then you will need to take an event-based approach (which is a better approach anyway, as it eliminates dependencies).

Event Handler behavioral difference .net 1.1 vs 2.0 with null delegate

Not sure what exactly is going on here, but seems like in .NET 1.1 an uninitialized event delegate can run without issues, but in .NET 2.0+ it causes a NullReferenceException. Any ideas why. The code below will run fine without issues in 1.1, in 2.0 it gives a NullReferenceException. I'm curious why does it behave differently? What changed?
Thanks
eg
class Class1
{
public delegate void ChartJoinedRowAddedHandler(object sender);
public static event ChartJoinedRowAddedHandler ChartJoinedRowAdded;
public static DataTable dt;
public static void Main()
{
dt = new DataTable();
dt.RowChanged += new DataRowChangeEventHandler(TableEventHandler);
object [] obj = new object[]{1,2};
dt.Columns.Add("Name");
dt.Columns.Add("Last");
dt.NewRow();
dt.Rows.Add(obj);
}
private static void TableEventHandler(object sender, DataRowChangeEventArgs e)
{
ChartJoinedRowAdded(new object());
}
}
[updated] AFAIK, there was no change here to the fundamental delegate handling; the difference is in how DataTable behaves.
However! Be very careful using static events, especially if you are subscribing from instances (rather than static methods). This is a good way to keep huge swathes of objects alive and not be garbage collected.
Running the code via csc from 1.1 shows that the general delegate side is the same - I think the difference is that the DataTable code that raises RowChanged was swallowing the exception. For example, make the code like below:
Console.WriteLine("Before");
ChartJoinedRowAdded(new object());
Console.WriteLine("After");
You'll see "Before", but no "After"; an exception was thrown and swallowed by the DataTable.
The eventhandler system is basically just a list of functions to call when a given event is raised.
It initializes to the "null" list, and not the empty list, so you need to do
if (ChartJoinedRowAdded != null)
ChartJoinedRowAdded(new object())
The way events work hasn't really changed from 1.1 to 2
Although the syntax looks like normal aggregation it really isn't:
dt.RowChanged += TableEventHandler;
dt.RowChanged += null;
dt.RowChanged += delegate (object sender, DataRowChangeEventArgs e) {
//anon
};
Will fire TableEventHandler and then the delegate - the null is just skipped.
You can use null to clear events, but only inside the event firing class:
this.MyEvent = null;
If nothing subscribes your event will be null - see soraz's answer. The DataTable class will contain a similar check and won't fire the event if there are no subscribers.
The standard pattern is:
//events should just about always use this pattern: object, args
public static event EventHandler<MyEventArgs> ChartJoinedRowAdded;
//inheriting classes can override this event behaviour
protected virtual OnChartJoinedRowAdded() {
if( ChartJoinedRowAdded != null )
ChartJoinedRowAdded( this, new MyEventArgs(...) );
}