New to X# and need some direction

Public support forum for peer to peer support with related to the Visual Objects and Vulcan.NET products
User avatar
lumberjack
Posts: 727
Joined: Fri Sep 25, 2015 3:11 pm
Location: South Africa

New to X# and need some direction

Post 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,
______________________
Johan Nel
Boshof, South Africa
User avatar
lumberjack
Posts: 727
Joined: Fri Sep 25, 2015 3:11 pm
Location: South Africa

New to X# and need some direction

Post 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,
______________________
Johan Nel
Boshof, South Africa
User avatar
lumberjack
Posts: 727
Joined: Fri Sep 25, 2015 3:11 pm
Location: South Africa

New to X# and need some direction

Post 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,
______________________
Johan Nel
Boshof, South Africa
tom@dieselworks.com.au

New to X# and need some direction

Post 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 502 times
User avatar
lumberjack
Posts: 727
Joined: Fri Sep 25, 2015 3:11 pm
Location: South Africa

New to X# and need some direction

Post 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
______________________
Johan Nel
Boshof, South Africa
tom@dieselworks.com.au

New to X# and need some direction

Post by tom@dieselworks.com.au »

Copied in and tested, no change.
Attachments
XIDE_LastError2.JPG
XIDE_LastError2.JPG (90.83 KiB) Viewed 502 times
User avatar
lumberjack
Posts: 727
Joined: Fri Sep 25, 2015 3:11 pm
Location: South Africa

New to X# and need some direction

Post 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!
______________________
Johan Nel
Boshof, South Africa
User avatar
wriedmann
Posts: 3754
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

New to X# and need some direction

Post 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
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
User avatar
lumberjack
Posts: 727
Joined: Fri Sep 25, 2015 3:11 pm
Location: South Africa

New to X# and need some direction

Post 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.
______________________
Johan Nel
Boshof, South Africa
NickFriend
Posts: 248
Joined: Fri Oct 14, 2016 7:09 am

New to X# and need some direction

Post 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
Post Reply