• Delphi中存储二维数组的方法[转]


      今天突然用到Delphi中的二维数组,本来想用二维数组来存储用户的权限去控制登陆界面后的若干菜单子项的,可是发现用数据库存储二维数组还需要经过一些转化,于是想了个笨方法,在数据库中把二维数组转换为String字符串进行存储,读出后再还原成二维数组,下面是我写的两个转化函数。
    二维数组的形式如下:a[(1,1,1,1,1,1,1,1,1,1),(1,1,1,1,1,1,1,1,1,1),(1,1,1,1,1,1,1,1,1,1)......]
    转后后的字符串格式如下:1,1,1,1,1,1,1,1,1,1,1,1,1,1........

    Function TwoArrayToString(Sender:TObject; SourceArray:myArray; xMax:Integer; yMax:Integer):String;
    var
        tmpstr:String;
        i,j:Integer;
    begin
        tmpstr:='';
        for i:=1 to xMax do
        begin
            for j:=1 to yMax do
            begin
                if (i<>xMax) or (j<>yMax)  then
                begin
                    tmpstr:=tmpStr+IntToStr(SourceArray[i][j]);
                    tmpstr:=tmpStr+',';
                end
                else
                begin
                    tmpstr:=tmpStr+IntToStr(SourceArray[i][j]);
                end;
            end;
            //tmpstr:=tmpstr+#13#10;
        end;
        result:=tmpstr;
    end;
    Function StringToTwoArray(Sender:TObject; SourceStr:String; xMax:Integer;yMax:Integer):myArray;
    var
        i,j,x:Integer;
        myOwnArray:myArray;
        tmpstr:String;
    begin
        x:=1;
        tmpstr:=SourceStr;
        for i:=1 to xMax do
        begin
            for j:=1 to yMax do
            begin
                if x<Length(tmpstr)/2+1 then
                begin
                    myOwnArray[i][j]:=StrToInt(tmpstr[x*2-1]);
                    inc(x);
                end;
            end;
        end;
        result:=myOwnArray;
    end;


    注:一些变量定义如下:
    const  upermissonX=10;
    const  upermissonY=10;
    Type
      myArray=array[1..upermissonX,1..upermissonY] of integer;

  • 相关阅读:
    ff与ie 的关于js兼容性
    CSS清除浮动的方法
    java8 LocalDateTime
    BigDecimal
    JAVA将 Word 文档转换为 PDF
    Ionic4
    SpringBoot后端统一格式返回
    SpringBoot集成JWT
    Java Lombok
    SpringBoot 中通过 CORS 解决跨域问题
  • 原文地址:https://www.cnblogs.com/railgunman/p/1889685.html
Copyright © 2020-2023  润新知