xsharp.eu • New to X# and need some direction - Page 5
Page 5 of 8

New to X# and need some direction

Posted: Tue Jun 26, 2018 12:56 pm
by lumberjack
Hi Tom,
tom@dieselworks.com.au wrote:
I am not sure if this si a reference issue also?
error XS0120: An object reference is required for the non-static field, method, or property 'ReadableRangeService<Account>.GetRange(CompanyFile, string, ICompanyFileCredentials, string)' 85,19 Form1.prg MYOB_Test1
The forum is not very friendly to go back to find your source code to solve the error. Can you please also add the line of code that is creating the error when you post.

Regards,

New to X# and need some direction

Posted: Tue Jun 26, 2018 1:03 pm
by lumberjack
Please ignore this message, my next message is applicable. I leave it here for Tom to better understand reading error messages in .NET
Sorry for any inconvenience.
lumberjack wrote:Hi Tom,
tom@dieselworks.com.au wrote:
I am not sure if this si a reference issue also?
error XS0120: An object reference is required for the non-static field, method, or property 'ReadableRangeService<Account>.GetRange(CompanyFile, string, ICompanyFileCredentials, string)' 85,19 Form1.prg MYOB_Test1

Code: Select all

VAR accounts := accountService.GetRange(companyFile,NULL,credentials)
Ok finally found it. Look at GetRange, the second parameter in the error is "string". In your example we pass NULL, that should give you and indication that you need to have a "string" variable declared that you pass in. Not knowing the MYOB Assembly I do suggest you get ILSpy as quickly as possible going, it helps a lot in identifying these issues. Obviously you need to add the X# plug-in for full benefit otherwise you need to know c#.
HTH,

New to X# and need some direction

Posted: Tue Jun 26, 2018 1:11 pm
by lumberjack
Hi Tom,
tom@dieselworks.com.au wrote:
I am not sure if this si a reference issue also?
error XS0120: An object reference is required for the non-static field, method, or property 'ReadableRangeService<Account>.GetRange(CompanyFile, string, ICompanyFileCredentials, string)' 85,19 Form1.prg MYOB_Test1

Code: Select all

VAR accounts := accountService.GetRange(companyFile,NULL,credentials)
Ok, too fast in my reply. Look at GetRange, the 2nd and 4th parameters in the error is "string". In your example we pass NULL, but only 3 parameters. Change your code to:

Code: Select all

VAR accounts := accountService.GetRange(companyFile,NULL,credentials, NULL)
Let us know what happens then.

HTH,

New to X# and need some direction

Posted: Tue Jun 26, 2018 1:54 pm
by tom@dieselworks.com.au
Thanks Johan
Have tried with lost of hope but bugger, still the same :-(

See attached pic - also this is the current code:

using System.Windows.Forms
#using System.Drawing
#using System.LinQ

#using MYOB.AccountRight.SDK
#using MYOB.AccountRight.SDK.Services
#using MYOB.AccountRight.SDK.Services.GeneralLedger
#using MYOB.AccountRight.SDK.Contracts


//USING MYOB.AccountRight.SDK
//USING MYOB.AccountRight.SDK.Services
//USING MYOB.AccountRight.SDK.Contracts

CLASS BasicForm INHERIT System.Windows.Forms.Form

PROTECT oTextBox AS System.Windows.Forms.TextBox
PROTECT oOKButton AS System.Windows.Forms.Button
// User code starts here (DO NOT remove this line) ##USER##

CONSTRUCTOR()

SUPER()
SELF:InitializeForm()

RETURN

METHOD InitializeForm() AS VOID

// IDE generated code (please DO NOT modify)

SELF:oTextBox := System.Windows.Forms.TextBox{}
SELF:oOKButton := System.Windows.Forms.Button{}

SELF:SuspendLayout()

SELF:ClientSize := System.Drawing.Size{392 , 264}
SELF:Location := System.Drawing.Point{100 , 100}
SELF:Name := "BasicForm"
SELF:Text := "Basic form application"

SELF:oTextBox:Location := System.Drawing.Point{8 , 48}
SELF:oTextBox:Name := "TextBox"
SELF:oTextBox:Size := System.Drawing.Size{341 , 20}
SELF:oTextBox:TabIndex := 1
SELF:Controls:Add(SELF:oTextBox)

SELF:oOKButton:Click += SELF:OKButtonClick
SELF:oOKButton:Location := System.Drawing.Point{280 , 232}
SELF:oOKButton:Name := "OKButton"
SELF:oOKButton:Size := System.Drawing.Size{104 , 24}
SELF:oOKButton:TabIndex := 0
SELF:oOKButton:Text := "&OK"
SELF:Controls:Add(SELF:oOKButton)

SELF:ResumeLayout()

RETURN

METHOD OKButtonClick(sender AS OBJECT , e AS System.EventArgs) AS VOID

//SELF:Close()
SELF:OKButtonClick2()
// SELF:oTextBox:Text := "Ok"
RETURN

METHOD OKButtonClick2() AS VOID

VAR configuration := ApiConfiguration{"http://localhost:8080/accountright"}
VAR cfService := CompanyFileService{configuration}
VAR companyFiles := cfService.GetRange()

SELF:oTextBox:Text :="Company Files set"


VAR companyFile := companyFiles.FirstOrDefault({x => Version{x:ProductVersion} >= Version{"2013.3"}})


VAR credentials := CompanyFileCredentials{"Administrator","muffin023H"}


VAR accountService := AccountService{configuration}

VAR accounts := accountService.GetRange(companyFile,NULL,credentials,NULL)

RETURN

END CLASS
XIDE_LastError.JPG
XIDE_LastError.JPG (65.05 KiB) Viewed 532 times

New to X# and need some direction

Posted: Tue Jun 26, 2018 2:06 pm
by lumberjack
Hi Tom,
Try replace your OkButtonClick2 with this code. Let us know the result.
tom@dieselworks.com.au wrote:
Have tried with lost of hope but bugger, still the same :-(
also this is the current code:

Code: Select all

METHOD OKButtonClick2() AS VOID
LOCAL s1, s2 AS STRING
//s1 := "" // Uncomment these lines if the code still give an error
//s2 := ""
VAR configuration 	:= ApiConfiguration{"http://localhost:8080/accountright"}
VAR cfService 		:= CompanyFileService{configuration}
VAR companyFiles 	:= cfService.GetRange() 
SELF:oTextBox:Text 	:="Company Files set"
VAR companyFile 	:= companyFiles.FirstOrDefault({x => Version{x:ProductVersion} >= Version{"2013.3"}})
VAR credentials 	:= CompanyFileCredentials{"Administrator","muffin023H"}
VAR accountService 	:= AccountService{configuration}   
VAR accounts 		:= accountService.GetRange(companyFile,s1,credentials,s2)  
RETURN

New to X# and need some direction

Posted: Tue Jun 26, 2018 2:12 pm
by tom@dieselworks.com.au
Copied in and tested, no change.

New to X# and need some direction

Posted: Tue Jun 26, 2018 2:53 pm
by lumberjack
Hi Tom,

Ok think I know what is wrong. You should not have this code in a Form class. See below:
Go to your Program.cs and change

Code: Select all

Application.Run(new Form1());
to

Code: Select all

public static Form1 form1 = new Form1(); // Place this var out of the constructor
Application.Run(form1);
Now you can access a control with

Code: Select all

Program.form1.<Your control>
So unfortunately it seems you will have to move the code to outside your Form.

Code: Select all

FUNCTION Start() AS VOID
// Need here to call something.  My first impression is a static class.... HELP!!!
MYOBInterfaceClass.MYOBInit()
Application.Run(oForm1)
RETURN

STATIC MYOBInterfaceClass
STATIC METHOD MYOBInit() AS VOID/LOGIC ?
VAR configuration 	:= ApiConfiguration{"http://localhost:8080/accountright"}
VAR cfService 		:= CompanyFileService{configuration}
VAR companyFiles 	:= cfService.GetRange() 
//SELF:oTextBox:Text 	:="Company Files set"
VAR companyFile 	:= companyFiles.FirstOrDefault({x => Version{x:ProductVersion} >= Version{"2013.3"}})
VAR credentials 	:= CompanyFileCredentials{"Administrator","muffin023H"}
VAR accountService 	:= AccountService{configuration}   
VAR accounts 		:= accountService.GetRange(companyFile,NULL,credentials,NULL)
RETURN
At this point one of the experts like Robert need to get involved. It does make sense to me since you want the above variables to be accessible globally in your application. Just never did something where I needed static variables.

I do believe we now very close if somebody with knowledge of this can jump in here.

Hope we now on the right track!

New to X# and need some direction

Posted: Tue Jun 26, 2018 3:06 pm
by wriedmann
Hi Johan,

I have such a class in nearly all of my applications:

Code: Select all

class SyncSettings
static protect _oCurrent as SyncSettings
protect _cAppName as string

static constructor() 

_oCurrent := SyncSettings{} 
_oCurrent:InitSettings()
	
return

protect constructor()	// Instanzierung unterbinden
	
return				

method InitSettings() as logic

  _cAppName := "SuperOfficeSync"	

  return true

static method GetInstance() as SyncSettings
	
	return _oCurrent                        

static property AppName as string get _oCurrent:_cAppName

end class
This class can be used as follows:

Code: Select all

cVar := SyncSettings.AppName
HTH

Wolfgang

New to X# and need some direction

Posted: Tue Jun 26, 2018 3:30 pm
by lumberjack
Hi Wolfgang,
Thanks. Yes you are correct. Problem is if Tom will make sense of this.
Tom can you create such an MYOBSetting class with your code in it?
Regards,
PS: Think somebody else need to get in here that can help. Got an article to finish and I still need to do the coding for it.

New to X# and need some direction

Posted: Tue Jun 26, 2018 4:42 pm
by NickFriend
Stupid idea, but hell it's worth a try....given that X# is not case sensitive and you have

Code: Select all

VAR accountService 	:= AccountService{configuration}   
VAR accounts 		:= accountService.GetRange(companyFile,NULL,credentials,NULL)
with the class and variable names the same, and implicit type inference (VAR), how about just changing it to

Code: Select all

VAR myaccountService 	:= AccountService{configuration}   
VAR accounts 		:= myaccountService.GetRange(companyFile,NULL,credentials,NULL)
or explicity declaring the type

Code: Select all

ReadableRangeService<Account> accountService 	:= AccountService{configuration}   
VAR accounts 		:= accountService.GetRange(companyFile,NULL,credentials,NULL)
HTH

Nick