-1

Dont know how to formulate this exactly so bear with me please... I am saving text from a memo to a database with date selected in the PlannerCalendar1. Since I can select multiple dates in the PlannerCalendar1, how can I post the value of the memo to all dates selected in the PlannerCalendar1?So when I click 'save' the contents of the memo gets saved to all selected dates.Database is SQLite. The table also has an ID field which is autoinc (primary).PlannerCalendar is from the set of TMS components.

procedure TForm1.cxButton1Click(Sender: TObject);
 var i:integer;
begin
with UniQuery1 do
begin
 UniQuery1.SQL.Text:='INSERT INTO LOG (DATE,PERSON,DONE,TIME) VALUES (:a1,:a2,:a3,:a4)';
 UniQuery1.PARAMS.ParamByName('A1').VALUE := PlannerCalendar1.Date;
 UniQuery1.PARAMS.ParamByName('A2').VALUE := cxmemo1.Lines.text ;
 UniQuery1.PARAMS.ParamByName('A3').VALUE := (0);
 UniQuery1.PARAMS.ParamByName('A4').Value := AdvOfficeStatusBar1.Panels[0].Text;
 UniQuery1.ExecSQL;
 cxmemo1.Clear;
 UniTable1.Refresh;

Tried this at the end but it wont work :

with plannercalendar1.Dates do
begin
for i := 0 to -1 do
begin
UniQuery1.PARAMS.ParamByName('A1').VALUE :=plannercalendar1.dates.Add + i ;
UniQuery1.ExecSQL;
end;
user3181689
  • 241
  • 6
  • 22

2 Answers2

1

I have no idea what a PlannerCalendar is, but presumably there's some way to get at the list of dates that are selected. You want to do something like this:

UniQuery1.SQL.Text:='INSERT INTO LOG (DATE,PERSON,DONE,TIME) VALUES (:a1,:a2,:a3,:a4)';
UniQuery1.PARAMS.ParamByName('A2').VALUE := cxmemo1.Lines.text ;
UniQuery1.PARAMS.ParamByName('A3').VALUE := (0);
UniQuery1.PARAMS.ParamByName('A4').Value := AdvOfficeStatusBar1.Panels[0].Text;

for i := 0 to PlannerCalendar1.NumberOfDatesSelected-1 do begin
    UniQuery1.PARAMS.ParamByName('A1').VALUE := PlannerCalendar1.SelectedDate[i];
    UniQuery1.ExecSQL;
end;

Of course, NumberOfDatesSelected and SelectedDate are wild guesses. You'll need to find out what they're really called.

Blorgbeard
  • 101,031
  • 48
  • 228
  • 272
  • PlannerCalendar1 has no dates selected property...Closest is for i := 0 to PlannerCalendar1.Dates.Add-1 do begin....but I get [dcc32 Error] Unit1.pas(69): E2010 Incompatible types: 'Variant' and 'TSelDateItem' – user3181689 Jan 24 '14 at 09:21
  • I find it very odd not to exist something like PlannerCalendar1.Dates.Count. If it does you can use something like that in the for loop above – vkamayiannis Jan 24 '14 at 09:35
  • 1
    @user3181689 Or maybe something like SelectedDates. Don't have us guess at a component that you are using and that you can get the docs for. – Jan Doggen Jan 24 '14 at 10:38
  • Don't forget to use `Prepared := True;`. It is a little bit faster if you replace parameters multiple times – EProgrammerNotFound Jan 24 '14 at 11:44
  • no such thing as SelectionToAbsTime ....nor will "with plannercalendar1.Dates do begin for i := 0 to -1 do...." Any solution???This : UniQuery1.PARAMS.ParamByName('A1').VALUE := plannercalendar1.dates.Add + i ;will not add anything... – user3181689 Jan 24 '14 at 19:32
  • @user3181689 You must be using a very old version of TMS Planner. SelectionToAbsTime is in the current documentation and I tried it in the version I have here (2.5 dated May 2010). I suggest you upgrade your planner version. – Andy_D Jan 27 '14 at 09:53
1

You need to use the Planner's SelectionToAbsTime method :-

Var
  lStart, lEnd : TDateTime;
Begin
  Planner1.SelectionToAbsTime(lStart, lEnd);
  For I := Trunc(lStart) To Trunc(lEnd) Do
    SaveMemosForDate(I);
End;
Andy_D
  • 2,340
  • 16
  • 21