今儿来写写如何使用Free Pascal处理文件,感觉挺有用的
任务一:写hello world到文件
1 procedure TForm1.Button1Click(Sender: TObject); 2 var 3 f: TextFile; 4 begin 5 AssignFile(f, 'hello.txt'); 6 ReWrite(f); 7 Write(f, 'hello world'); 8 CloseFile(f); 9 end;
任务二:写0x00-0xff的二进制数据到文件
1 procedure TForm1.Button1Click(Sender: TObject); 2 var 3 f: file of byte; 4 i: integer; 5 begin 6 AssignFile(f, 'hello.txt'); 7 ReWrite(f); 8 9 for i:= 0 to $ff do 10 begin 11 Write(f, i); 12 end; 13 14 CloseFile(f); 15 end;
任务三:写0x00-0xff到文件,每个数字占用4字节
1 procedure TForm1.Button1Click(Sender: TObject); 2 var 3 f: file of longWord; 4 i: integer; 5 begin 6 AssignFile(f, 'hello.txt'); 7 ReWrite(f); 8 9 for i:= 0 to $ff do 10 begin 11 Write(f, i); 12 end; 13 14 CloseFile(f); 15 end;
总结
到这里你就已经很牛逼了
标签:文件,begin,end,ReWrite,Free,Pascal,lazarus,AssignFile,hello From: https://www.cnblogs.com/eoli/p/17353869.html