Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > DB Tools

Lost Password?

Closed Thread
 
Thread Tools Display Modes
  #1  
Old 12-23-2016, 06:50 AM
Atarimark Atarimark is offline
Junior Member
 
Join Date: Jan 2015
Posts: 18
Default Filtering on Date field

I am using XE7 and having a problem with "stack overflow" errors when trying to sort on a date field so I started a new project, put a dbgrid, a navigator, a clientset and datasource, a datetimepicker and selected one of the sample datasets (orders.xml) and wrote a simple on filter event:

ClientDataSet1.Active := False;
ClientDataSet1.Filtered := False;
Accept := ClientDataSet1.FieldByName('SaleDate').AsDateTime <= DateTimePicker1.Date;
ClientDataSet1.Filtered := True;
ClientDataSet1.Active := True;

However when I try and execute the filter I get the stack overflow error on the ClientDataSet1.Active := True; line.

I am obviously doing something wrong but I cannot figure it out. I am using the filter even correct right?
  #2  
Old 12-27-2016, 08:05 PM
rojam rojam is offline
Senior Member
 
Join Date: Jun 2015
Posts: 166
Default

Code:
procedure TForm1.ClientDataSet1FilterRecord(DataSet: TDataSet; var Accept: Boolean);
begin
  //do not open and close the cds within the FilterRecord method, ONLY set Accept...
  Accept := ClientDataSet1.FieldByName('SaleDate').AsDateTime <= DateTimePicker1.Date;
end;
 
procedure TForm1.FilterBitBtnClick(Sender: TObject);
begin
  //turn filtering on and off with button click
  ClientDataSet1.Filtered := Not ClientDataSet1.Filtered;
end;
 
procedure TForm1.OpenCloseBitBtnClick(Sender: TObject);
begin
  //open and close the cds with a button click
  ClientDataSet1.Active := Not ClientDataSet1.Active;
end;

Last edited by rojam; 12-27-2016 at 08:21 PM.
  #3  
Old 12-28-2016, 03:27 AM
Atarimark Atarimark is offline
Junior Member
 
Join Date: Jan 2015
Posts: 18
Default

OK, I got that so using the DateToStr with the tdatetime variable, then why does this code:

InvData.Filter := 'DEPART = ' + QuotedStr(DepartmentListBox.Text) + ' NEXTCAL <= ' + QuotedStr(DateToStr(NextDate));

produce this error:

Project Proj2.exe raised exception class EDatabaseError with message 'Unterminated string constant'.
  #4  
Old 12-28-2016, 04:10 AM
rojam rojam is offline
Senior Member
 
Join Date: Jun 2015
Posts: 166
Default

try this
Code:
InvData.Filter := 'DEPART = ' + QuotedStr(DepartmentListBox.Text) + ' AND NEXTCAL <= ' + QuotedStr(DateToStr(NextDate));
  #5  
Old 12-29-2016, 12:37 AM
Atarimark Atarimark is offline
Junior Member
 
Join Date: Jan 2015
Posts: 18
Default

You sir are a damn hero! I was so hung up on the date conversion, I never ever once thought about the basic syntax of the statement. /sigh Thank you!
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 12:34 PM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2017, vBulletin Solutions, Inc.