本文介绍了做什么的目的(MyJobject为ILocalObject).GetObjectID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在delphi Tokyo源代码中,我看到了两种检索服务管理器"

In delphi Tokyo source code i see this 2 differents way to retrieve a "service Manager"

var FLocationManager: JLocationManager;
FLocationManager := TJLocationManager.Wrap(TAndroidHelper.Context.getSystemService(TJContext.JavaClass.LOCATION_SERVICE));

和:

var FNotificationManager: JNotificationManager;
var NotificationServiceNative: JObject;
NotificationServiceNative := TAndroidHelper.Context.getSystemService(TJContext.JavaClass.NOTIFICATION_SERVICE);
FNotificationManager := TJNotificationManager.Wrap((NotificationServiceNative as ILocalObject).GetObjectID);

这两种方式之间到底有什么区别?为什么在第二种情况下会这样做(NotificationServiceNative 作为ILocalObject)?GetObjectID ,而不是在第一种情况下?

What is exactly the difference between these 2 ways ? why in the second case they do (NotificationServiceNative as ILocalObject).GetObjectID and not in the first case ?

推荐答案

将Java对象引用投射到 ILocalObject 并提取其 ObjectID 正确使用 Wrap()将对象引用转换为另一种对象类型的方法.

Casting a Java object reference to ILocalObject and extracting its ObjectID is the correct way to convert the object reference to another object type using Wrap().

但是,的较短方法是有效的,因为 Wrap()具有一个重载,该重载将Java对象引用作为输入并在内部调用 GetObjectID ,然后 Wrap()就是这样.

However, the shorter way also works, because Wrap() has an overload that takes a Java object reference as input and internally calls GetObjectID on it and then Wrap()'s that.

因此,要回答您的问题-并没有真正的区别.两种方法都可以.

So, to answer your question - there is no real difference. Both ways work.

较长的代码可能只是从较早版本的Delphi继承而来的?我不记得 Wrap()重载是否始终存在.当然,在德尔福(Delphi)对Android的早期支持中,您总是必须手动获取 ObjectID . Wrap()重载可能是在以后添加的,也许并不是所有的FMX代码都可以利用它.

The longer code might simply be a carry-over from an older version of Delphi? I don't recall if the Wrap() overload always existed. Certainly in the early days of Android support in Delp you always had to get the ObjectID manually. The Wrap() overload was likely added later, and maybe not all FMX code takes advantage of it yet.

这篇关于做什么的目的(MyJobject为ILocalObject).GetObjectID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 09:59