How to call functions defined on __proto__ object under ui-grid - angular-ui-grid

I can see getCellValue function defined on proto object under grid instance.
I am calling the function like below:
grid.__proto__.getCellValue( row, col )
But during runtime calling getCellValue throws an exception in console like below:
TypeError: Cannot read property 'flatEntityAccess' of undefined
Is there any other way to access the functions defined on proto object in Ui-grid.
Thanks

There is no need to have the access of proto object. This objects is being internally inherit by the object instance. So we can make a call directly by
grid.getCellValue( row, col )

Related

How can I define a custom ant datatype that checks for required attributes?

Ideally, I would like to throw an exception or log an error at the point where the data type is instantiated, rather than at some later time when the data type instance is referenced.
Is there a method that gets invoked at the point where the data type instance has been fully configured with attributes (and child elements)?

Casting a JObject to a JList

To cast a JObject to a JList (or anything else, it doesn't matter, this is just an example), is just doing JList(MyJobject) a good way? I don't receive any error, but I'm not sure if it's the correct way to go.
When casting between different object types, you cannot use a plain type-cast. You must cast the JObject to ILocalObject and call its GetObjectID() method, and then pass that result to the Wrap() method of the destination class type, in this case TJList, eg:
For example:
var
MyJobject: JObject;
MyJList: JList;
MyJobject := ...;
MyJList := TJList.Wrap((MyJobject as ILocalObject).GetObjectID);
Or simpler (which is just a wrapper for the above):
var
MyJobject: JObject;
MyJList: JList;
MyJobject := ...;
MyJList := TJList.Wrap(MyJobject);
See What the purpose of doing (MyJobject as ILocalObject).GetObjectID
There are two possible problems with using plain typecast.
First, if particular Java class has not been initialized with previous Delphi code, its VMT table will not be initialized. Next, references returned by JNI calls are local references and they are only valid for the duration of particular native method.
JNI tips
Every argument passed to a native method, and almost every object
returned by a JNI function is a "local reference". This means that
it's valid for the duration of the current native method in the
current thread. Even if the object itself continues to live on after
the native method returns, the reference is not valid.
This applies to all sub-classes of jobject, including jclass, jstring,
and jarray. (The runtime will warn you about most reference mis-uses
when extended JNI checks are enabled.)
The only way to get non-local references is via the functions
NewGlobalRef and NewWeakGlobalRef.
If you want to hold on to a reference for a longer period, you must
use a "global" reference. The NewGlobalRef function takes the local
reference as an argument and returns a global one. The global
reference is guaranteed to be valid until you call DeleteGlobalRef.
Wrap solves both issues. It initializes Java class VMT if not already initialized and converts local JObject reference to global one.
Plain typecast can only work if class is initialized by some previous code and the local reference is not used outside native (Delphi) method that retrieved said reference.
That is why plain typecast used in JStringToString(JString(PurchaseDataList.get(I))) can work properly. JObject reference returned by get is immediately converted to Delphi string and JString VMT is already initialized at that point, being commonly used Java class.
When in doubt, using Wrap is safer, but it also takes more time than plain typecast.

Delphi 7 TListSortCompare that can access object properties

I'm writing a custom component that owns a Tlist of records . the problem is : how the TListSortCompare function -used to sort the list's records- can access component's fields ?
the compiler refuses object method as a list compareator , and in the component's unit there is no instance created yet to access .
Thanks
Wael
The compare function can't be a non-static class method, it has to be either a standalone function or a static class method, which means it has no Self parameter to directly access any component object, it only knows about the 2 input parameters that point to the records being compared.
So, the only ways for you to indirectly access the component object inside your compare function is if you either:
store a pointer to the component object in a global or threadvar variable.
store a pointer to the component object inside the records themselves.
use a thunk for the comparer, where the pointer to the component object is stored hidden inside the thunk itself (this is the technique the VCL uses internally to allow Win32 HWND message handlers to call TWinControl.WindowProc on a per-object basis).

property OnProcessEvent: TOnProcessEventProc read FOnProcessEvent write FOnProcessEvent;

I have come across a below function in a delphi code. I am quite new to delphi.There are quite a few places in Delphi where this function is called. However I can't seem to find the definition of this function. Could someone please explain what this means.
property OnProcessEvent: TOnProcessEventProc read FOnProcessEvent write FOnProcessEvent;
That declaration is not a function, it is a property, or more specifically an event. In that same class, you will see a data member named FOnProcessEvent of type TOnProcessEventProc. If you look at the declaration of TOnProcessEventProc, you will see that it is an alias for a method pointer of a specific signature, eg:
type
TOnProcessEventProc = procedure(Sender: TObject; ... other parameters here ...) of object;
That means any non-static class method that matches that signature can be assigned to the OnProcessEvent event. And if the event is declared as published, such a method can even be assigned at design-time instead of in code at run-time.
In the code for the class that declares the event property, all it has to do is call FOnProcessEvent() as if it were a procedure, eg:
if Assigned(FOnProcessEvent) then
FOnProcessEvent(Self, ... parameter values here ...);
Whatever method is actually assigned to FOnProcessEvent, if any, will be called.

What's the syntax on this line of code?

What's the syntax on this line of code (part of a script that create a html window and prints?)
function (write)
{var ctx=$(this)[offset]();
ctx[drawImage](this,ctx[left]-slidePos[left],ctx[top]-slidePos[top]);
});
This invokes the jQuery function and returns a jQuery object (referencing this in the current context):
$(this)
An object's properties (some of which may be functions) can be indexed on the object, so this is indexing a specific property:
$(this)[offset]
Turns out this property is a function, because it's invoked:
$(this)[offset]()
The returned result of that function is stored in a variable:
var ctx=$(this)[offset]()
That variable is presumably another object, which can also have its properties indexed:
ctx[drawImage]
And that indexed property can also be a function:
ctx[drawImage]()
That function takes three arguments:
ctx[drawImage](this,ctx[left]-slidePos[left],ctx[top]-slidePos[top])
The first argument is simply this in the current context. The second argument is an arithmetic expression of another property on that object minus a property on another object:
ctx[left]-slidePos[left]
So is the third argument:
ctx[top]-slidePos[top]
These two lines together are encapsulated within a function:
function (write)
{
// ...
}
Oddly enough, that function doesn't appear to use the write argument that it expects.

Resources