Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

运行不起来,可以提供下完整的demo吗 #3

Open
reghtml opened this issue Apr 25, 2020 · 1 comment
Open

运行不起来,可以提供下完整的demo吗 #3

reghtml opened this issue Apr 25, 2020 · 1 comment

Comments

@reghtml
Copy link

reghtml commented Apr 25, 2020

运行提示如下:

panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x20 pc=0x52a42c]

goroutine 1 [running]:
github.com/suiyunonghen/GVCL/Components/Controls.(*WApplication).Run(0xc000148000)
D:/GO/GOPATH/src/github.com/suiyunonghen/GVCL/Components/Controls/Forms.go:154 +0xec
main.main()
D:/GO/GoProject/003-gvcl/main.go:69 +0x2cd

Process finished with exit code 2

我的代码:
package main

import (
controls "github.com/suiyunonghen/GVCL/Components/Controls"
"github.com/suiyunonghen/GVCL/WinApi"
)

type GForm1 struct {
controls.GForm
Button1 *controls.GButton
Edit1 *controls.GEdit
}

func NewForm1(app *controls.WApplication) *GForm1 {
frm := new(GForm1)
frm.SubInit()
frm.Button1 = controls.NewButton(frm)
frm.Button1.SetWidth(80)
frm.Button1.SetHeight(30)
frm.Button1.SetLeft(frm.Width() - 90)
frm.Button1.SetTop(frm.Height() - 80)
frm.Button1.SetCaption("确定关闭")

frm.Edit1 = controls.NewEdit(frm)
frm.OnClose = func(sender interface{}, closeAction *int8) {
	*closeAction = controls.CAFree
}
frm.Button1.OnClick = func(sender interface{}) {
	WinApi.MessageBox(frm.GetWindowHandle(), "sadf", "Asdf", 64)
	frm.SetModalResult(controls.MrOK)
}
return frm

}

func main() {
app := new(controls.WApplication)
app.ShowMainForm = true
m := app.CreateForm()
m.SetLeft(200)
m.SetTop(50)
m.SetCaption("测试窗体")

e := controls.NewEdit(m)
e.SetName("Edit1")
e.SetLeft(10)
e.SetWidth(100)
e.SetHeight(20)
e.SetCaption("测试")
b := controls.NewButton(m)
b.SetDefault(true)
b.SetLeft(120)
b.SetCaption("创建窗体")
b.OnClick = func(sender interface{}) {
	tmpm := NewForm1(app)
	tmpm.SetCaption(e.GetText())
	if tmpm.ShowModal() == controls.MrOK {
		WinApi.MessageBox(tmpm.GetWindowHandle(), "程序确定退出", "消息", 64)
	}
}

b1 := controls.NewButton(m)
b1.SetCaption("关闭")
b1.SetLeft(100)
b1.SetTop(40)
b1.OnClick = func(sender interface{}) {
	b.SetVisible(!b.Visible())
	b.SetCaption("测试")
}
app.Run()

}

@suiyunonghen
Copy link
Owner

运行提示如下:

panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x20 pc=0x52a42c]

goroutine 1 [running]:
github.com/suiyunonghen/GVCL/Components/Controls.(*WApplication).Run(0xc000148000)
D:/GO/GOPATH/src/github.com/suiyunonghen/GVCL/Components/Controls/Forms.go:154 +0xec
main.main()
D:/GO/GoProject/003-gvcl/main.go:69 +0x2cd

Process finished with exit code 2

我的代码:
package main

import (
controls "github.com/suiyunonghen/GVCL/Components/Controls"
"github.com/suiyunonghen/GVCL/WinApi"
)

type GForm1 struct {
controls.GForm
Button1 *controls.GButton
Edit1 *controls.GEdit
}

func NewForm1(app *controls.WApplication) *GForm1 {
frm := new(GForm1)
frm.SubInit()
frm.Button1 = controls.NewButton(frm)
frm.Button1.SetWidth(80)
frm.Button1.SetHeight(30)
frm.Button1.SetLeft(frm.Width() - 90)
frm.Button1.SetTop(frm.Height() - 80)
frm.Button1.SetCaption("确定关闭")

frm.Edit1 = controls.NewEdit(frm)
frm.OnClose = func(sender interface{}, closeAction *int8) {
	*closeAction = controls.CAFree
}
frm.Button1.OnClick = func(sender interface{}) {
	WinApi.MessageBox(frm.GetWindowHandle(), "sadf", "Asdf", 64)
	frm.SetModalResult(controls.MrOK)
}
return frm

}

func main() {
app := new(controls.WApplication)
app.ShowMainForm = true
m := app.CreateForm()
m.SetLeft(200)
m.SetTop(50)
m.SetCaption("测试窗体")

e := controls.NewEdit(m)
e.SetName("Edit1")
e.SetLeft(10)
e.SetWidth(100)
e.SetHeight(20)
e.SetCaption("测试")
b := controls.NewButton(m)
b.SetDefault(true)
b.SetLeft(120)
b.SetCaption("创建窗体")
b.OnClick = func(sender interface{}) {
	tmpm := NewForm1(app)
	tmpm.SetCaption(e.GetText())
	if tmpm.ShowModal() == controls.MrOK {
		WinApi.MessageBox(tmpm.GetWindowHandle(), "程序确定退出", "消息", 64)
	}
}

b1 := controls.NewButton(m)
b1.SetCaption("关闭")
b1.SetLeft(100)
b1.SetTop(40)
b1.OnClick = func(sender interface{}) {
	b.SetVisible(!b.Visible())
	b.SetCaption("测试")
}
app.Run()

}

那个建立Application的时候,不要你创建,需要用GVCL中的函数
app := controls.NewApplication()
然后里面提供有一个例子啊,test就是的啊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants