Eiffel: How to get class of a Void object? is it possible? - eiffel

I have a void object which I declared, but want to get its class name is it possible??
item: detachable DB_ENTITY
db_connection.base_selection.query("SELECT * FROM " + item.generating_type.out)
Creating it is not what I want...

A type object (i.e. an object like the one returned by generating_type for an existing object) can be obtained using curly braces enclosing the type name:
{MY_TYPE}
In your example it would be {attached like item} if item is a feature (of type detachable DB_ENTITY to allow for a value Void), or {DB_ENTITY} if item is a local variable, so that the whole expression would read in one of the following ways:
db_connection.base_selection.query("SELECT * FROM " + ({attached like item}).out)
db_connection.base_selection.query("SELECT * FROM " + ({DB_ENTITY}).out)
In the second case, the corresponding string would be equivalent to "SELECT * FROM DB_ENTITY".

I would use
item_type_anchor: detachable DB_ENTITY
-- `item_type_anchor' for Current.
and then
db_connection.base_selection.query ("SELECT * FROM " + ({like item_type_anchor}).generating_type.out)
This means that the feature `item_type_anchor' clearly communicates that it does not expect to be attached, but is there as a type-anchor reference only. Used with the static reference Alex pointed out, the story is now clear and concise. :-)

Related

How do I encode an array of Byte32 values for Web3j to pass to my smart contract?

Contract function is defined as:
function createAggregate (string memory key, bytes32[2] memory part_array) public returns (bytes32)
and have incoming a list of parts, defined as...
List<Bytes32> elements
so was trying to use:
List<Type> items = new ArrayList<Type>();
items.add(...); // user reference
items.add(new DynamicArray<>(elements));
final Function function = new Function("createAggregate",
items,
Arrays.asList(new TypeReference<Bytes32>() {})
);
...
But this does not work, seems to be an encoding issue - what is the right what of encoding the Bytes32 ? (This seems to work fine for an array of strings)
Sort of solved this with the following (although was really looking for a more dynamic size solution)
new StaticArray2(Bytes32.class, Utils.typeMap(elements, Bytes32.class));

Eiffel: compilation error `Source of assignment is not compatible with target`

With complete void check set in compiler I've got a Variable is not properly set compilation error on following case which for me is right (in my mind). It says that the source of assignment is not compatible with target. What am I missing here??? (DB_SERVICE.load_from_primary_key...)
Class DB_SERVICE
deferred class
DB_SERVICE [G -> DB_ENTITY create make_from_db_result end]
inherit
ACTION
redefine
start,
execute
end
LOGGABLE
rename
make as make_from_loggable
end
feature -- Creation
make (a_db_connection: attached DB_CONNECTION)
require
valid_db_connection: a_db_connection.is_connected
do
make_from_loggable
db_connection := a_db_connection
create last_items.make (100)
create last_column_names.make_empty
ensure
db_connection_setted: a_db_connection = db_connection and db_connection.is_connected
end
feature -- Access
item: detachable G
db_connection: DB_CONNECTION
last_items: HASH_TABLE[like item, INTEGER] -- content of last resultset
last_column_names: ARRAY[STRING] -- Column names of last resultset
feature -- status_report
load_from_primary_key (primary_key: INTEGER)
-- Loads given item into item otherwise item will be Void
require
attached db_connection.base_selection
local
l_db_result: DB_RESULT
do
if attached db_connection.base_selection as bs then
bs.query ("SELECT * FROM " + ({attached like item}).out + " WHERE " + {attached like item}.Primary_key_db_column_name + "=" + primary_key.out)
if bs.is_ok then
bs.load_result
create item.make_from_db_result(last_column_names, bs.cursor)
else
item := Void --HERE is the compiler complaining!
logger.write_critical ("Error while retreiving " + ({like item}).out + " from DB")
end
else
item := Void
logger.write_error ("base_selection is void")
end
end
end -- class
Class COMPANY_SERVICE
class
COMPANY_SERVICE
inherit
DB_SERVICE[COMPANY]
redefine
make
end
...
Class COMPANY
class
COMPANY
inherit
DB_ENTITY
rename
primary_key as id,
set_primary_key as set_id,
Primary_key_db_column_name as Id_db_column_name
redefine
make,
make_from_db_result,
out
end
create
make,
make_from_db_result
....
The type declaration detachable G indicates that if the corresponding actual generic is a reference type, the variable of that type could be detachable. In that case it would be OK to assign Void to such a variable. However, it's also possible that the actual generic is an expanded type. Prefixing an expanded type with detachable has no effect, the type remains the same and the variable cannot be assigned Void.
As an example, let's consider a simpler case, when there is no formal generic constraint for the parameter G. An actual generic could be STRING, and the variable item has a type detachable STRING. In this case, it's OK to assign Void to item.
Now, if the actual generic is INTEGER, the variable has a type detachable INTEGER that is equivalent to INTEGER. Assigning Void to a variable of this type makes no sense and is not permitted by the language rules.
The variable item still can be set to Void if the actual generic parameter is a reference type. For that, a local variable with the same type can be declared and its value can be assigned to item:
local
default_item: like item
do
item := default_item

How do I remove an item from an array that consists of functions within a class?

When I try to remove an item from the following array:
var actualFormNamesFromFormClass = [Forms.iPhoneForm, Forms.AppleForm, Forms.swiftBirdForm, Forms.watchForm, Forms.macForm]
Using the following code:
actualFormNamesFromFormClass.remove(at: i)
I get the error "Expression resolves to an unused function". My array actualFormNamesFromFormClass consists of functions that construct an array of type [UIBezierPath]. I want to remove an item from the array at index i, but I get that error. The Forms is a class and after the dot is the function in that class.
You can always add _ = to the start:
_ = actualFormNamesFromFormClass.remove(at: i)
since _ means "I don't need this".

Weird data type mismatch error VBA [duplicate]

I need to pass a String array to set a class property using its setter method. Array was declared in Module and it's perfectly set the values using Redim Preserve. When calling the Class setter method it gives error. If I continued to without setting array data type it worked. But I need to declare the data type as String.
I received a compile error "Type mismatch: array or user defined type expected."
Module
Dim sPageDetails() As String
' set some values to array
' Declare class instance
dim x as new X
with x
.SetPageNumberDetails(sPageDetails) ' assume SetPageNumberDetails is the setter method in class X
end with
End module
'class module start X
Private pageDetails() as String
' Setter for pageDetails array
Public Sub SetPageNumberDetails(ByRef sPageDetails() As String)
pageDetails= sPageDetails
End Sub
' Getter for pageDetails array
Public Function GetPageNumberDetails() As String()
GetPageNumberDetails= pageDetails
End Function
.SetPageNumberDetails(sPageDetails)
Remove the parentheses:
.SetPageNumberDetails sPageDetails
Remain the parentheses and add explicit 'Call':
Call .SetPageNumberDetails(sPageDetails)
It took 5-10 CPU ticks (~30 nsec), but code wil be more readable, editable, auditable etc. And it is simply comme il faut...
.

Set value array with a query

I want to set this Array with the result of ths Query but I can't. How do I do it ?
String[] q = (from p in MDB.aspnet_Memberships
where p.aspnet_User.aspnet_UsersInRoles.Single().aspnet_Role.RoleName.ToString() == GroupDDL.SelectedItem.ToString()
select new{p.UserId }).ToArray();
Exception :
Cannot implicitly convert type 'AnonymousType#1[]' to 'string[]'
You're selecting a new anonymous object by using the braces. When you do "select new { p.UserID }", the compiler creates a brand new object type. You just want the userID's themselves, not a new object wrapping them up. Try just
select p.UserId).ToArray();
as your select clause.

Resources