在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
program WriteStruct; {$APPTYPE CONSOLE} uses SysUtils; //写入结构体 type TCustomer = record ID: string[10]; Code: string[10]; Name: string[10]; end; var Customers: array[1..10] of TCustomer; i: Integer; myText: file of TCustomer; //file of type type必须是固定大小的,不能是对象, String, Variant等 customer: TCustomer; begin try AssignFile(myText, 'D:\customer.cus'); //重写文件 Rewrite(myText); for i := 1 to 10 do begin Customers[i].ID := 'Test:' + IntToStr(i); Customers[i].Code := 'Buy:' + IntToStr(i); Customers[i].Name := 'monty' + IntToStr(i); Write(myText, Customers[i]); end; CloseFile(myText); for i := 1 to 10 do begin Customers[i].ID := '0'; Customers[i].Code := '0'; Customers[i].Name := '0'; end; //只读模式打开文件 Reset(myText); //读取文件是否结束 while not Eof(myText) do begin read(myText, customer); //输出 Writeln(Customer.ID, customer.Name, customer.Code); end; CloseFile(myText); Readln; except on E: Exception do Writeln(E.ClassName, ': ', E.Message); end; end. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论