Comments (5)
我修改了下,这样写才对,有可能被GC
package main
import (
"unsafe"
"github.com/ying32/govcl/vcl"
)
type Person struct {
Name string
}
func main() {
// 这里已经是指针了
p1 := &Person{}
p1.Name = "Tom"
strList := vcl.NewStringList()
// 要记得添加内存释放的
defer strList.Free()
// 这里直接使用
strList.AddObject("item1", vcl.ObjectFromInst(uintptr(unsafe.Pointer(p1))))
// 这里要获取指针的实例地址
item1 := (*Person)(unsafe.Pointer(strList.Objects(0).Instance()))
println("Name = " + item1.Name)
}
from govcl.
前面我的测试代码有个笔误:
strList.AddObject("item1", vcl.ObjectFromInst(uintptr(unsafe.Pointer(&p1))))
后面取了指针的指针,所以怎么试都崩溃,用上面你改的示例可以运行。
但拿到事件回调函数中获取就不行了,应该是被gc了。可能需要类似ListView和TreeView那样的改造。
from govcl.
你检出下dev分支的代码,然后这样写个看看
package main
import (
"unsafe"
"github.com/ying32/govcl/vcl"
)
type Person struct {
Name string
}
func main() {
// 这里已经是指针了
p1 := &Person{}
p1.Name = "Tom"
strList := vcl.NewStringList()
// 要记得添加内存释放的
defer strList.Free()
// 这里直接使用
strList.AddObject("item1", vcl.ObjectFromUnsafePointer(unsafe.Pointer(p1)))
item1 := (*Person)(strList.Objects(0).UnsafeAddr())
println("Name = " + item1.Name)
}
from govcl.
checkout了dev分支测试了一下,上面的代码运行OK。在事件回调中测试也OK,完美!
from govcl.
哈哈,遇到GC上面的代码也不知道会有不会啥意外的
from govcl.
Related Issues (20)
- 去掉黑框问题 HOT 4
- TPageControl has no TabVisible property available HOT 2
- 请问GoVCLDesigner😍是开源的吗? HOT 2
- initFile 中readDate、readTime、readDateTime三个返回的是0,导致解析成1970-01-01.... HOT 2
- res2go doesn't work. HOT 8
- 这几个组件是不支持吗? HOT 2
- res2go插件包名无法删除 HOT 1
- 生成名称属性已更改的控件时出错 HOT 2
- 怎么将go image包的Image转换成vcl.IGraphic实例? HOT 15
- 怎么让一个画布重绘? HOT 2
- example中有很多gfm文件,用lazarus也打不开啊。要怎么转换格式才能打开呢 HOT 1
- 报错 HOT 3
- Button的Caption值能否支持换行,或使用其他控件 HOT 1
- TreeView再SetData后,用Data函数得到的指针总是错的。TreeNode的地址总是在改变,尽管里面的Instance指针是不变的 HOT 1
- 能否支持Virtual TreeView呢? HOT 1
- windows系统下,管理员检测不对 HOT 2
- MacOS 下面XButton的Caption字体模糊 HOT 7
- 为什么不使用 syscall.LazyDLL 加载 liblcl 模块? 应该允许用户在调用 vcl.Application.Initialize 初始化之前动态释放 liblcl模块. HOT 1
- mac平台go build报错 HOT 3
- 自定义 LibName 不支持 go1.21.1 以上版本 HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from govcl.