c# - Cannot access a non-static member of outer type XXX via nested type with a third-party provided class -


this problem has been addressed in sof in general. however, unable (not competent enough) apply suggestions example. getting "cannot access non-static member of outer type 'fixclienttest.form1' via nested type ... " error. in case, nested type instantiation of 3rd party provided class (in case, open-source quickfix/n library). understand source not relevant trying avoid suggestion might have me modifying code , don't have knowledge around problem. goal update form controls based on information in callbacks library. (the code below simple form 2 buttons, 1 set event callbacks , other stop them.) appreciate suggestions community might have.

thank you.

using system; using system.linq; using system.text; using system.threading.tasks; using system.windows.forms; using quickfix;  namespace fixclienttest {     public partial class form1 : form     {         public form1()         {             initializecomponent();         }          public class myquickfixapp : quickfix.iapplication         {                 public void fromapp(quickfix.message msg, sessionid sessionid) { }             public void oncreate(sessionid sessionid) { }             public void onlogout(sessionid sessionid)              {                 console.writeline("logged out.");             }             public void onlogon(sessionid sessionid)              {                 console.writeline("logged in.");             }             public void fromadmin(quickfix.message msg, sessionid sessionid)              {                 //loglistview.items.add(msg.tostring()); <<generates error!              }             public void toadmin(quickfix.message msg, sessionid sessionid) { }             public void toapp(quickfix.message msg, sessionid sessionid) { }         }          public quickfix.transport.socketinitiator _initiator = null;          private void connectbutton_click(object sender, eventargs e)         {             string file = "c:/fix/tradeclientib.cfg";             try             {                 quickfix.sessionsettings settings = new quickfix.sessionsettings(file);                 quickfix.iapplication myapp = new myquickfixapp();                 quickfix.imessagestorefactory storefactory = new quickfix.filestorefactory(settings);                 quickfix.ilogfactory logfactory = new quickfix.screenlogfactory(settings);                 _initiator = new quickfix.transport.socketinitiator(myapp, storefactory, settings, logfactory);                    _initiator.start();              }             catch (system.exception err)             {                 messagebox.show(err.tostring());             }         }          private void stopbutton_click(object sender, eventargs e)         {             _initiator.stop();         }     } } 

your myquickfixapp class doesn't know form1 object.

first, i'd suggest moving out of form1 class. then, i'd @ how , when myquickfixapp object created. i'm not familiar quickfix library, quick glance @ docs suggests creating in button message handler isn't right way this. (in winforms app i'd imagine you'd create in program.main method).

as actual error, need give myquickfixapp object reference form1 object (probably pass in constructor).

public class myquickfixapp : quickfix.iapplication {     private readonly form1 _form1;     public myquickfixapp(form1 form)     {        _form1 = form;     }      public void fromadmin(quickfix.message msg, sessionid sessionid)      {         _form1.loglistview.items.add(msg.tostring());     } } 

Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -