File 动态更改pascal中记录类型的变量文件

File 动态更改pascal中记录类型的变量文件,file,variables,record,pascal,freepascal,File,Variables,Record,Pascal,Freepascal,这里有个问题,我应该为每个数据库声明两个不同的变量和整个数据库过程操作。 我想使用动态变量简化我的代码,例如 database : array [1..3] of string = ('QA.db','Level.db','Highscore.db'); type QA = record Question : string[255]; Options : array['A'..'D'] of string[255]; Answer : char; end; type level


这里有个问题,我应该为每个数据库声明两个不同的变量和整个数据库过程操作。
我想使用动态变量简化我的代码,例如

database : array [1..3] of string = ('QA.db','Level.db','Highscore.db'); 

type QA = record
 Question : string[255];
 Options  : array['A'..'D'] of string[255];
 Answer   : char;
end;

type level = record
 money: longint;
 safe: boolean;
end;

type score = record
  name : string[255];
  reward : longint;
 end;

var
 f1:file of QA;
 ftemp1: QA;
 f2 : file of level;
 ftemp2: level;
 f3 : file of score;
 ftemp3: score;          

//Database Operation
  procedure print, change, etc.
  begin reset(f1); ....; write(f,ftemp); close(f1); end; etc.


有了这段代码,我只能为所有数据库声明一个数据库操作,我该怎么做呢?我使用的是lazarus IDE。

如果要写入非类型文件,可以使用“TextFile”


,你能给我举个例子吗?我不知道有非类型化或类型化的文件,内存之间的关系是什么?如何将非类型化的文件传递到过程或函数中@AbelistoAs是任何其他变量,但使用
var
modifier。我认为世界已经向前发展,现在有更好的方法来存储数据
var
 f:file of VAR;
 ftemp: VAR;

procedure Add;
begin
 reset(f);
 ....
 write(f,ftemp);
 close(f);
end;

begin
 VAR:QA;
 Add;
 VAR:level;
 Change;
end; 
procedure xyz..
var
  myFile: TextFile;
begin
  AssignFile(myFile, 'C:\QA.db');
  try
    rewrite(myFile);
    writeln(myFile, 'New Sample text!');
    CloseFile(myFile);
  except
    // Important ERROR handling!
    on E: EInOutError do
      writeln('Some error in filewriting!: ', E.ClassName, ':', E.Message);
  end;
end;