convert str2enum how I can do this ?

hi

I want to convert str2enum when I do it it return error how I can do this ?

this is the code :

query query;
querybuilddatasource querybuilddatasource;
querybuildrange querybuildrange;
queryrun queryrun;
empltable empltable;
HAL_TmpChargement tmp;

;

super();

query = new query();
querybuilddatasource = query.addDataSource(tablenum(empltable));
querybuildrange = querybuilddatasource.addrange(fieldnum(empltable,PBAUserProfile));
querybuildrange.value(“point”);

queryrun = new queryrun(query);

while (queryrun.next())
{
empltable =queryrun.get(tablenum(empltable));
ttsbegin;
while select forupdate tmp
{

tmp.hal_pointer = str2enum(empltable.EmplId); // here its return error why ? can you correct me ?
tmp.update();
HAL_TmpChargement_ds.refreshEx();

}
ttscommit;
}

thank you

EmplId is EDT and not an Enum. You are calling ‘str2enum’ function incorrectly.

Also I don’t see declaration for ‘tmp.hal_pointer’.

What are you trying to achieve?

Have a look here for more understanding of the same

http://msdn.microsoft.com/en-us/library/aa655065(v=AX.50).aspx

Hello Hakim,

In your code you have not called the str2enum function correctly i.e. the parameters supplied to this function are not correct. Below is some useful information about the function enum2str.

str2Enum Function: Converts a text string into an enumerated text of the type specified by _type.

enum str2Enum(enum _type, str _text)

Parameter Description

_type The type that the string should be converted to.

_text The text to use as the name of the enumerated text.

Return Value: An enumerated text of type _type that has the name _text.

Example: The following example returns the enumerated text Current.

static void str2EnumExample(Args _arg)

{

BankAccountType bat;

;

str2Enum(bat,“Current”);

}

Regards,

Shankar

I want to select all record (emplid) in empltable who has PBAuserprofile == “point”

and make it in this field tmp.hal_pointer this field is enum type.

the field tmp.hal_pointer is field in hal_tmpchargement table

can you help me .

I see this site

http://msdn.microsoft.com/en-us/library/aa655065(v=AX.50).aspx

but it doesn’t show me how i can convert str result to enum

thank you

I do this but it doesn’tanswer my question

i want to convert my str type result to enum type

thank you

You cannot put the Empld Value into a field of type enum - by using a str2enum function. You are misusing it.

Does your field has some enum value which is equivalent to EmplId?

I don’t understand why you are trying to put a str value(EmplId) in an enum type field.

Hello Hakim,

Your approach is not right.

You are trying to assign incompatible string values to an enum type field. I’ll explain you more clearly. Suppose the enum field hal_pointer in your table HAL_TmpChargement has 4 enum elements/values: ‘A’, ‘B’, ‘C’, ‘D’. Enum values are represented internally as integers. The first literal has number 0, the next has number 1, the next has number 2, and so on.

Then as I have given you an example earlier the function str2enum will correctly be used only when your field EmplId in the table Empltable has one of the four string values: “A”, “B”, “C” and “D”.

The function str2enum converts a string type matching value to an enum type value so that there is no type incompatibility while assigning values because otherwise you can never assign a string value to an enum field.

Suppose your field EmplId in the table Empltable has a value “E” and you are trying to assign this string value to the field hal_pointer in your table HAL_TmpChargement by using the str2enum function then this is incorrect and meaningless as the enum field HAL_TmpChargement has only 4 enum elements/values: ‘A’, ‘B’, ‘C’, ‘D’ and it cannot accept any other enum element /value. And this is what you are trying to do because every EmplId is a new unique value and you cannot assign these unmatching values to the enum type field hal_pointer in your table HAL_TmpChargement.

I hope this makes the issue clearer.

Best regards,

Shankar

Does your field has some enum value which is equivalent to EmplId?

  • no it does not this field is empty but I want to

I don’t understand why you are trying to put a str value(EmplId) in an enum type field.

  • i would like to select all emplid in the table emltable who have PBAuserprofile ==“poin” and make this result in hal_pointer filed for use it .

how I can select all empltable.emplid who have empltable.PBAuserprofile==“point” and make this result in field as list combobox ?

thank you

Hi Hakin,

Why is it that you are assigning string value of the field EmplId in the table Empltable to the enum type field hal_pointer in your table HAL_TmpChargement. Instead of it you can create a new string field with name like EmplIdPBAUserProfile whose extended data type is “EmplId” in your table HAL_TmpChargement and assign the string values of the field EmplId in the table Empltable to this field. Further you’ll have to try overriding the lookup() method of the datasource bound field control in your form which is using the table HAL_TmpChargement as the datasource if you want that the lookup of field EmplIdPBAUserProfile in your form field shows only those EmplId’s of EmplTable who have empltable.PBAuserprofile==“Point”.

This is just a suggestion for you to try. By assigning the values to an enum type field by using str2enum function you cannot achieve what you are trying to achieve.

Thanks & Regards,

Shankar Dutt Sharma

please can you give me an exemple of lookup() methode ?

thank you

Hello Hakim,

The fields shown in a standard lookup form are determined by the relations set on the database table or on the extended data type for the field. The fields shown in the lookup form are those in the relation and those specified for the TitleField1 and TitleField2 properties on the related table.

To create a lookup form that displays different fields, override the lookup method on the form control that will display the lookup by using the SysTableLookup application class.

Note: When you override the lookup method, comment out the call to super(). Otherwise, an autogenerated lookup form will instead be displayed.

Here is an example:

void lookup()

{

Query query = new Query();

QueryBuildDataSource queryBuildDataSource;

QueryBuildRange queryBuildRange;

// Create an instance of SysTableLookup where ‘this’

// is the current form control.

SysTableLookup sysTableLookup =

SysTableLookup::newParameters(tableNum(custTable), this);

;

// Add fields to be shown in the lookup form.

sysTableLookup.addLookupField(fieldNum(CustTable, AccountNum));

sysTableLookup.addLookupField(fieldNum(CustTable, Name));

// Limit and arrange the data selection.

queryBuildDataSource = query.addDataSource(tableNum(CustTable));

queryBuildRange = queryBuildDataSource.addRange(

fieldNum(CustTable, AccountNum));

queryBuildRange.value(‘A…B’);

sysTableLookup.parmQuery(query);

// Perform the lookup.

sysTableLookup.performFormLookup();

//Don’t call super() (commented out in the code).

// super()

}

Thanks & Regards,

Shankar Dutt Sharma

so I create lookup() in field hal_pointer method in the form (HAL_TmpChargement_hal_pointer) ?

thanks

No Hakim you don’t have to create a lookup() method but you have to override it.

Suppose in the form HAL_TmpChargement_hal_pointer you are using the table HAL_TmpChargement as datasource and you have to show the filtered value of the EmplId’s in the EmplTable in the string control which is bound to the newly created datasource field EmplIdPBAUserProfile such that empltable.PBAuserprofile==“Point”.

For this you will have to override the lookup() method in that string control in your form’s design in the following way -

  1. Right-click the string control, click Properties, and confirm that the LookupButton property is set to Auto.

  2. Click the string control, right-click Methods, click Override Method, and then click Lookup. The code editor appears.

  3. Follow the example for overriding the lookup() method.

Now when you open the form HAL_TmpChargement_hal_pointer you will see the lookup symbol in the field EmplIdPBAUserProfile on clicking of which will show only those EmplId’s from the EmplTable for which empltable.PBAuserprofile==“Point”.

But make sure that you will have to do this in all the forms which will use the table HAL_TmpChargement as datasource and show the newly added field EmplIdPBAUserProfile.

I hope this helps.

Thanks & Regards,
Shankar Dutt Sharma

when I make this code It select only one record (emplid) who has (PBAuserprofile==“poin”) but I have 4 record ?

why can you correct me ?

public void lookup()
{

Query query = new Query();

QueryBuildDataSource queryBuildDataSource;

QueryBuildRange queryBuildRange;

// Create an instance of SysTableLookup where ‘this’

// is the current form control.

SysTableLookup sysTableLookup =

SysTableLookup::newParameters(tableNum(empltable), this);

;

// Add fields to be shown in the lookup form.

sysTableLookup.addLookupField(fieldNum(empltable, EmplId));

//sysTableLookup.addLookupField(fieldNum(CustTable, Name));

// Limit and arrange the data selection.

queryBuildDataSource = query.addDataSource(tableNum(empltable));

queryBuildRange = queryBuildDataSource.addRange(

fieldNum(empltable, EmplId));

queryBuildRange.value(‘point’);

sysTableLookup.parmQuery(query);

// Perform the lookup.

sysTableLookup.performFormLookup();

//Don’t call super() (commented out in the code).

// super()
}

thanks

I found the error this the true code :

public void lookup()
{

Query query = new Query();

QueryBuildDataSource queryBuildDataSource;

QueryBuildRange queryBuildRange;

// Create an instance of SysTableLookup where ‘this’

// is the current form control.

SysTableLookup sysTableLookup =

SysTableLookup::newParameters(tableNum(empltable), this);

;

// Add fields to be shown in the lookup form.

sysTableLookup.addLookupField(fieldNum(empltable, EmplId));

//sysTableLookup.addLookupField(fieldNum(CustTable, Name));

// Limit and arrange the data selection.

queryBuildDataSource = query.addDataSource(tableNum(empltable));

queryBuildRange = queryBuildDataSource.addRange(

fieldNum(empltable, PBAUserProfile));

queryBuildRange.value(‘point’);

sysTableLookup.parmQuery(query);

// Perform the lookup.

sysTableLookup.performFormLookup();

//Don’t call super() (commented out in the code).

// super()

}

thanks thanks you thanks you [:D][:D][:)][8-|]