Good night all.

There was such a problem in writing requests, I was not particularly strong, so I tried. Code

var Form1: TForm1; stDay : array[1..7] of string[11] = ('воскресенье', 'понедельник', 'вторник', 'среда', 'четверг', 'пятница', 'суббота'); stMonth : array[1..12] of string[8] = ('января', 'февраля', 'марта', 'апреля', 'мая', 'июня', 'июля', 'августа', 'сентября', 'октября', 'ноября', 'декабря'); implementation {$R *.dfm} uses DateUtils; 

Here is the request code.

 procedure TForm1.Button1Click(Sender: TObject); var st : string; begin st:= FormatDateTime('dd/mm/yyyy',Now); Form1.Query1.SQL[3] := '(ECPsrok = '''+st+''')'; Form1.Query1.Open; if form1.Query1.RecordCount <> 0 then form1.DataSource1.DataSet := Form1.Query1 else begin ShowMessage('На сегодня ничего нет.'); //form1.DataSource1.DataSet := Table1; end; end; 

It is registered in query

 SELECT * FROM po.db 

Frankly, I saw the code on the Internet, I decided to try to write a program using this query. But when you press a button, it knocks out a message

Project Project.exe raised exceptoin class EStringListError with message 'List index out if bounds(3)'.Process stop....

Tell me what could be the error. Advance ATP. I forgot to say that I created a database in the Paradox DBD.

  • 2
    Yes, are you all kidding? .. @Paul, To format a code, select it with the mouse and click on the button 101010 of the editor. - Zowie


2 answers 2

 TForm1.Button1Click(Sender: TObject); var st : string; begin st:= FormatDateTime('dd/mm/yyyy',Now); Form1.Query1.SQL.Clear; Form1.Query1.sql.text:='select * from po.db';// Если без фильтра // Если надо фильтр // Form1.Query1.sql.text:='select * from po.db where myday=''+st+''; Form1.Query1.Open; if form1.Query1.RecordCount <> 0 then form1.DataSource1.DataSet := Form1.Query1 else begin ShowMessage('На сегодня ничего нет.'); end; 

PS: check the po.db line, it hasn't worked with access for a long time.

  • Dear Vfvtnjd, and who told you that with Access in general a question? - NDenis
  • I don’t know why I read it as an accessory. Kherina knows .. - Vfvtnjd

There is a way to use a variable. For example, your request for a sample

 select * from doc where ddate1=:ValueDate1 Form1.Query1.SQL.text:='select * from doc where ddate1=:ValueDate1'; Form1.Query1.params[0]:=now-1; // текущий момент - 1 день Form1.Query1.open; 

Or directly edit the request

 Function Q(s:string):string; // моя функция для возврата строки в кавычках begin result:='"'+s+'"'; end; s:=q(DateTimeToStr(now-1)); Form1.Query1.SQL.text:='select * from doc where ddate1='+s; Form1.Query1.open; 

A small example of the program of work with Access + Delphi, contacts in the same place - if I consult you.

PS here captcha is really brutal.