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;