zoukankan      html  css  js  c++  java
  • array of TVarRec 动态数组使用

    FDQuery.AppendRecord()里是一个array of TVarRec。我们一般都是直接用[Var1,Var2,...]。这样手工输入,但如果增加的元素我们预先不知道,就要声明一个array of TVarRec的动态数组,然后赋值了。我一直找不到方面,经QDAC的作者指点。做了以下实例:

    procedure TForm1.btn1Click(Sender: TObject);
    var
      cSQL:string;
      cList:TStringList;
      cRec:array of TVarRec;
      cText:Variant;
      i:Integer;
    begin
      cList:=TStringList.Create;
      cList.Add('01001');
      cList.Add('原材料');
      SetLength(cRec,cList.Count);
      for I := 0 to cList.Count-1 do
        begin
          cText:=cList.Strings[i];
          cRec[i+1].VVariant:=Addr(cText);
        end;
    
     // FDQuery1.AppendRecord(cRec);
    end;

     XE10后发生了一些变成,不知是什么原因原来的代码不可以用了。改了一下代码。

    procedure TForm3.SpeedButton1Click(Sender: TObject);
    var
      cList:TStringList;
      cRec:array of TVarRec;
      i:Integer;
    begin
      if not  FDMemTable1.Exists then  FDMemTable1.CreateDataSet;
      cList:=TStringList.Create;
      cList.Add('01001');
      cList.Add('原材料');
      SetLength(cRec,cList.Count);
      for I := 0 to cList.Count-1 do
        begin
          cRec[i].VAnsiString:=Pointer(cList.Strings[i]);
          cRec[i].VType:=17;
        end;
      cList.Free;
      Self.FDMemTable1.AppendRecord(cRec);
    end;
  • 相关阅读:
    exploded archive 和packaged archive 区别
    MyEclipse6.5使用设置技巧及快捷键
    本机上设置域名解析
    Cookie的生命周期问题
    简单的函数柯里化
    cookie操作
    自定义事件
    解耦应用逻辑/事件处理程序
    dragdrop + 自定义事件
    在窃取函数中用作用域安全的构造函数
  • 原文地址:https://www.cnblogs.com/wuxi15/p/FireDAC.html
Copyright © 2011-2022 走看看