Comments (18)
😟😟😟我刚也遇到你这个问题。。。。 感觉Rust中不好弄。。。
from rust-vcl.
这样是否可以
#![feature(trait_alias)]
pub trait TNotifyEvent = Fn(i32) -> i32;
fn test(f: impl TNotifyEvent) {
println!("{}", f(10));
}
fn callback(i: i32) -> i32 {
i * 10
}
let x = 10;
test(MainForm::callback);
test(|i:i32| i + x);
from rust-vcl.
这个得要看lclapi.rs
中doEventCallback
事件中能不能更好的处理这种了
from rust-vcl.
我试了下, 貌似不好实现,而且我现在这个版本貌似开启了
#![feature(trait_alias)]
也不能编译通过。
from rust-vcl.
确实 我试过,
#[link(name = "liblcl")]
extern "system" {
// ...
pub fn MainMenu_SetOnChange(AObj: usize, AEventId: TMenuChangeEvent);
// ...
}
impl trait不能往里传。
from rust-vcl.
试了很多种方法都无解,分析了下汇编代码,
像这种的:
TMainForm::test(testEvent);
在汇编中生成了一个拷贝版:
lea rcx, [rbp+var_20] ; void (__fastcall *__ptr32 *)(int)
mov edx, 0Ah ; int
call _ZN4core3ops8function2Fn4call17h31c4630f33dae3cfE ; core::ops::function::Fn::call::h31c4630f33dae3cf
jmp short $+2
_ZN4core3ops8function2Fn4call17h31c4630f33dae3cfE
这个实际内部直接调用的原来的。。。。
sub rsp, 38h
mov [rsp+38h+var_C], edx
mov [rsp+38h+var_8], rcx
mov ecx, [rsp+38h+var_C] ; int
call _ZN7apptest9testEvent17hb62bbdb09a071e27E ; apptest::testEvent::hb62bbdb09a071e27
nop
add rsp, 38h
retn
_ZN7apptest9testEvent17hb62bbdb09a071e27E
实际上就是testEvent
。
最终他的调就大概就是这样:
f: impl TNotifyEvent -> _ZN4core3ops8function2Fn4call17h31c4630f33dae3cfE(&f, 10); -> testEvent(10);
PS:要实现估计得另想办法了
from rust-vcl.
做了种实验性的,虽然没有实现你说的那种,但是现在是用的下面的这样的:
fn onBtnColorDialogClick(&self, _sender: usize) {
if self.dlgColor.Execute() {
let color = self.dlgColor.Color();
println!("color={}", color);
self.form.SetColor(color);
}
}
from rust-vcl.
好的,麻烦你了,我把govcl的examples写一遍学习学习。
from rust-vcl.
ImplISId
是不是用用derive更好点。
from rust-vcl.
是的,刚写好这个
from rust-vcl.
不过你要拿rust把govcl的例子写一遍感觉很累的。。。
新的Form定义现在是这样:
#[derive(VclForm)]
pub struct TForm2 {
btn: TButton,
pub form: TForm, // 固定名form, 放最后,前面引用完后,后面move到form。
}
App的:
#[derive(VclApp)]
struct TApp {
mainForm: TMainForm,
form2: TForm2,
}
from rust-vcl.
感谢,没什么,学习一下
from rust-vcl.
Set系列函数是否可以返回self让其支持链式调用:
form.SetWidth(800).SetHeight(600);
from rust-vcl.
有个问题,比如:
fn Test1(&self) -> &Self {
// 这地方应该是返回 self还是&self呢,,我测试好像都没问题
self
&self
}
from rust-vcl.
应该是rust特有的吧,我也不太了解,我试着&&self一样可以,这里我觉得用self就可以了。
我查了下可能是编译器优化掉了,参考链接:
https://users.rust-lang.org/t/reference-to-a-reference/44753
from rust-vcl.
查了下,用self就行了:
pub fn init(&self) -> &Self {
let sid = self.getSId();
// TForm
self.form
.SetCaption("你好,Rust! - Hello Rust!")
.SetWidth(200)
.SetHeight(300)
.EnabledMaximize(false)
.SetPosition(TPosition::poScreenCenter);
// TButton
self.btn.SetParent(self)
.SetCaption("msgbox")
.SetOnClick(sid, Self::onBtnClick)
.AnchorHorizontalCenterTo(self)
.AnchorVerticalCenterTo(self);
return self;
}
from rust-vcl.
好的 谢谢了 我先关闭了 有问题再来请教。
from rust-vcl.
好的,请教不敢当,一起讨论讨论,我学Rust也就几天时间而已。自己都还是一知半解的😂😂😂
看了下汇编代码,&self和 self是一样的,编译器会优化掉:
pub fn Test1(&self) -> &Self {
&self
}
mov rax, [rsp+38h+var_10] ; return &self;
pub fn Test2(&self) -> &Self {
self
}
mov rax, [rsp+48h+var_28] ; return self;
from rust-vcl.
Related Issues (7)
- x86下LNK2019错误 HOT 13
- MessageDlg相关问题 HOT 4
- 类似TMouseButton的enum比较问题 HOT 2
- to_RustString导出 HOT 47
- Error HOT 23
- TTreeView类名不对 HOT 2
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 rust-vcl.