//没有Delphi我无法调试
//自己看看思路
funciton Min(const mArr: array of Integer): Integer;
var
I: Integer;
begin
Result := 0;
for I := Low(mArr) to High(mArr) do
if Result > mArr then
Result := mArr;
end;funciton Max(const mArr: array of Integer): Integer;
var
I: Integer;
begin
Result := 0;
for I := Low(mArr) to High(mArr) do
if Result > mArr then
Result := mArr;
end;//...
function f: string;
var
I: Integer;
S: string;
begin
Result := '';
for I := Min(Low(no), Low(student), Low(class), Low(address)) to Max(High(no), High(student), Hight(class), Hight(address)) do begin
S := '';
if (I >= Low(no)) and (I <= High(no)) then
S := S + #9 + no[I]
else S := S + #9 + '<NULL>';
if (I >= Low(student)) and (I <= High(student)) then
S := S + #9 + student[I]
else S := S + #9 + '<NULL>';
if (I >= Low(class)) and (I <= High(class)) then
S := S + #9 + class[I]
else S := S + #9 + '<NULL>';
if (I >= Low(address)) and (I <= High(address)) then
S := S + #9 + address[I]
else S := S + #9 + '<NULL>';
Delete(S, 1, 1);
Result := Result + S + #13#10;
end;
end;//demo
Memo1.Text := f;
//自己看看思路
funciton Min(const mArr: array of Integer): Integer;
var
I: Integer;
begin
Result := 0;
for I := Low(mArr) to High(mArr) do
if Result > mArr then
Result := mArr;
end;funciton Max(const mArr: array of Integer): Integer;
var
I: Integer;
begin
Result := 0;
for I := Low(mArr) to High(mArr) do
if Result > mArr then
Result := mArr;
end;//...
function f: string;
var
I: Integer;
S: string;
begin
Result := '';
for I := Min(Low(no), Low(student), Low(class), Low(address)) to Max(High(no), High(student), Hight(class), Hight(address)) do begin
S := '';
if (I >= Low(no)) and (I <= High(no)) then
S := S + #9 + no[I]
else S := S + #9 + '<NULL>';
if (I >= Low(student)) and (I <= High(student)) then
S := S + #9 + student[I]
else S := S + #9 + '<NULL>';
if (I >= Low(class)) and (I <= High(class)) then
S := S + #9 + class[I]
else S := S + #9 + '<NULL>';
if (I >= Low(address)) and (I <= High(address)) then
S := S + #9 + address[I]
else S := S + #9 + '<NULL>';
Delete(S, 1, 1);
Result := Result + S + #13#10;
end;
end;//demo
Memo1.Text := f;
var
I: Integer;
begin
Result := 0;
for I := Low(mArr) to High(mArr) do
if Result < mArr then
// ~~
Result := mArr;
end;
// ~[]
High()取数组最大下标
Delete()删除字符行不行呢?
假设你的学号也转化成了字符串那么如此写代码:先定义变量:
sourceFile:TextFile;
i:integer;
resultStr:String;主要实现语句.
AssignFile(sourceFile,myFileName); //myFileName是你要存数据的文件名比如"myRecord.txt"
ReWrite(sourceFile); //重写或建立新文件.for i :=1 to StudentCount do
begin
resultStr:=copy(StudentRecord[i].no+' ',1,6)+copy(StudentRecord[i].student+' ',1,12)+copy(StudentRecord[i].class+' ',1,12)+StudentRecord[i].address;
Writeln(SourceFile,resultStr);
end; closeFile(sourceFile); //关闭文件.
你可以在按钮事件中如此写:procedure TForm1.Button1Click(Sender: TObject);
var
变量申明
begin
if OpenDialog1.Execute
then begin
AssignFile(sourceFile,SaveDialog1.FileName);
ReWrite(sourceFile);
……
closeFile(sourceFile);
end;
end;
1 xx 1
aaaaaaaaa
2 xxxx 1
bbbbbbbb
3 xx 2
cccccccccc
该如何做?我的学号、班级、姓名。地址是四个数组。谢谢!