• dellphi可变数组


    dellphi可变数组

    unit Unit1;
    
    interface
    
    uses
      DB, Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;
    
    type
      TForm1 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
      private    { Private declarations }
      public    { Public declarations }
      end;
    
    var
      Form1: TForm1;
    
    
    implementation
    
    {$R *.dfm}
    
    type
      TRec = array of TVarRec;
    
    procedure addRec(var P: TRec; values: array of const);
    var
      i: integer;
    begin
      Setlength(P, High(values) + 1);
      for i := Low(P) to High(P) do
      begin
        P[i].VType := values[i].VType;
        case values[i].VType of
          vtInteger:
            P[i].VInteger := values[i].VInteger;
          vtInt64:
            P[i].VInt64 := values[i].VInt64;
          vtBoolean:
            P[i].VBoolean := values[i].VBoolean;
          VtChar:
            P[i].VPchar := values[i].VPchar;
          vtString:
            P[i].VString := values[i].VString;
          vtAnsiString:
            P[i].VAnsiString := values[i].VAnsiString;
          vtWideString:
            P[i].VWideString := values[i].VWideString;
          vtPointer:
            P[i].VPointer := values[i].VPointer;
        end;
      end;
    end;
    
    procedure TForm1.Button1Click(Sender: TObject);
    var
      p, p2: TRec; //array of TVarRec;
      i, l: integer;
      b:array of Byte;
    begin
      addRec(p, ['中华人民共和国', 123]);
      l:=SizeOf(p);
      SetLength(b,l);
      Move(p, b[0], l);
    
      SetLength(p2, l);
      Move(b[0], p2, l);
      for i := low(p2) to high(p2) do
        case p2[i].VType of
          vtInteger: ShowMessage(IntToStr(p2[i].VInteger));         //中华人民共和国
          VtChar, vtString, vtAnsiString: ShowMessage(p[i].VPchar); //123
        end;
    end;
    
    end.
  • 相关阅读:
    String分割成int[]和List<Integer>
    linux查询正在运行的jar包并kill进程
    linux自动清理n天(1个月)前日志文件
    zookeeper命令行操作
    sql开窗函数
    hdfs shell操作
    centos7安装mysql8
    hadoop集群安装
    hdfs基本介绍
    IDEA下运行MAVEN项目,报"程序包******不存在"
  • 原文地址:https://www.cnblogs.com/hnxxcxg/p/16053567.html
Copyright © 2020-2023  润新知