Search code examples
delphidelphi-xe7tms

check if dbPlanner (TMS) item exists before copying


To copy an event item in the dbPlanner I used the suggestion from the manual on TMS website:

procedure TForm1.AdvGlowButton3Click(Sender: TObject);
begin
dbPlanner2.Items.Select(dbPlanner2.Items.Selected);
dbPlanner2.Items.CopyToClipboard;
dbPlanner2.SelectCells(dbPlanner2.SelItemBegin,dbPlanner2.SelItemEnd,dbPlanner2.SelPosition +1 );
end;

But how do I check if the item to be copied exists in the first place ? If I click the button to copy and no item selected,I get an exception.


Solution

  • A very simple way to check if an item is selected is to check Assigned(dbPlanner2.Items.Selected).

    If this condition resolves to false you should exit the procedure.