Hi!
i m trying to call managed code developed in Delphi | C# Projects in Delphi for 
win32 application.
i followed following steps:
  1> create a c# Class : 
  
namespace DemoProject
{
 /// <summary>
 /// Summary description for Class.
 /// </summary>
 public interface Demointerface
 {
  int DemoFunc1(int a);
}
   [ClassInterface(ClassInterfaceType.None)]
 public class DemoClass : Demointerface
 {
  public DemoClass()
  {
   //
   // TODO: Add constructor logic here
   //
    }
   public int DemoFunc1(int a)
   {
   int igive;
   igive = a *10;
   return igive;
   }
2> compiled it and build a dll of it.
  3> genarates .snk file and in AssemblyInfo file provided the path of this snk 
file + made COMVisibe true.
  4>registered successfully  this assembly using regasm DemoProject.dll
  5>created tlb file from this usin command tlbexp.
  6> Now open one fresh Delphi for win32 Application.
in that selected Component | Import Component | Type Library
and gives the path for DemoProject.tlb.
  7>creates DemoProject_TLB.pas showing mine interface, class and functions all.
  8>put DemoProject_TLB under uses section and creates object of TDemoClass.
i am able to see my class name, function interface in intellisence.
and on accessing it compiles and builds properly.
  But while running give error :
Project DemoDelphiProject.exe raised exception class EAccessViolation with 
message 'Access violation at address 0045A642 in module 
'DemoDelphiProject.exe'. Read of address 00000050'
and below there options r break continue ignore
  when i click break it goes to
function TDemoClass.GetDefaultInterface: Demointerface;
begin
  if FIntf = nil then  // in DemoProject_TLB.pas file.
   then  goes to function TDemoClass.DemoFunc1(a: Integer): Integer;
begin
  Result := DefaultInterface.DemoFunc1(a);
  here i m not able to see a:integer the value i passed from unit file. it 
shows me 0 only.
  i don't know where i m going wrong or what i m missing.
  i thought of writing delegate in c# class as function pointer, but i can't.
i haven't use it before and giving me some compilation error.
  Q> will delegate solve this problem? how to write delegate in c# and hoe to 
refer in Delphi for win32?
  Q>Is there any thing missing in the procedure i followed.
  I know I can get a vrey good guidence from your side that will solve my 
problem.
thanks.
  ***** I m sending DemoProject_TLB.pas file for your better understanding of 
my problem.
  with regards
Bijal...

                                
---------------------------------
 Jiyo cricket on Yahoo! India cricket
Yahoo! Messenger Mobile Stay in touch with your buddies all the time.
  ----------

unit DemoProject_TLB;

// ************************************************************************ //
// WARNING                                                                    
// -------                                                                    
// The types declared in this file were generated from data read from a       
// Type Library. If this type library is explicitly or indirectly (via        
// another type library referring to this type library) re-imported, or the   
// 'Refresh' command of the Type Library Editor activated while editing the   
// Type Library, the contents of this file will be regenerated and all        
// manual modifications will be lost.                                         
// ************************************************************************ //

// PASTLWTR : 1.2
// File generated on 4/19/2006 4:04:18 PM from Type Library described below.

// ************************************************************************  //
// Type Lib: C:\Demodll\bin\Debug\DemoProject.dll (1)
// LIBID: {47F26895-C81E-34DA-AD92-D7E56A9858D4}
// LCID: 0
// Helpfile: 
// HelpString: 
// DepndLst: 
//   (1) v2.0 stdole, (C:\WINDOWS\system32\stdole2.tlb)
//   (2) v1.10 mscorlib, 
(C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\mscorlib.tlb)
// Errors:
//   Error creating palette bitmap of (TDemoClass) : List index out of bounds 
(3)
// ************************************************************************ //
// *************************************************************************//
// NOTE:                                                                      
// Items guarded by $IFDEF_LIVE_SERVER_AT_DESIGN_TIME are used by properties  
// which return objects that may need to be explicitly created via a function 
// call prior to any access via the property. These items have been disabled  
// in order to prevent accidental use from within the object inspector. You   
// may enable them by defining LIVE_SERVER_AT_DESIGN_TIME or by selectively   
// removing them from the $IFDEF blocks. However, such items must still be    
// programmatically created via a method of the appropriate CoClass before    
// they can be used.                                                          
{$TYPEDADDRESS OFF} // Unit must be compiled without type-checked pointers. 
{$WARN SYMBOL_PLATFORM OFF}
{$WRITEABLECONST ON}
{$VARPROPSETTER ON}
interface

uses Windows, ActiveX, Classes, Graphics, mscorlib_TLB, OleServer, StdVCL, 
Variants;
  


// *********************************************************************//
// GUIDS declared in the TypeLibrary. Following prefixes are used:        
//   Type Libraries     : LIBID_xxxx                                      
//   CoClasses          : CLASS_xxxx                                      
//   DISPInterfaces     : DIID_xxxx                                       
//   Non-DISP interfaces: IID_xxxx                                        
// *********************************************************************//
const
  // TypeLibrary Major and minor versions
  DemoProjectMajorVersion = 1;
  DemoProjectMinorVersion = 0;

  LIBID_DemoProject: TGUID = '{47F26895-C81E-34DA-AD92-D7E56A9858D4}';

  IID_Demointerface: TGUID = '{85AF49C6-AB31-3FC8-8149-3C3EBEA9F29F}';
  IID__DemoDelegate1: TGUID = '{6E1740D9-5672-3CAA-88C1-4F2FE30967D2}';
  IID__DemoDelegate2: TGUID = '{1255D297-E742-3A14-BECC-5BAC6576513A}';
  CLASS_DemoClass: TGUID = '{51DF1D97-F081-389B-BF7A-D26AFC7F574F}';
  CLASS_DemoDelegate1: TGUID = '{74D5057E-387C-3F07-92E6-AA8F7DA6EED8}';
  CLASS_DemoDelegate2: TGUID = '{2F3FE5CD-DF58-3F3C-8637-5E38919DA3C0}';
type

// *********************************************************************//
// Forward declaration of types defined in TypeLibrary                    
// *********************************************************************//
  Demointerface = interface;
  DemointerfaceDisp = dispinterface;
  _DemoDelegate1 = interface;
  _DemoDelegate1Disp = dispinterface;
  _DemoDelegate2 = interface;
  _DemoDelegate2Disp = dispinterface;

// *********************************************************************//
// Declaration of CoClasses defined in Type Library                       
// (NOTE: Here we map each CoClass to its Default Interface)              
// *********************************************************************//
  DemoClass = Demointerface;
  DemoDelegate1 = _DemoDelegate1;
  DemoDelegate2 = _DemoDelegate2;


// *********************************************************************//
// Interface: Demointerface
// Flags:     (4416) Dual OleAutomation Dispatchable
// GUID:      {85AF49C6-AB31-3FC8-8149-3C3EBEA9F29F}
// *********************************************************************//
  Demointerface = interface(IDispatch)
    ['{85AF49C6-AB31-3FC8-8149-3C3EBEA9F29F}']
    function DemoFunc1(a: Integer): Integer; safecall;
    function DemoFunc2(const strdisp: WideString): WideString; safecall;
  end;

// *********************************************************************//
// DispIntf:  DemointerfaceDisp
// Flags:     (4416) Dual OleAutomation Dispatchable
// GUID:      {85AF49C6-AB31-3FC8-8149-3C3EBEA9F29F}
// *********************************************************************//
  DemointerfaceDisp = dispinterface
    ['{85AF49C6-AB31-3FC8-8149-3C3EBEA9F29F}']
    function DemoFunc1(a: Integer): Integer; dispid 1610743808;
    function DemoFunc2(const strdisp: WideString): WideString; dispid 
1610743809;
  end;

// *********************************************************************//
// Interface: _DemoDelegate1
// Flags:     (4432) Hidden Dual OleAutomation Dispatchable
// GUID:      {6E1740D9-5672-3CAA-88C1-4F2FE30967D2}
// *********************************************************************//
  _DemoDelegate1 = interface(IDispatch)
    ['{6E1740D9-5672-3CAA-88C1-4F2FE30967D2}']
  end;

// *********************************************************************//
// DispIntf:  _DemoDelegate1Disp
// Flags:     (4432) Hidden Dual OleAutomation Dispatchable
// GUID:      {6E1740D9-5672-3CAA-88C1-4F2FE30967D2}
// *********************************************************************//
  _DemoDelegate1Disp = dispinterface
    ['{6E1740D9-5672-3CAA-88C1-4F2FE30967D2}']
  end;

// *********************************************************************//
// Interface: _DemoDelegate2
// Flags:     (4432) Hidden Dual OleAutomation Dispatchable
// GUID:      {1255D297-E742-3A14-BECC-5BAC6576513A}
// *********************************************************************//
  _DemoDelegate2 = interface(IDispatch)
    ['{1255D297-E742-3A14-BECC-5BAC6576513A}']
  end;

// *********************************************************************//
// DispIntf:  _DemoDelegate2Disp
// Flags:     (4432) Hidden Dual OleAutomation Dispatchable
// GUID:      {1255D297-E742-3A14-BECC-5BAC6576513A}
// *********************************************************************//
  _DemoDelegate2Disp = dispinterface
    ['{1255D297-E742-3A14-BECC-5BAC6576513A}']
  end;

// *********************************************************************//
// The Class CoDemoClass provides a Create and CreateRemote method to          
// create instances of the default interface Demointerface exposed by           
   
// the CoClass DemoClass. The functions are intended to be used by             
// clients wishing to automate the CoClass objects exposed by the         
// server of this typelibrary.                                            
// *********************************************************************//
  CoDemoClass = class
    class function Create: Demointerface;
    class function CreateRemote(const MachineName: string): Demointerface;
  end;


// *********************************************************************//
// OLE Server Proxy class declaration
// Server Object    : TDemoClass
// Help String      : 
// Default Interface: Demointerface
// Def. Intf. DISP? : No
// Event   Interface: 
// TypeFlags        : (2) CanCreate
// *********************************************************************//
{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
  TDemoClassProperties= class;
{$ENDIF}
  TDemoClass = class(TOleServer)
  private
    FIntf:        Demointerface;
{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
    FProps:       TDemoClassProperties;
    function      GetServerProperties: TDemoClassProperties;
{$ENDIF}
    function      GetDefaultInterface: Demointerface;
  protected
    procedure InitServerData; override;
  public
    constructor Create(AOwner: TComponent); override;
    destructor  Destroy; override;
    procedure Connect; override;
    procedure ConnectTo(svrIntf: Demointerface);
    procedure Disconnect; override;
    function DemoFunc1(a: Integer): Integer;
    function DemoFunc2(const strdisp: WideString): WideString;
    property DefaultInterface: Demointerface read GetDefaultInterface;
  published
{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
    property Server: TDemoClassProperties read GetServerProperties;
{$ENDIF}
  end;

{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
// *********************************************************************//
// OLE Server Properties Proxy Class
// Server Object    : TDemoClass
// (This object is used by the IDE's Property Inspector to allow editing
//  of the properties of this server)
// *********************************************************************//
 TDemoClassProperties = class(TPersistent)
  private
    FServer:    TDemoClass;
    function    GetDefaultInterface: Demointerface;
    constructor Create(AServer: TDemoClass);
  protected
  public
    property DefaultInterface: Demointerface read GetDefaultInterface;
  published
  end;
{$ENDIF}


// *********************************************************************//
// The Class CoDemoDelegate1 provides a Create and CreateRemote method to       
   
// create instances of the default interface _DemoDelegate1 exposed by          
    
// the CoClass DemoDelegate1. The functions are intended to be used by          
   
// clients wishing to automate the CoClass objects exposed by the         
// server of this typelibrary.                                            
// *********************************************************************//
  CoDemoDelegate1 = class
    class function Create: _DemoDelegate1;
    class function CreateRemote(const MachineName: string): _DemoDelegate1;
  end;

// *********************************************************************//
// The Class CoDemoDelegate2 provides a Create and CreateRemote method to       
   
// create instances of the default interface _DemoDelegate2 exposed by          
    
// the CoClass DemoDelegate2. The functions are intended to be used by          
   
// clients wishing to automate the CoClass objects exposed by the         
// server of this typelibrary.                                            
// *********************************************************************//
  CoDemoDelegate2 = class
    class function Create: _DemoDelegate2;
    class function CreateRemote(const MachineName: string): _DemoDelegate2;
  end;

procedure Register;

resourcestring
  dtlServerPage = '(none)';

  dtlOcxPage = '(none)';

implementation

uses ComObj;

class function CoDemoClass.Create: Demointerface;
begin
  Result := CreateComObject(CLASS_DemoClass) as Demointerface;
end;

class function CoDemoClass.CreateRemote(const MachineName: string): 
Demointerface;
begin
  Result := CreateRemoteComObject(MachineName, CLASS_DemoClass) as 
Demointerface;
end;

procedure TDemoClass.InitServerData;
const
  CServerData: TServerData = (
    ClassID:   '{51DF1D97-F081-389B-BF7A-D26AFC7F574F}';
    IntfIID:   '{85AF49C6-AB31-3FC8-8149-3C3EBEA9F29F}';
    EventIID:  '';
    LicenseKey: nil;
    Version: 500);
begin
  ServerData := @CServerData;
end;

procedure TDemoClass.Connect;
var
  punk: IUnknown;
begin
  if FIntf = nil then
  begin
    punk := GetServer;
    Fintf:= punk as Demointerface;
  end;
end;

procedure TDemoClass.ConnectTo(svrIntf: Demointerface);
begin
  Disconnect;
  FIntf := svrIntf;
end;

procedure TDemoClass.DisConnect;
begin
  if Fintf <> nil then
  begin
    FIntf := nil;
  end;
end;

function TDemoClass.GetDefaultInterface: Demointerface;
begin
  if FIntf = nil then
    Connect;
  Assert(FIntf <> nil, 'DefaultInterface is NULL. Component is not connected to 
Server. You must call ''Connect'' or ''ConnectTo'' before this operation');
  Result := FIntf;
end;

constructor TDemoClass.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
  FProps := TDemoClassProperties.Create(Self);
{$ENDIF}
end;

destructor TDemoClass.Destroy;
begin
{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
  FProps.Free;
{$ENDIF}
  inherited Destroy;
end;

{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
function TDemoClass.GetServerProperties: TDemoClassProperties;
begin
  Result := FProps;
end;
{$ENDIF}

function TDemoClass.DemoFunc1(a: Integer): Integer;
begin
  Result := DefaultInterface.DemoFunc1(a);
end;

function TDemoClass.DemoFunc2(const strdisp: WideString): WideString;
begin
  Result := DefaultInterface.DemoFunc2(strdisp);
end;

{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
constructor TDemoClassProperties.Create(AServer: TDemoClass);
begin
  inherited Create;
  FServer := AServer;
end;

function TDemoClassProperties.GetDefaultInterface: Demointerface;
begin
  Result := FServer.DefaultInterface;
end;

{$ENDIF}

class function CoDemoDelegate1.Create: _DemoDelegate1;
begin
  Result := CreateComObject(CLASS_DemoDelegate1) as _DemoDelegate1;
end;

class function CoDemoDelegate1.CreateRemote(const MachineName: string): 
_DemoDelegate1;
begin
  Result := CreateRemoteComObject(MachineName, CLASS_DemoDelegate1) as 
_DemoDelegate1;
end;

class function CoDemoDelegate2.Create: _DemoDelegate2;
begin
  Result := CreateComObject(CLASS_DemoDelegate2) as _DemoDelegate2;
end;

class function CoDemoDelegate2.CreateRemote(const MachineName: string): 
_DemoDelegate2;
begin
  Result := CreateRemoteComObject(MachineName, CLASS_DemoDelegate2) as 
_DemoDelegate2;
end;

procedure Register;
begin
  RegisterComponents(dtlServerPage, [TDemoClass]);
end;

end.


[Non-text portions of this message have been removed]



-----------------------------------------------------
Home page: http://groups.yahoo.com/group/delphi-en/
To unsubscribe: [EMAIL PROTECTED] 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/delphi-en/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 


Reply via email to