1

I am trying to convert some C++ Builder code to Delphi and I ran into some uncertainties if the code is actually correct. I would appreciate an expert eye on areas where I should be correcting in case I have made a mistake. This is also a learning process for me since this is the first time I have attempted something like this.

I also omitted the "Properties" for the TAssistor Class since I am unsure on how to do that in Delphi.

I thank you all in advance for any help you can offer.

File: assistor.h

#ifndef assistorH
#define assistorH
#include "OrsaDll.h"
#include "ievect.hpp"
#include "ieview.hpp"
enum TAssistorType  {astDummy, astKeys, astGrid, astBox, astMatch};
class TDescContainer
{
public:
   struct descContainer
       {
       keypointsData kp;
       TIERectangle  rect;
       };
   TDescContainer(void) {CellSize = 0; Cell = 0; }
   virtual ~TDescContainer(void) {ClearCells(); }
   void ClearCells(void)
        {
        if (Cell)
           {
           for (int i = 0; i < CellSize; i++)
               {
               delete []Cell[i].kp.Data;
               Cell[i].kp.Data = 0;
               }
           }
        delete []Cell;
        CellSize = 0;
        }
    void CreateCells(int size)
        {
        ClearCells();
        CellSize = size;
        Cell = new descContainer[size];
        for (int i = 0; i < CellSize; i++)
            {
            Cell[i].kp.Data = 0;
            Cell[i].kp.Count = 0;
            }
        }
    void Keys2Cell(keypointsData *keyPoints, int index)
        {
        if (Cell[index].kp.Data)
           delete [] Cell[index].kp.Data;
        Cell[index].kp.Data = new keypoint[keyPoints->Count];
        Cell[index].kp.Count = keyPoints->Count;
        for (int i = 0; i < keyPoints->Count; i++)
            Cell[index].kp.Data[i] = keyPoints->Data[i];
        }
    void Cell2Keys(keypointsData *keyPoints, int index)
        {
        if (keyPoints->Count != Cell[index].kp.Count)
           {
           if (keyPoints->Count > 0)
              delete [] keyPoints->Data;
           keyPoints->Count = Cell[index].kp.Count;
           keyPoints->Data = new keypoint[keyPoints->Count];
           }
        for (int i = 0; i < keyPoints->Count; i++)
            keyPoints->Data[i] = Cell[index].kp.Data[i];
        }
   //
   descContainer *Cell;
   int CellSize;
 };
//--------------------------------------------------------------------------
class TAssistor // TODO: inherit base class. example: TAssistorGrid: 
TAssistorBase
{
private:
    TImageEnVect *_paint;
    int *_hAssistorObject, _hAssistorSize, _hAssistorIndex;
    int _boxID;
    TAssistorType _assType;
    void collectBoxes(void);
public:
    TAssistor(TImageEnVect *paint);
    virtual ~TAssistor(void);
    //
    void Add(int hobj, bool anchorToLayer = true);
    void Delete(void);
    void CreateGrid(int rows, int cols, int penSize, TColor penColor);
    void CreateKeys(TDescContainer &dscC, int sigma, int penSize, TColor 
penColor);
    void PrepareAddBox(int penSize, TColor penColor, TColor brushColor);
    void PrepareMoveBox(void);
    void DeleteBox(void);
    void MoveBox(void);
    void Hide(bool full = false);
    void Show(bool full = false);
    TIERectangle GetObjRect(int val);
    // events
    void __fastcall NewBox(TObject *Sender, int hobj);
    // properites
    __property int Size = {read = _hAssistorSize};
    __property int *Object = {read = _hAssistorObject};
    __property TAssistorType Type = {read = _assType};
};
#endif

File: assistor.cpp

#include <vcl.h>
#pragma hdrstop
#include "assistor.h"
//--------------------------------------------------------------------------
#pragma package(smart_init)
//--------------------------------------------------------------------------
TAssistor::TAssistor(TImageEnVect *paint)
{
_paint = paint;
_hAssistorObject = 0;
_hAssistorSize = 0;
_hAssistorIndex = 0;
_assType = astDummy;
_boxID = 99;
}
//--------------------------------------------------------------------------
TAssistor::~TAssistor(void)
{
Delete();
}
//--------------------------------------------------------------------------
void TAssistor::Add(int hobj, bool anchorToLayer)
{
if (_hAssistorIndex < _hAssistorSize)
   {
   _hAssistorObject[_hAssistorIndex++] = hobj;
   if (anchorToLayer)
      _paint->ObjLayer[hobj] = _paint->LayersCurrent;
   }
}
//--------------------------------------------------------------------------
void TAssistor::Delete(void)
{
if (_hAssistorObject)
   {
   for (int i = _hAssistorSize - 1; i >= 0; i--)
       _paint->RemoveObject(_hAssistorObject[i]);
   delete [] _hAssistorObject;
   _hAssistorObject = 0;
   _hAssistorSize = 0;
   _hAssistorIndex = 0;
   }
}
//--------------------------------------------------------------------------
void TAssistor::Show(bool full)
{
if (_hAssistorObject)
   {
   for (int i = 0; i <_hAssistorSize; i++)
       {
       if (full)
           _paint->ObjStyle[_hAssistorObject[i]] = TIEVStyle()
<<ievsSelectable<<ievsVisible<<ievsMoveable<<ievsSizeable;
       else
           _paint->ObjStyle[_hAssistorObject[i]] = TIEVStyle()<<ievsVisible;
        }
   }
}
//--------------------------------------------------------------------------
void TAssistor::Hide(bool full)
{
if (full)
   {
_    paint->MouseInteractVt = TIEMouseInteractVt();    // disable all 
interactions
    _paint->OnNewObject = 0;                           // disable events
   }
//
if (_hAssistorObject)
   {
   for (int i = 0; i <_hAssistorSize; i++)
       _paint->ObjStyle[_hAssistorObject[i]] = TIEVStyle();
   }
}
//--------------------------------------------------------------------------
void TAssistor::CreateGrid(int rows, int cols, int penSize, TColor penColor 
)
{
_assType = astGrid;
Delete();
// create grid as bunch of boxes so it can be converted to sizable boxes if necessary
int hobj;
int iWidth  = _paint->IEBitmap->Width;
int iHeight = _paint->IEBitmap->Height;
double tileWidth, tileHeight, curX, curY;
_hAssistorSize = cols * rows;
tileWidth  = iWidth * 1.0 / cols;
tileHeight = iHeight * 1.0 / rows;
_hAssistorObject = new int[_hAssistorSize];
curY = 0.0f;
for (int i = 0; i < rows; i++)
    {
    curX = 0.0f;
    for (int j = 0; j < cols; j++)
        {
        hobj = _paint->AddNewObject();
        _paint->ObjKind[hobj] = iekBOX;
        _paint->ObjBrushStyle[hobj] = bsClear;
        _paint->ObjTop[hobj]  =  (int)curY;
        _paint->ObjLeft[hobj] =  (int)curX;
        _paint->ObjWidth[hobj]  = (int)tileWidth;
        _paint->ObjHeight[hobj] = (int)tileHeight;
        _paint->ObjPenWidth[hobj] =  penSize;
        _paint->ObjPenColor[hobj] =  penColor;
        _paint->ObjStyle[hobj] = TIEVStyle()<<ievsVisible;
        Add(hobj);
        curX += tileWidth;
        }
    curY += tileHeight;
    }
}
//--------------------------------------------------------------------------
// show keypoints as circles
//--------------------------------------------------------------------------
void TAssistor::CreateKeys(TDescContainer &dscC, int sigma, int penSize, TColor penColor)
{
_assType = astKeys;
Delete();
int kpsSize = 0;
for (int i = 0; i < dscC.CellSize; i++)
    kpsSize += dscC.Cell[i].kp.Count;
_hAssistorSize = kpsSize;
_hAssistorObject = new int[_hAssistorSize];
// show keypoints
int hobj, radius;
keypoint *key;
for (int i = 0; i < dscC.CellSize; i++)
   {
    for (int j = 0; j < dscC.Cell[i].kp.Count; j++)
       {
       key = &(dscC.Cell[i].kp.Data[j]);
       hobj = _paint->AddNewObject();
       radius = ceil(key->scale * sigma);  // initial sigma
       _paint->ObjPenWidth[hobj] =  penSize;
       _paint->ObjPenColor[hobj] = penColor;
       _paint->ObjBrushStyle[hobj] = bsClear;
       _paint->ObjKind[hobj] = iekELLIPSE;
        //paint->ObjTop[hobj] =  PaintView->IEBitmap->Height - 1 - (int)kfDesc[i].x - radius;
       _paint->ObjTop[hobj]  =  key->y - radius + dscC.Cell[i].rect.y;
       _paint->ObjLeft[hobj] =  key->x - radius + dscC.Cell[i].rect.x;
       _paint->ObjWidth[hobj] =  radius*2;
       _paint->ObjHeight[hobj] = radius*2;
       _paint->ObjStyle[hobj] = TIEVStyle();
       Add(hobj);
       }
    }
}
//--------------------------------------------------------------------------
void TAssistor::PrepareAddBox(int penSize, TColor penColor, TColor brushColor)
{
_assType = astBox;
_paint->OnNewObject = NewBox;
_paint->ObjKind[IEV_NEXT_INSERTED_OBJECT] = iekBOX;
_paint->ObjBrushStyle[IEV_NEXT_INSERTED_OBJECT] = bsCross;
_paint->ObjBrushColor[IEV_NEXT_INSERTED_OBJECT] = brushColor;
_paint->ObjPenWidth[IEV_NEXT_INSERTED_OBJECT] =  penSize;
_paint->ObjPenColor[IEV_NEXT_INSERTED_OBJECT] =  penColor;
_paint->MouseInteractVt = TIEMouseInteractVt()<<miPutBox;
}
//--------------------------------------------------------------------------
void TAssistor::PrepareMoveBox(void)
{
_assType = astBox;
Show(true);
_paint->MouseInteractVt = TIEMouseInteractVt()<<miObjectSelect;
}
//--------------------------------------------------------------------------
void TAssistor::DeleteBox(void)
{
for (int i = _paint->SelObjectsCount-1; i >= 0; i--)
    {
    if (_paint->ObjID[_paint->SelObjects[i]] == _boxID)
       _paint->RemoveObject(_paint->SelObjects[i]);
    }
 CollectBoxes();
}
//--------------------------------------------------------------------------
// private method
//--------------------------------------------------------------------------
void TAssistor::CollectBoxes(void)
{
_assType = astBox;
if (_hAssistorObject)
   {
   delete [] _hAssistorObject;
   _hAssistorObject = 0;
   _hAssistorSize = 0;
   _hAssistorIndex = 0;
   }
// collect boxes
int i, hobj, numBoxes = 0;
for (int i = 0; i < _paint->ObjectsCount; i++)
    {
    hobj = _paint->GetObjFromIndex(i);
    if (_paint->ObjID[hobj] == _boxID)
       numBoxes++;
    }
_hAssistorSize = numBoxes;
_hAssistorObject = new int[_hAssistorSize];
// boxes
for (i = 0; i < _paint->ObjectsCount; i++)
    {
    hobj = _paint->GetObjFromIndex(i);
    if (_paint->ObjID[hobj] == _boxID)
       Add(hobj);
    }
}
//--------------------------------------------------------------------------
TIERectangle TAssistor::GetObjRect(int val)
{
TIERectangle rect;
if (_hAssistorObject)
   {
   int hobj = _hAssistorObject[val];
   rect.x = _paint->ObjLeft[hobj];
   rect.y = _paint->ObjTop[hobj];
   rect.width = _paint->ObjWidth[hobj];
   rect.height = _paint->ObjHeight[hobj];
   }
else
   {
   rect.width = 0;
   rect.height = 0;
   }
return rect;
}
//--------------------------------------------------------------------------
// event
//--------------------------------------------------------------------------
void __fastcall TAssistor::NewBox(TObject *Sender, int hobj)
{
_paint->ObjID[hobj] =  _boxID;
collectBoxes();
}

My attempted Delphi assistor.pas

unit assistor;

interface

uses
  Winapi.Windows,
  Winapi.Messages,
  System.SysUtils,
  System.Variants,
  System.Classes,
  Vcl.Graphics,
  Vcl.Controls,
  Vcl.Forms,
  Vcl.Dialogs,
  Vcl.StdCtrls,
  Vcl.ExtCtrls,
  Vcl.ComCtrls,
  System.Math,
  //ImageEn
  ievect,
  hyiedefs,
  //Orsa
  OrsaDLL;

type
  TAssistorType = (
    astDummy,
    astKeys,
    astGrid,
    astBox,
    astMatch );

type
  descContainer = record
    kp: keypointsdata;
    rect: TIERectangle;
  end;

type
  TDescContainer = class
    constructor Create;
    destructor Destroy;
  public
    Cell: array of descContainer;
    CellSize: Integer;
    procedure ClearCells;
    procedure CreateCells( size : integer);
    procedure Keys2Cell(var keyPoints : keypointsData; index : integer);
    procedure Cell2Keys(var keyPoints : keypointsData; index : integer);
 end;

type
  TAssistor = class
  private
    _paint: TImageEnVect;
    _hAssistorObject: Integer;
    _hAssistorSize: Integer;
    _hAssistorIndex: Integer;
    _boxID: Integer;
    _assType: TAssistorType;
   procedure CollectBoxes;
   procedure NewBox(Sender: TObject; hobj: Integer);
 public
   procedure Add( hobj : integer; anchorToLayer : Boolean);
   procedure Delete;
   procedure Show( full : Boolean);
   procedure Hide( full : Boolean);
   procedure CreateGrid( rows, cols, penSize : integer; penColor : TColor);
   procedure CreateKeys( dscC : TDescContainer; sigma, penSize : integer; penColor : TColor);
   procedure PrepareAddBox( penSize : integer; penColor, brushColor : TColor);
   procedure PrepareMoveBox;
   procedure DeleteBox;
   function GetObjRect( val : integer):TIERectangle;
end;

implementation

procedure TDescContainer.ClearCells;
var
  i : integer;
begin
    if (Length( Cell ) > 0) then begin
       for i := 0 to CellSize-1 do
         begin
         //delete []Cell[i].kp.Data;
         dispose( Cell[i].kp.Data );       //<-- not sure if this is correct
         Cell[i].kp.Data := 0;
         end;
       end;
    //delete []Cell;    //<-- don't know what is Delphi equivalent
    CellSize := 0;
end;


procedure TDescContainer.CreateCells( size : integer);
var
  i : integer;
begin
    ClearCells();
    CellSize := size;
    for i := 0 to CellSize-1 do
      begin
      Cell[i].kp.Data := 0;
      Cell[i].kp.Count := 0;
      end;
end;


procedure TDescContainer.Keys2Cell(var keyPoints : keypointsData; index : 
integer);
var
  i : integer;
begin
    //if Cell[index].kp.Data then delete [] Cell[index].kp.Data;

   if (Cell[index].kp.Data <> nil) then                  //<-- not sure if this is correct
       dispose( Cell[index].kp.Data );                   //<-- not sure if this is correct
    Cell[index].kp.Count := keyPoints.Count;
    for i := 0 to keyPoints.Count-1 do;
      Cell[index].kp.Data[i] := keyPoints.Data[i];       //<-- compiler complains - should Cell be an array of array of TDescContainer?
    end;


procedure TDescContainer.Cell2Keys(var keyPoints : keypointsData; index : 
integer);
var
  i : integer;
begin
    if keyPoints.Count <> Cell[index].kp.Count then begin
       if keyPoints.Count > 0 then
        //delete [] keyPoints.Data;
        dispose( keyPoints.Data );                 //<-- not sure if this is correct
       keyPoints.Count := Cell[index].kp.Count;
       end;
    for i := 0 to keyPoints.Count-1 do
      keyPoints.Data[i] := Cell[index].kp.Data[i];
end;

{ TAssistor }

procedure TAssistor.Add( hobj : integer; anchorToLayer : Boolean);
begin
 if _hAssistorIndex < _hAssistorSize then begin
   //_hAssistorObject[PostInc(_hAssistorIndex)] := hobj;
   _hAssistorObject[Inc(_hAssistorIndex)] := hobj;       //<-- not sure if this correct

   if anchorToLayer then _paint.ObjLayer[hobj] := _paint.LayersCurrent;
   end;
end;


procedure TAssistor.Delete;
var
 i: Integer;
begin
//if _hAssistorObject then begin
if Assigned(_hAssistorObject) then begin   //<-- not sure if this is correct
   for i := 0 to _hAssistorSize - 1 do begin
      //PostDec(i);
      Dec(i);                   //<-- not sure if this is correct
      _paint.RemoveObject(_hAssistorObject[i]);
   end;
   //delete [] _hAssistorObject;      //<-- don't know Delphi equivalent
   _hAssistorObject := 0;
   _hAssistorSize := 0;
   _hAssistorIndex := 0;
   end;
end;


procedure TAssistor.Show( full : Boolean);
var
  i : integer;
begin
//if _hAssistorObject then begin
if Assigned(_hAssistorObject) then begin     //<-- not sure if this is correct
   for i := 0 to _hAssistorSize-1 do
     begin
     if full then
       _paint.ObjStyle[_hAssistorObject[i]] := [ievsSelectable, ievsVisible, 
ievsMoveable, ievsSizeable]
     else
       _paint.ObjStyle[_hAssistorObject[i]] := [ievsVisible];
     end;
   end;
end;


procedure TAssistor.Hide( full : Boolean);
var
  i : integer;
begin
if full then begin
  _paint.MouseInteractVt := [];    // disable all interactions
  _paint.OnNewObject := 0;         // disable events
end;
//
//if _hAssistorObject then begin
if Assigned(_hAssistorObject) then begin    //<-- not sure if this is correct
   for i := 0 to _hAssistorSize-1 do
     _paint.ObjStyle[_hAssistorObject[i]] := [];
   end;
end;


procedure TAssistor.CreateGrid( rows, cols, penSize : integer; penColor : 
TColor);
var
  hobj,
  iWidth,
  iHeight    : integer;
  tileWidth,
  tileHeight,
  curX,
  curY       : Double;
  i, 
  j          : integer;
begin
_assType := astGrid;
Delete();
// create grid as bunch of boxes so it can be converted to sizable boxes if 
necessary
iWidth := _paint.IEBitmap.Width;
iHeight := _paint.IEBitmap.Height;
_hAssistorSize := cols * rows;
tileWidth := iWidth * 1.0 / cols;
tileHeight := iHeight * 1.0 / rows;
curY := 0;
for i := 0 to rows-1 do
  begin
  curX := 0;
  for j := 0 to cols-1 do
    begin
    hobj := _paint.AddNewObject();
    _paint.ObjKind[hobj] := iekBOX;
    _paint.ObjBrushStyle[hobj] := bsClear;
    _paint.ObjTop[hobj] :=  Round(curY);
    _paint.ObjLeft[hobj] := Round(curX);
    _paint.ObjWidth[hobj] := Round(tileWidth);
    _paint.ObjHeight[hobj] := Round(tileHeight);
    _paint.ObjPenWidth[hobj] := penSize;
    _paint.ObjPenColor[hobj] := penColor;
    _paint.ObjStyle[hobj] := [ievsVisible];
    Add(hobj);
    curX  := curX + tileWidth;
    end;
  curY  := curY + tileHeight;
  end;
end;


procedure TAssistor.CreateKeys( dscC : TDescContainer; sigma, penSize : 
integer; penColor : TColor);
var
  kpsSize, i, hobj, radius : integer;
  key : ^keypoint;
  j : integer;
begin
_assType := astKeys;
Delete();
kpsSize := 0;
for i := 0 to dscC.CellSize-1 do
  kpsSize  := kpsSize + (dscC.Cell[i].kp.Count);
_hAssistorSize := kpsSize;
// show keypoints
for i := 0 to dscC.CellSize-1 do
  begin
  for j := 0 to dscC.Cell[i].kp.Count-1 do
     begin
     key := (dscC.Cell[i].kp.Data[j]);
     hobj := _paint.AddNewObject();
     radius := ceil(key.scale * sigma);  // initial sigma
     _paint.ObjPenWidth[hobj] := penSize;
     _paint.ObjPenColor[hobj] := penColor;
     _paint.ObjBrushStyle[hobj] := bsClear;
     _paint.ObjKind[hobj] := iekELLIPSE;
     //paint.ObjTop[hobj] =  PaintView.IEBitmap.Height - 1 - (Round(kfDesc[i].x) - radius;
     _paint.ObjTop[hobj] := key.y - radius + dscC.Cell[i].rect.y;
     _paint.ObjLeft[hobj] := key.x - radius + dscC.Cell[i].rect.x;
     _paint.ObjWidth[hobj] := radius*2;
     _paint.ObjHeight[hobj] := radius*2;
     _paint.ObjStyle[hobj] := [];
     Add(hobj);
     end;
   end;
end;


procedure TAssistor.PrepareAddBox( penSize : integer; penColor, brushColor : 
TColor);
begin
_assType := astBox;
_paint.OnNewObject := NewBox;
_paint.ObjKind[IEV_NEXT_INSERTED_OBJECT] := iekBOX;
_paint.ObjBrushStyle[IEV_NEXT_INSERTED_OBJECT] := bsCross;
_paint.ObjBrushColor[IEV_NEXT_INSERTED_OBJECT] := brushColor;
_paint.ObjPenWidth[IEV_NEXT_INSERTED_OBJECT] := penSize;
_paint.ObjPenColor[IEV_NEXT_INSERTED_OBJECT] := penColor;
_paint.MouseInteractVt := TIEMouseInteractVt() shl miPutBox;
end;

procedure TAssistor.NewBox(Sender: TObject; hobj: Integer);
begin
  _paint.ObjID[hobj] :=  _boxID;
  collectBoxes();
end;

procedure TAssistor.PrepareMoveBox;
begin
_assType := astBox;
Show(true);
_paint.MouseInteractVt := TIEMouseInteractVt() shl miObjectSelect;
end;


procedure TAssistor.DeleteBox;
var
 i: Integer;
begin
for i := 0 to _paint.SelObjectsCount-1 do begin
  //PostDec(i);
  Dec(i);             //<-- not sure if this is correct

if _paint.ObjID[_paint.SelObjects[i]] = _boxID then 
_paint.RemoveObject(_paint.SelObjects[i]);
end;
CollectBoxes();
end;


procedure TAssistor.CollectBoxes;
var
  i,
  hobj,
  numBoxes,
  i        : integer;
begin
_assType := astBox;
//if _hAssistorObject then begin
if Assigned(_hAssistorObject) then begin   //<-- not sure if this is correct
//   delete [] _hAssistorObject;           //<-- don't know Delphi equivalent
   _hAssistorObject := 0;
   _hAssistorSize := 0;
   _hAssistorIndex := 0;
   end;
// collect boxes
numBoxes := 0;
for i := 0 to _paint.ObjectsCount-1 do
  begin
  hobj := _paint.GetObjFromIndex(i);
  if _paint.ObjID[hobj] = _boxID then begin
    //PostInc(numBoxes);
    inc(numBoxes);              //<-- not sure if this is correct
  end;
 end;
_hAssistorSize := numBoxes;
// boxes
for i := 0 to _paint.ObjectsCount-1 do
  begin
  hobj := _paint.GetObjFromIndex(i);
  if _paint.ObjID[hobj] = _boxID then Add(hobj);
  end;
end;


function TAssistor.GetObjRect( val : integer):TIERectangle;
var
  rect : TIERectangle;
  hobj : integer;
begin
//if _hAssistorObject then begin
if Assigned(_hAssistorObject) then begin   //<-- not sure if this is correct
   hobj := _hAssistorObject[val];
   rect.x := _paint.ObjLeft[hobj];
   rect.y := _paint.ObjTop[hobj];
   rect.width := _paint.ObjWidth[hobj];
   rect.height := _paint.ObjHeight[hobj];
   end
else
   begin
   rect.width := 0;
   rect.height := 0;
   end;
Result := rect;
end;

end.

I am sorry if my question caused any bad feelings, that my "code dump" was simply a way to get away with free help without any work on my part. My intention was to learn from my mistakes that can be corrected by more experienced coders and I am sure there are many readers out there who can benefit from this, especially the ones who are undergoing the same task of converting C++ code to Delphi. Its sites like this that gives us all a chance to share our experiences and to broaden our knowledge at the same time.

The reason that I put the whole code in the question was because I wanted to know if I did the conversion structure of the C++ class correctly in Delphi. If I had taken snippets out of it, I think it would have been too confusing to know what is head or tail of the code.

Assuming that the flow of the conversion is correct, and I hope someone can point any mistakes out, then the areas that I am having serious uncertainties are in these areas:

  1. In the C++ code, Cell is defined as: descContainer *Cell. I made Cell as an array of TDescContainer in Delphi. But in Key2Cell, there is Cell[index].kp.Data[i] := keyPoints.Data[i], which made me think that it should be an array of array of TDescContainer. If I did that, then other areas of Cell in the code causes an issue. So, what should be the correct definition of Cell in this case?

  2. in ClearCells, I wrote the conversion of the C++ code of delete []Cell[i].kp.Data as dispose( Cell[i].kp.Data ). Is this correct? And what would be the Delphi equivalent to the C++ code of delete []Cell in this case?

  3. Are the C++ PostInc and PostDec the same as Delphi's Inc and Dec?

  4. In CollectBoxes, I am not sure what _hAssistorObject should be. I have defined as an Integer in Delphi but the C++ code of if (_hAssistorObject) { delete [] _hAssistorObject confuses me. Is this correct in Delphi if I did this: if Assigned(_hAssistorObject) then begin, and what is Delphi's equivalent to delete [] _hAssistorObject in this case?

Again, thank you all in advance for picking your brains. I sincerely hope that I did not spoil anybody's weekend with this.

glennsl
  • 28,186
  • 12
  • 57
  • 75
AndyC
  • 31
  • 4
  • If you have a particular concern, post only that code and explain what has you concerned. To put it bluntly, I don't get paid to do your code reviews! – Disillusioned Mar 25 '17 at 01:10
  • 1
    You might have better success with your question on [Code Review](http://codereview.stackexchange.com/) – Tom Brunberg Mar 25 '17 at 07:40
  • @TomBrunberg Agreed. But even there, asking to work through well over 700 lines of code without a clear understanding of expected behaviour is an extremely unreasonable request. And aiming for a one-one translation is also not a good idea as there are some significant idiomatic differences between the two languages. – Disillusioned Mar 25 '17 at 11:57
  • @Craig: If the class is a C++Builder class, and if it is based on TObject and has properties, there will be no big "idiomatic differences", ISTM. OK, it is a lot of code and the purpose is not clear, but it should be pretty easy to convert. – Rudy Velthuis Mar 25 '17 at 13:54
  • 1
    A `__property` is actually an extension to the C++Builder compiler so Delphi properties can be implemented. The first property would be: `property Size: Integer read _hAssistorSize;` and the others would be similar. Note that in Delphi (and C++Builder) it is customary to call members beginning with a capital F, so it would become: `FAssistorSize: PInteger;` and the property `property Size: Integer read FAssistorSize;`, but that is a convention, not a necessity. – Rudy Velthuis Mar 25 '17 at 14:14
  • @RudyVelthuis Nonsense.The last time I checked, Delphi didn't support: pass-by-value on objects, flagging methods as const (i.e. non-mutating), const modifiers to prevent calling mutating methods, scoped or multiple inheritance. Meaning that any idiomatic use of such features would need to be adapted accordingly. However, in the other direction, Borland/Embarcadero has made most (maybe all) Delphi features available in BCC so a one-one mapping is theoretically possible. But that just means you'd be writing Delphi code using C++ punctuation. _Which is an exercise of dubious value._ – Disillusioned Mar 26 '17 at 01:07
  • @RudyVelthuis That aside 700 lines is a lot of code to diligently check for subtle errors. _NOTE: Trusting that OP has already done a decent job, it will only be the **less obvious** errors that remain._ Apart from the unreasonable expectation of free services for substantial work: This question is of little value to this site because it is ***too broad***. It's a code dump that encompasses a wide variety features/techniques/syntax and possible errors. The question can improved by splitting in multiple: each focusing on a specific concern and only that code. Prime example: **properties** – Disillusioned Mar 26 '17 at 01:20
  • @Craig: if this is a TObject derived class, many of these things are not allowed anyway. If it is not (I must admit it doesn't look like it), then it is a little more work. I agree that 700 lines are too much for a simple answer, either here or on Codereview. – Rudy Velthuis Mar 26 '17 at 06:08
  • @RudyVelthuis, thank you for the the property tip. I will give that a try. – AndyC Mar 26 '17 at 13:57

0 Answers0