out object parameter

  • Thread starter Thread starter Mike Carroll
  • Start date Start date
M

Mike Carroll

I have a COM server that's generally working ok. But one of its methods,
when the IDL gets read by the Intertop layer, has parameters of type "out
object".

The C# compiler tells me that it can't convert from object to out object, or
from int* to out object, or from object[] to out object. In fact, I can't
find anything at all that it will accept as a parameter on the call.

I don't think this is a COM issue, because if I wrote my own C# method with
an "out object" parameter I'd have the same problem.

So what does it want to have passed in?

Mike Carroll
Sigma Data Systems
 
C# client code, attempting to call methods on DisplayableFieldsLister COM
object:

unsafe private void buttonListMasters_Click(object sender, System.EventArgs
e)
{
AmsDataModule.DisplayableFieldsLister lister = new
DisplayableFieldsLister();
lister.ShowMessage("Hi there!"); // testing COM client; this works

int* tableNames;
object actualFieldNames;
object[] siteFieldNames;
void* fieldDataTypes;
lister.GetDisplayableFields("ListMasters", true, true, true,
tableNames, actualFieldNames, siteFieldNames, fieldDataTypes);
}

Compiler messages:
[C# Error] JobPostingsEditorForm.cs(1032): Argument '5': cannot convert from
'int*' to 'out object'
[C# Error] JobPostingsEditorForm.cs(1032): Argument '6': cannot convert from
'object' to 'out object'
[C# Error] JobPostingsEditorForm.cs(1032): Argument '7': cannot convert from
'object[]' to 'out object'
[C# Error] JobPostingsEditorForm.cs(1032): Argument '8': cannot convert from
'void*' to 'out object'

Preceded by the message:
[C# Error] JobPostingsEditorForm.cs(1031): The best overloaded method match
for 'AmsDataModule.IDisplayableFieldsLister.GetDisplayableFields(string,
bool, bool, bool, out object, out object, out object, out object)' has some
invalid arguments
 
Ok, so "out" is supposed to be sprinkled in among the parameters being
passed. Don't think I've seen that in any other language.

object tableNames;
object actualFieldNames;
object siteFieldNames;
object fieldDataTypes;
lister.GetDisplayableFields("ListMasters", true, true, true,
out tableNames, out actualFieldNames, out siteFieldNames, out
fieldDataTypes);
 
Mike Carroll said:
Ok, so "out" is supposed to be sprinkled in among the parameters being
passed. Don't think I've seen that in any other language.

That doesn't mean it's a bad thing - on the contrary, it's been added
to make the language clearer. In C#, it's always obvious if you're
passing something as a "ref" or "out" parameter, because it's in the
calling code as well as the method declaration. This is a very good
thing for readability, IMO.
 
Back
Top