Search code examples
delphitms

TMS DBPlanner - copy and paste an event


I am trying to copy and paste an event from the DBPlanner. I tried :

procedure TForm1.Copy1Click(Sender: TObject);
begin
DBPlanner2.Items.Select(APlannerItem);
DBPlanner2.Items.CopyToClipboard;
DBPlanner2.SelectCells(DBPlanner2.SelItemBegin,DBPlanner2.SelItemEnd, DBPlanner2.SelPosition + 1);
end;

I get :

[dcc32 Error] Unit1.pas(107): E2003 Undeclared identifier: 'APlannerItem'

Then to paste :

procedure TForm1.Paste1Click(Sender: TObject);
begin
DBPlanner2.Items.PasteFromClipboardAtPos;
end;

What am I doing wrong ?


Solution

  • It seems that you made a classical mistake and that is Copying code from either examples or from other code. No worries, we all have done that.

    The APlannerItem in the compiler error refers to the first line in Copy1Click:

    DBPlanner2.Items.Select(APlannerItem);
    

    In the context of Copy1Click the compiler does not know what APlannerItem is. It might be something that you brought in from an example or documentation or other code in which case it most probably refers to a function/procedure parameter in that code where the line occurred.

    You now have to change that to the specific PlannerItem which you want to select and copy. I assume that you click on a PlannerItem before you want to copy. If so then you must refer to that PlannerItem. If not then you must access the PlannerItem through the DBPlanner's indexed list of PlannerItems, whatever the name of the function may be. I see that you have an Items property in DBPlanner2 so that may be the passage to the item you want. There might even be an ItemIndex property which states which item is selected.

    As a side note just for incase you did not know this before: The compiler always try to show you where the error happened and in the case of the error it will show the line number of the code where the error happened. In this case line number 107. Go to that line and inspect the code to figure out what is the problem.