我的系统中做了一个多任务定时提醒的功能,任务的时间、标题和内容,都是存储在数据库中。目前是每隔0.5秒查询一次数据库,看是否有到点的任务,有则提醒。我感觉这样很消耗数据库的资源,请问大家有什么好的思路么。(注:任务的数据需要存储在数据库中)有人提示可以将列表读到内存中,可是我不会内存如何加载多列数据和读取,百度也找不到。

解决方案 »

  1.   

    TList, 容器类,喜欢什么放什么
      

  2.   


    type
      TMyItem = record
         time: TDateTime;
         title: string;
         data: string;
      end;
      TMyItemArray = array of  TMyItem;procedure TForm1.Button1Click(Sender: TObject);
    var
      list: TMyItemArray;
      i: integer;
      count: integer;
    begin
      try
        // load DataBase
        // .....
        count := ?; // Data count
        SetLength(list, count);
        for i := 0 to count - 1 do
        begin
          list[i].time := ?
          list[i].title := ?
          list[i].data := ?
        end;
      finally  end;
    end;
      

  3.   

    把数据库的每一条记录封装成一个对象,程序启动的时候把记录读出来,动态生成对象,然后用TObjectList保存以下,轮询TObjectList就行了~