class property: Error: Illegal symbol for property access - lazarus

I have this variable, function, property combination
ffieldIntegerPrivate:Integer;
function getFieldIntegerPrivate:Integer;
class property fieldIntegerPrivate:Integer read getFieldIntegerPrivate;
and in the implementation I have
function TMyClass.getFieldIntegerPrivate:Integer;
begin
Result := ffieldIntegerPrivate;
end;
I get error: Error: Illegal symbol for property access
What could be the cause of this error?
Thanks in advance for your help.

Class property can only read class var.

The function needs the keyword static added.
function getFieldIntegerPrivate:Integer;static;

Related

Passing shared_ptr as an argument to thread function, results into an error

I am trying to do something similar as below:
std::shared_ptr<asengine::PreCompileConfig> precompileconfigobj = std::make_shared<asengine::PreCompileConfig>();
std::thread rsync_t(&asengine::PreCompile::RunRsyncDb, precompileconfigobj));
I get the following error:
/usr/include/c++/4.8/functional:1697:61: error: no type named 'type' in 'class std::result_of<std::_Mem_fn<void (asengine::PreCompile::*)(const std::shared_ptr<asengine::PreCompileConfig>&)>(std::reference_wrapper<std::shared_ptr<asengine::PreCompileConfig> >)>'
typedef typename result_of<_Callable(_Args...)>::type result_type;
^
/usr/include/c++/4.8/functional:1727:9: error: no type named 'type' in 'class std::result_of<std::_Mem_fn<void (asengine::PreCompile::*)(const std::shared_ptr<asengine::PreCompileConfig>&)>(std::reference_wrapper<std::shared_ptr<asengine::PreCompileConfig> >)>'
_M_invoke(_Index_tuple<_Indices...>)
After brief research, I could find out that thread function expects reference of the argument object, instead of value.
std::thread rsync_t(&asengine::PreCompile::RunRsyncDb, std::ref(precompileconfigobj));
But still, it doesn't solve the problem. Any help to figure out the problem would be appreciated.
I think I solved the problem. I had to pass the object through which thread function is going to be called.
std::thread rsync_t(&asengine::PreCompile::RunRsyncDb, precompileobj, std::ref(precompileconfigobj));

OMNET++ how to access function or variables in another class

I have modified inet NodeStatus.cc with a customized function that return the variable value as follows:
int NodeStatus::getValueA()
{
return ValueA;
}
Then, I created another simple module called simpleNodeB.cc and I wanted to retrieve ValueA from NodeStatus.cc. I tried the following code in simpleNodeB.cc but didn't work:
if(getParentModule()->getSubModule(NodeStatus).getValueA()==test1)
bubble("Value is the same");
The error message I got -> error: expected expected primary-expression before ')' token. I'm not sure if I used the correct way to call getValueA() function. Please enlighten me. thanks a lot.
There are many errors in your code.
The method getSubmodule requires a name of module, not a name of class. Look at your NED file and check the actual name of this module.
getSubmodule returns a pointer to the cModule object. It has to be manually cast into another class.
Assuming that an NodeStatus module in your NED is named fooStatus the correct code should look like:
cModule *mod = getParentModule()->getSubmodule("fooStatus");
NodeStatus *status = check_and_cast<NodeStatus*>(mod);
if(status->getValueA() == test1)
bubble("Value is the same");
Reference: OMNeT++ Manual.

How to expose an array of UDTs through a property?

I have a class cDept which has a UDT defined.
public type udtEmp
Name as string
Id as long
end type
I have an array defined:
private m_Emps() as udtEmp
I want to expose the array through a property. I tried the following:
Public Property Get Employees() As udtEmp()
Employees= m_Emps
End Property
So far everything compiles. Now I instantiate the class and try to access the property.
dim myUdt as udtEmp
dim oDept as cDept
set oDept = new cDept
myUdt = oDept.Employees(1) ' -- error
I get an error stating Wrong number of arguments or invalid property assignment.
What am I missing?
(Not tested)
I think your property access is trying to use the '1' as an argument to the property (which has no arguments), thus the 'wrong number' error. Rather than trying to property get the array and then index access the array, will it work to have the property get (or a different one) return the desired array element?
Public Property Get Employees(ndx as long) As udtEmp
Employees= m_Emps(ndx)
End Property

Can I use gcc visibility attributes on an enumeration?

I have the following enum:
__atttribute__((visibility ("default") )) enum MSG
{
OK,
FAIL,
};
When I compile, it gives me the warning:
warning: attribute ignored in declaration of ‘enum MSG’
warning: attribute for ‘enum MSG’ must follow the ‘enum’ keyword
When I put the attribute after the enum, I get the following errors:
warning: type attributes are honored only at type definition
error: use of enum ‘MSG’ without previous declaration
error: expected unqualified-id before ‘{’ token
Can anyone tell me how to fix this?
The visibility attribute applies to symbols like functions and variables. A definition of an enumeration type that doesn't contain a variable name doesn't create any symbols.
Enumeration type without a variable:
enum msg { OK, FAIL };
An enumeration variable:
enum msg message;
Enumeration type together with a variable:
enum msg { OK, FAIL } message;
In the first case, there's no symbol the visibility attribute could affect at all.
You can fix this by declaring the type of your enum like this:
enum class MSG : std::uint32_t __atttribute__((visibility ("default") ))
{
OK,
FAIL,
};
Though it seems like this is a bug in GCC that was fixed in versions 6+. Related SO post

Returning empty UDT From a function

I have written a function that returns a User Defined Type.
How can i return a empty UDT in case of any error from the function?
I tried setting function to 'Nothing',but it is throwing 'Object Required' error.
Thanks in advance.
If at all possible, use a Class/Object instead. Even doing something as simple as turning this type:
Public Type EmpRecord
FName As String
LName As String
HiredDate As Date
End Type
into a class can be done by adding a Class to your project called EmpRecord and including just this in it:
Public FName As String
Public LName As String
Public HiredDate As Date
Then you can return Nothing from a function that gets an error while retrieving the record.
In VB6, a user-defined type is a "value type", while a class is a "reference type". Value types are typically stored on the stack (unless they're a member of a class). Reference types are stored as a pointer on the stack pointing to a place in the heap where the actual instance data is stored.
That means a reference to a class can be Nothing (the pointer is zero), whereas a value type can't.
There are multiple ways to solve your problem:
Add a Boolean member to your user-defined type to indicate success or failure.
Create another "wrapper" UDT like (see below) and return it from your function.
Change your UDT into a class, which can be Nothing (as tcarvin said).
Write the function to return a Boolean and take a ByRef parameter. The results are written to the parameter passed in if the function result is True. (A lot of people don't like this, but it's a common solution you should be aware of.)
Wrapper:
Public Type Wrapper
Success As Boolean
Inner As YourOriginalUDT
End Type
Function with ByRef:
Function Foo(ByRef Result As YourOriginalUDT) As Boolean
...
If Success Then
Foo = True
Result.A = A
Result.B = B
Result.C = C
... etc. ...
End If
End Function
A UDT can't be empty.
You can either use a "dummy" unintialised UDT, or just set all it's members back to the default values.

Resources