Copy Constructor in C++
Moderators: SDS, support, admin
Copy Constructor in C++
Hi,
As far as I know there is no copy contructor in Delphi. So when you need to create a copy construct a class you have to create from a metaclass.
Please would you convert the following code snippet to C++ that has been taken from Delphi Editor example.
Thanks.
As far as I know there is no copy contructor in Delphi. So when you need to create a copy construct a class you have to create from a metaclass.
Please would you convert the following code snippet to C++ that has been taken from Delphi Editor example.
Thanks.
Code: Select all
procedure TfmPreview.FillImage(ASManager: TsgSelectionManager;
ADXFImage: TsgDXFImage);
var
I: Integer;
vEnt: TsgDXFEntity;
vDXFImage: TsgDXFImage;
begin
FSManager := ASManager;
vDXFImage := TsgDXFImage.Create;
for I := 0 to FSManager.SelectedEntities.Count - 1 do
begin
vEnt := TsgDXFEntityClass(TsgDXFEntity(FSManager.SelectedEntities[I]).ClassType).Create;
vEnt.AssignEntity(TsgDXFEntity(FSManager.SelectedEntities[I]));
vDXFImage.Converter.OnCreate(vEnt);
vDXFImage.Converter.Sections[csEntities].AddEntity(vEnt);
vDXFImage.Converter.Loads(vEnt);
end;
vDXFImage.GetExtents;
FDNavigator.Picture.Graphic := vDXFImage;
FDNavigator.Color := vDXFImage.BackgroundColor;
//TsgDXFImage(sgImage.Picture.Graphic).IsWithoutBorder := True;// without border
vDXFImage.Free;
FDNavigator.FitToSize;
end;
We suppose you have met some difficulties when converting the following line:
vEnt = vDXFImage->Converter->NewEntity(NULL, FSManager->SelectedEntities)->ClassType());
Sergey.
Please post questions to the forum or write to support@cadsofttools.com
vEnt = vDXFImage->Converter->NewEntity(NULL, FSManager->SelectedEntities)->ClassType());
Sergey.
Please post questions to the forum or write to support@cadsofttools.com
The compiler gaves eror to the line that you have send.
E2034 Cannot convert "TList" to "TMetaClass"
vEnt = vDXFImage->Converter->NewEntity(NULL, FSManager->SelectedEntities)->ClassType());
Please would you send the correct one.
The problem is TCadManager is not documentated. Or at least my copy is old. Is there any documents on TCadManager class.
Thanks
Aby
E2034 Cannot convert "TList" to "TMetaClass"
vEnt = vDXFImage->Converter->NewEntity(NULL, FSManager->SelectedEntities)->ClassType());
Please would you send the correct one.
The problem is TCadManager is not documentated. Or at least my copy is old. Is there any documents on TCadManager class.
Thanks
Aby
Hi Aby,
Please try the following code:
Sergey.
Please post questions to the forum or write to support@cadsofttools.com
Please try the following code:
Code: Select all
void TfmPreview::FillImage(TsgSelectionManager *ASManager,TsgDXFImage *ADXFImage)
{
int i;
TsgDXFEntity *vEnt, *vSelEnt;
TsgDXFImage *vDXFImage;
FSManager = ASManager;
vDXFImage = new TsgDXFImage();
try
{
for(i = 0; i < FSManager->SelectedEntities->Count; i++)
{
vSelEnt = (TsgDXFEntity *)(FSManager->SelectedEntities->Items[i]);
vEnt = vDXFImage->Converter->NewEntity(NULL, vSelEnt->ClassType());
vEnt->AssignEntity(vSelEnt);
vDXFImage->Converter->OnCreate(vEnt);
vDXFImage->Converter->Sections[csEntities]->AddEntity(vEnt);
vDXFImage->Converter->Loads(vEnt);
}
vDXFImage->GetExtents();
FDNavigator->Picture->Graphic = vDXFImage;
FDNavigator->Color = vDXFImage->BackgroundColor;
}
__finally
{
delete vDXFImage;
}
FDNavigator->FitToSize();
}
Please post questions to the forum or write to support@cadsofttools.com
Hi Sergey,
vSelEnt = (TsgDXFEntity *)(FSManager->SelectedEntities->Items);
I was writing above
vSelEnt = dynamic_cast< TsgDXFEntity *>(FSManager->SelectedEntities->Items);
The line must be written like that.
vSelEnt = reinterpret_cast< TsgDXFEntity *>(FSManager->SelectedEntities->Items);
The last question on this subject.
TsgDrawingNavigator does not contain ChangeScale method. What method shoudl I have to use.
Aby
vSelEnt = (TsgDXFEntity *)(FSManager->SelectedEntities->Items);
I was writing above
vSelEnt = dynamic_cast< TsgDXFEntity *>(FSManager->SelectedEntities->Items);
The line must be written like that.
vSelEnt = reinterpret_cast< TsgDXFEntity *>(FSManager->SelectedEntities->Items);
The last question on this subject.
TsgDrawingNavigator does not contain ChangeScale method. What method shoudl I have to use.
Aby
<blockquote id="quote"><font size="2" face="Verdana, Arial, Helvetica" id="quote">quote:<hr height="1" noshade id="quote"><i>Originally posted by aby</i>
<br />Hi Sergey,
vSelEnt = (TsgDXFEntity *)(FSManager->SelectedEntities->Items);
I was writing above
vSelEnt = dynamic_cast< TsgDXFEntity *>(FSManager->SelectedEntities->Items);
The line must be written like that.
vSelEnt = reinterpret_cast< TsgDXFEntity *>(FSManager->SelectedEntities->Items);
<hr height="1" noshade id="quote"></font id="quote"></blockquote id="quote">
Thank you for the info.
<blockquote id="quote"><font size="2" face="Verdana, Arial, Helvetica" id="quote">quote:<hr height="1" noshade id="quote">
The last question on this subject.
TsgDrawingNavigator does not contain ChangeScale method. What method shoudl I have to use.<hr height="1" noshade id="quote"></font id="quote"></blockquote id="quote">
We recommend to use TsgDrawingNavigator.AlterScale:
<b>function</b> AlterScale(Factor: Double; IsAbsolute: Boolean; Position: TPoint): Boolean;
<b>Description</b>
Scales the drawing. Returns:
True – if succeeded.
False – if failed.
<b>Factor</b> - scaling factor (set Factor = 1 and IsAbsolute = True to draw image 1x1).
<b>IsAbsolute</b>:
True - scaling respectively drawings extents.
False - scaling respectively current scale
<b>Position</b> - point respectively which a scaling occurs.
Sergey.
Please post questions to the forum or write to support@cadsofttools.com
<br />Hi Sergey,
vSelEnt = (TsgDXFEntity *)(FSManager->SelectedEntities->Items);
I was writing above
vSelEnt = dynamic_cast< TsgDXFEntity *>(FSManager->SelectedEntities->Items);
The line must be written like that.
vSelEnt = reinterpret_cast< TsgDXFEntity *>(FSManager->SelectedEntities->Items);
<hr height="1" noshade id="quote"></font id="quote"></blockquote id="quote">
Thank you for the info.
<blockquote id="quote"><font size="2" face="Verdana, Arial, Helvetica" id="quote">quote:<hr height="1" noshade id="quote">
The last question on this subject.
TsgDrawingNavigator does not contain ChangeScale method. What method shoudl I have to use.<hr height="1" noshade id="quote"></font id="quote"></blockquote id="quote">
We recommend to use TsgDrawingNavigator.AlterScale:
<b>function</b> AlterScale(Factor: Double; IsAbsolute: Boolean; Position: TPoint): Boolean;
<b>Description</b>
Scales the drawing. Returns:
True – if succeeded.
False – if failed.
<b>Factor</b> - scaling factor (set Factor = 1 and IsAbsolute = True to draw image 1x1).
<b>IsAbsolute</b>:
True - scaling respectively drawings extents.
False - scaling respectively current scale
<b>Position</b> - point respectively which a scaling occurs.
Sergey.
Please post questions to the forum or write to support@cadsofttools.com
Hi Sergey,
...
vDXFImage = new TsgDXFImage();
...
FDNavigator->Picture->Graphic = vDXFImage;
.....
}
__finally
{
delete vDXFImage;
}
There are logical bugs in these lines.
First you are creating an object on the stack,
then you are assigning this object to Graphic object
after you are deleting it.
If we are going to delete this object why are you assigning it.
This logical bug is very hard to find.
Either if we are going to use it after we must not delete, or if we are not using you must not assign. What must be?
Thanks
Aby
...
vDXFImage = new TsgDXFImage();
...
FDNavigator->Picture->Graphic = vDXFImage;
.....
}
__finally
{
delete vDXFImage;
}
There are logical bugs in these lines.
First you are creating an object on the stack,
then you are assigning this object to Graphic object
after you are deleting it.
If we are going to delete this object why are you assigning it.
This logical bug is very hard to find.
Either if we are going to use it after we must not delete, or if we are not using you must not assign. What must be?
Thanks
Aby
Hi Aby,
The following line:
is equivalent to:
Does it any error arise?
Sergey.
Please post questions to the forum or write to support@cadsofttools.com
The following line:
Code: Select all
FDNavigator->Picture->Graphic = vDXFImage;
Code: Select all
FDNavigator->Picture->Assign(vDXFImage);
Sergey.
Please post questions to the forum or write to support@cadsofttools.com