Board index » cppbuilder » Problem with using Delphi TCollection-successor

Problem with using Delphi TCollection-successor


2004-03-05 06:09:14 AM
cppbuilder108
Hello,
Does anybody know how to use TCollection-succesor written in Delphi from
Builder code?
It installed right, but when I try to execute next code, I get AV or stack
overload (depend on compiler settings)
d = MyCollection->Add();
when I trace that call in CPU window, I see - when Builder-created code load
virtual table for TCollection it differs from virtual table which loaded by
code which was created by dcc32.
Is there any way to resolve that mismatch?
Alex Zencovich
 
 

Re:Problem with using Delphi TCollection-successor

"Alex Zencovich" < XXXX@XXXXX.COM >wrote in message
Quote
It installed right, but when I try to execute next code,
I get AV or stack overload (depend on compiler settings)
Please show the actual Delphi code and the actual BCB generated code.
Gambit
 

Re:Problem with using Delphi TCollection-successor

Sorry. Here full test project code:
Delphi unit (Test.pas)
-----------------------------------------
unit Test;
interface
uses
Windows, SysUtils, Controls, Classes;
type
TMyCollectionItem = class(TCollectionItem)
private
FOwner : TCollection;
public
constructor Create(Collection : TCollection);override;
end;
TMyCollection = class(TCollection)
public
constructor Create;
function Add : TMyCollectionItem;
end;
TDelphiObject = class(TComponent)
private
FCollection : TMyCollection;
public
constructor Create(AOwner : TComponent);
destructor Destroy; override;
property Collection : TMyCollection read FCollection;
end;
procedure Register;
implementation
constructor TMyCollectionItem.Create(Collection : TCollection);
begin
FOwner := Collection;
inherited Create(Collection);
end;
constructor TMyCollection.Create;
begin
inherited Create(TMyCollectionItem);
end;
function TMyCollection.Add : TMyCollectionItem;
begin
Result := TMyCollectionItem(inherited Add);
end;
constructor TDelphiObject.Create(AOwner : TComponent);
begin
inherited Create(AOwner);
FCollection := TMyCOllection.Create;
end;
destructor TDelphiObject.Destroy;
begin
FCollection.Free;
inherited;
end;
procedure Register;
begin
RegisterComponents('TEST', [TDelphiObject]);
end;
end.
------------------------End of Delphi unit-------------
C++ Units
//-----------------------Unit1.cpp------------------------------------------
----
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//--------------------------------------------------------------------------
-
#pragma package(smart_init)
#pragma link "Test"
#pragma resource "*.dfm"
TForm1 *Form1;
//--------------------------------------------------------------------------
-
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//--------------------------------------------------------------------------
-
void __fastcall TForm1::Button1Click(TObject *Sender)
{
TMyCollectionItem *i;
i = DelphiObject1->Collection->Add();
}
//--------------------------------------------------------------------------
-
//--------------- Unit1.dfm
object Form1: TForm1
Left = 192
Top = 107
Width = 224
Height = 118
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object Button1: TButton
Left = 16
Top = 24
Width = 75
Height = 25
Caption = 'Button1'
TabOrder = 0
OnClick = Button1Click
end
object DelphiObject1: TDelphiObject
Left = 120
Top = 24
end
end
//-------------Unit1.h
//--------------------------------------------------------------------------
-
#ifndef Unit1H
#define Unit1H
//--------------------------------------------------------------------------
-
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include "Test.hpp"
//--------------------------------------------------------------------------
-
class TForm1 : public TForm
{
__published: // IDE-managed Components
TButton *Button1;
TDelphiObject *DelphiObject1;
void __fastcall Button1Click(TObject *Sender);
private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
//--------------------------------------------------------------------------
-
extern PACKAGE TForm1 *Form1;
//--------------------------------------------------------------------------
-
#endif
Some notes: Problem exists only if collection accesed as property of
TComponent-sucessor. Same TCollection code work OK if will accessed as
{
TMyCollectionItem *i;
TMyCollection *c
c = &TMyCollection;
i = c->Add();
}
Alex Zencovich
"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >сообщи?сообщила
?новостях следующе? news:4047c951$ XXXX@XXXXX.COM ...
Quote

"Alex Zencovich" < XXXX@XXXXX.COM >wrote in message
news: XXXX@XXXXX.COM ...

>It installed right, but when I try to execute next code,
>I get AV or stack overload (depend on compiler settings)

Please show the actual Delphi code and the actual BCB generated code.


Gambit


 

{smallsort}