zoukankan      html  css  js  c++  java
  • 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;

  • 相关阅读:
    《链队列---队列的链式表示和实现》
    《栈的应用_版本1.2(实现了可以在一次运行后进行多次操作)》
    《栈的应用_版本1.1(实现了如何十进制转十六进制)》
    《栈的应用 版本1.0》
    《栈的基本操作》
    《单链表练习》
    hdu5887 Herbs Gathering
    CF198 div1 D
    hdu5893 List wants to travel
    hdu5556 Land of Farms
  • 原文地址:https://www.cnblogs.com/railgunman/p/1889685.html
Copyright © 2011-2022 走看看