Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

declare strongly typed return value for a method using the foxpro IDE

Status
Not open for further replies.

bernardmanning

Programmer
Oct 14, 2003
61
GB
Hi

Can somebody tell me if it's possible to declare a strongly typed return value for a class method using the foxpro IDE?

Eg

In code you can do this kind of thing ;

Code:
	PROCEDURE SomeMethod as String
		RETURN "SomeString"
	ENDPROC

However I cannot find a way of telling foxpro via the IDE what the type of the return value for my class method is.

I'm having to do this as I'm building a COM component for use with .NET.

Any info would be greatly appreciated....

Bernard
 
Hi Mike,

Imagine you have a visual foxpro project with existing classes held within it.

You open the class visually using the IDE , ie click on the classes tab on the project manager find the class and click modify on the project manager.

once the class is open, I click class from the toolbar , then new method , I name my method "test" and click ok.

At no point am I allowed to specify my return values type,

eg what I trying to acheive is the same thing as if I did this in code ;

Code:
PROCEDURE SomeMethod as String
        RETURN "SomeString"
ENDPROC

do you know what I mean?

Thanks , Bernard.


 

Bernard,

OK. I understand now that when you referred to the IDE, you meant the visual class designer. I was confused because I take the IDE to mean the entire development environment, as distinct from the run-time environment.

So, you want create a method in a class that returns a strongly-typed result, using the visual class designer? Unfortunately, I don't think that's possible. You have to write the class in code. (Someone will correct me if I'm wrong.)

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My sites:
Visual FoxPro (www.ml-consult.demon.co.uk)
Crystal Reports (www.ml-crystal.com)
 
Does it make a difference? I didn't think VFP enforced the typing anyhow. I use strong typing for self documentation, not because it enforces a specific data type. I would think that if you want to ensure you get a string back that you caste it using some function (transform).

Pass a numeric to the following proc and you get a numeric back.

Code:
DEFINE CLASS FooClass AS Custom
	PROCEDURE FooProc AS String
		LPARAMETERS vsSomeArg
		RETURN vsSomeArg
	ENDPROC
ENDDEFINE

Ralph Kolva
 
Hi Bernard,

concerning OLEPUBLIC classes: Look at the part about COMARRAY in the help chapter about DEFINE CLASS:

Code:
      DIMENSION PEMName_COMATTRIB[5]
      [PEMName_COMATTRIB[1] = nFlags
       PEMName_COMATTRIB[2] = cHelpString
       PEMName_COMATTRIB[3] = cPropertyCapitalization
       PEMName_COMATTRIB[4] = cPropertyType
       PEMName_COMATTRIB[5] = nOptionalParams]]

Where PEM is for Property/Event/Method, so not limited to Properties only. In your case you'd define an array Somemethod_COMATTRIB[5] and set the array values corresponding, especially Somemethod_COMATTRIB[4].

Bye, Olaf.
 

Hi Mike,

Thanks for the reply, The lack of support for this in the visual class designer is not good news, at least for me....

We have a series of related, subclassed foxpro classes residing in different libraries and it looks like I'm going to have use the class brower to extract all the code from each lib in turn and paste it into a single prg in order to support strong typing...

Seems strange that in order to go forward into .Net we have to resort back to prg based classes...

Again, Thanks for the response...

 
Sorry, I see it's impossible to set values at design time to user defined array-properties.

Bye, Olaf.
 
Never mind,

Looking at the help file I see that typing is enforced when another COM calls the VPF COM


Visual FoxPro converts AS Type clause values automatically when other COM servers use them.


Ralph Kolva
 
Mike,

How about back ending the .vcx file (USE class.vcx)? All the methods are defined in a memo file and as a quick test I added some typing to proc and the visual class at least opened OK. I would want to test that it compiles correctly before going too far with it though.

Ralph Kolva
 
Hi Guys,

thanks for all the responses...

Looking at the _ComAttrib array I can get it to specify the attribute of a property but not a method.

Eg this works ;

Code:
DEFINE CLASS test AS container OLEPUBLIC
	Width = 200
	Height = 200
	Name = "test"
    
    MyString= .F.
    
    DIMENSION MyString_COMATTRIB[4]
    MyString_comattrib[1] = 0
    MyString_comattrib[2] = "Help string for the MyString property"
    MyString_comattrib[3] = "MyString"
    MyString_comattrib[4] = "String"

ENDDEFINE

When I look at the resulting DLL in the object browser the type info for this property shows up.

BUT...I can't get this to work with a return value for a method...

eg.

Code:
DEFINE CLASS test AS container OLEPUBLIC
	Width = 200
	Height = 200
	Name = "test"
    
    DIMENSION MyName_COMATTRIB[4]
    MyName_comattrib[1] = 0
    MyName_comattrib[2] = "Help string for the MyName method"
    MyName_comattrib[3] = "MyName"
    MyName_comattrib[4] = "String"   

    PROCEDURE MyName
    RETURN "Bernard"

ENDDEFINE

This doesn't work , the return type still shows up in the object browser as variant...

I can't get find any examples of how to specify the return type using the comattrib approach...

I realise that is the example above I could just place AS STRING after the PROCEDURE MyName line of code. But the idea is to place the comattrib in a vcx based class..

If you don't strongly type your return values then when you attempt to reference the class from .NET over COM interopt is gets 'shirty' and returns an error. Stringly type the values and all is well..

Anybody got any clues?

 

Ralph,

All the methods are defined in a memo file and as a quick test I added some typing to proc and the visual class at least opened OK.

Yes, I can see how that works. But, when you next go into the class designer and edit the code, won't it overwrite your hand-made mods to the VCX?

Bernard,

Sorry I can't suggest a solution -- other than to convert all your visual classes to PRG-based classes. I can see why you would be reluctant to do that.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My sites:
Visual FoxPro (www.ml-consult.demon.co.uk)
Crystal Reports (www.ml-crystal.com)
 
Mike,

You are definetly correct, it does see the type declaration when you edit the visual class and you'll need to remove it to save and then back end it again. I don't know what's more trouble, converting to prg or hacking the vcx. At least the class browser tool makes getting the code all at once pretty easy.

Ralph Kolva
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top