In Delphi 7, I'm trying to read some C# .Net public struct constants using COM.
I can't seem to get the syntax right.
Delphi code
I haven't found any way to write code that will even compile against extracted TLB.pas file. This code fails to compile with the error: "Object or class required"
S := ItemFieldIdentifier.AverageMarketPrice;
So, even though the C# programmer tells me that this isn't an instantiatable object, the TLB has a constructor for this type, so I figured I try instantiating. This code failed to compile with the error "Undeclared identifier":
var
ItemFieldIdentifier1: ItemFieldIdentifier;
...
ItemFieldIdentifier1 := CoItemFieldIdentifier.Create;
S := ItemFieldIdentifier1.AverageMarketPrice;
Is there a way for me to access these constants via COM, or does the C# programmer need create a instantiatable object that I can create and then access?
C# code
public struct ItemFieldIdentifier
{
...
public static readonly string AverageMarketPrice = "AMP";
...
Then, in C#, they have codes a com interop layer
public class ItemFieldIdentifier
{
public string AverageMarketPrice
{
get
{
return xxx.Public.ItemCat.ItemFieldIdentifier.AverageMarketPrice; // <-- this is getting the value from the struct.
}
TLB File
DIID__ItemFieldIdentifier: TGUID = '{667FB47F-6394-4ED6-842B-7581184B4138}';
IID__ItemFieldIdentifier_2: TGUID = '{FBF4AD9B-38B5-3856-ADAC-57DB3198BBE7}'
CLASS_ItemFieldIdentifier: TGUID = '{3A9E41E3-A509-483B-A212-6A507EA29B5B}';
_ItemFieldIdentifier = dispinterface;
_ItemFieldIdentifier_2 = interface;
_ItemFieldIdentifier_2Disp = dispinterface;
ItemFieldIdentifier = _ItemFieldIdentifier_2;
// *********************************************************************//
// DispIntf: _ItemFieldIdentifier
// Flags: (4096) Dispatchable
// GUID: {667FB47F-6394-4ED6-842B-7581184B4138}
// *********************************************************************//
_ItemFieldIdentifier = dispinterface
['{667FB47F-6394-4ED6-842B-7581184B4138}']
...
property AverageMarketPrice: WideString readonly dispid 45;
...
end;
// *********************************************************************//
// Interface: _ItemFieldIdentifier_2
// Flags: (4432) Hidden Dual OleAutomation Dispatchable
// GUID: {FBF4AD9B-38B5-3856-ADAC-57DB3198BBE7}
// *********************************************************************//
_ItemFieldIdentifier_2 = interface(IDispatch)
['{FBF4AD9B-38B5-3856-ADAC-57DB3198BBE7}']
end;
// *********************************************************************//
// Interface: _ItemFieldIdentifier_2
// Flags: (4432) Hidden Dual OleAutomation Dispatchable
// GUID: {FBF4AD9B-38B5-3856-ADAC-57DB3198BBE7}
// *********************************************************************//
_ItemFieldIdentifier_2 = interface(IDispatch)
['{FBF4AD9B-38B5-3856-ADAC-57DB3198BBE7}']
end;
// *********************************************************************//
// DispIntf: _ItemFieldIdentifier_2Disp
// Flags: (4432) Hidden Dual OleAutomation Dispatchable
// GUID: {FBF4AD9B-38B5-3856-ADAC-57DB3198BBE7}
// *********************************************************************//
_ItemFieldIdentifier_2Disp = dispinterface
['{FBF4AD9B-38B5-3856-ADAC-57DB3198BBE7}']
end;
// *********************************************************************//
// The Class CoItemFieldIdentifier provides a Create and CreateRemote method to
// create instances of the default interface _ItemFieldIdentifier_2 exposed by
// the CoClass ItemFieldIdentifier. The functions are intended to be used by
// clients wishing to automate the CoClass objects exposed by the
// server of this typelibrary.
// *********************************************************************//
CoItemFieldIdentifier = class
class function Create: _ItemFieldIdentifier_2;
class function CreateRemote(const MachineName: string): _ItemFieldIdentifier_2;
end;