type
aList=packed record
a:string[255];
b:string[255];
c:boolean;
d:array of [1..100] string[255];
d:array of [1..100] boolean;
end;
用Tlist管理这个记录类型的东西
怎么将aList里的东西存盘
并且正确的读出来返回到aList里
aList=packed record
a:string[255];
b:string[255];
c:boolean;
d:array of [1..100] string[255];
d:array of [1..100] boolean;
end;
用Tlist管理这个记录类型的东西
怎么将aList里的东西存盘
并且正确的读出来返回到aList里
解决方案 »
- 如何DELPHI制作一个备份数据库的功能
- 数据库查询结果总是不对
- ??? Delphi中=-是什么意思啊???
- 讨论!100分(我公司竞标某个MIS系统,竟然输给了PowerBuilder)Delphi还能走多远
- 数据库问题,同时操作两张表
- 请问DELPHI里怎么实现按钮点击就按下,再点弹起的功能啊???
- 线程的循环使用过程!急急急!!!!
- 关于:控制软件输入法的问题
- 請問Delphi與Access編寫的應用程序怎樣打包﹖萬分著急﹗﹗﹗謝﹗﹗﹗
- 如何调试ISAPI程序?
- 网上哪里可以找到类似Decision cube的决策分析控件,支持ADO
- 现在客户需要做一个修改数据的功能,是不是在查询界面那里让用户修改视图,请问前辈门对客户修改数据是怎样做这摸块的
unit GoodUnit;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, ExtCtrls, ComCtrls, DB, ADODB;type
TGoodItem = Class(TCollectionItem)
private
fPartNO : String;
fPartName : String;
fModel : String;
fCustomer : String;
fProcessStatus : String;
public
property PartNO : String read fPartNO write fPartNO;
property PartName : String read fPartName write fPartName;
property Model : String read fModel write fModel;
property Customer : String read fCustomer write fCustomer;
property ProcessStatus : String read fProcessStatus write fProcessStatus;
end;type
TGoodItemClass = Class of TGoodItem;type
TGoodList = Class(TCollection)
private
fGoodItem : TGoodItem;
function GetGoodItem(Index : integer) : TGoodItem;
procedure SetGoodItem(Index : integer; Value : TGoodItem);
public
Constructor Create(GoodItemClass : TGoodItemClass);
function Add : TGoodItem;
procedure LoadFromFile(FileName : String);
procedure LoadFromStream(S : TStream);
procedure SaveToFile(FileName : String);
procedure SaveToStream(S : TStream);
property Items[Index: Integer]: TGoodItem read GetGoodItem write SetGoodItem; default;
end;type
TGoodListWrapper = class(TComponent)
private
FGoodList: TGoodList;
published
property GoodList: TGoodList read FGoodList write FGoodList;
end;implementationconstructor TGoodList.Create(GoodItemClass: TGoodItemClass);
begin
inherited Create(GoodItemClass);
end;function TGoodList.Add: TGoodItem;
begin
Result := TGoodItem(inherited Add);
end;function TGoodList.GetGoodItem(Index: Integer): TGoodItem;
begin
Result := TGoodItem(inherited Items[Index]);
end;procedure TGoodList.LoadFromFile(Filename: string);
var
S: TFileStream;
begin
S := TFileStream.Create(Filename, fmOpenRead);
try
LoadFromStream(S);
finally
S.Free;
end;
end;procedure TGoodList.LoadFromStream(S: TStream);
var
Wrapper: TGoodListWrapper;
begin
Wrapper := TGoodListWrapper.Create(nil);
try
Wrapper.GoodList := TGoodList.Create(nil);
S.ReadComponent(Wrapper);
Assign(Wrapper.GoodList);
finally
Wrapper.GoodList.Free;
Wrapper.Free;
end;
end;procedure TGoodList.SaveToFile(Filename: string);
var
S: TStream;
begin
S := TFileStream.Create(Filename, fmCreate);
try
SaveToStream(S);
finally
S.Free;
end;
end;procedure TGoodList.SaveToStream(S: TStream);
var
Wrapper: TGoodListWrapper;
begin
Wrapper := TGoodListWrapper.Create(nil);
try
Wrapper.GoodList := Self;
S.WriteComponent(Wrapper);
finally
Wrapper.Free;
end;
end;procedure TGoodList.SetGoodItem(Index: Integer; Value: TGoodItem);
begin
Items[Index].Assign(Value);
end;end.
aList=packed record
a:string[255];
b:string[255];
c:Boolean;
d:array [1..100] of string[255];
e:array [1..100] of boolean;
end;procedure TForm1.Button1Click(Sender: TObject);
var
f: file;
al: aList;
begin
// 写入
FillChar(al, sizeof(al), 0);
al.a := 'abc';
al.b := 'bbb';
al.c := True;
al.d[1] := 'ddd';
al.e[1] := True;
AssignFile(f, 'd:\test');
Rewrite(f, SizeOf(al)); // 创建文件并设定记录大小
BlockWrite(f, al, 1); // 写入整个记录
CloseFile(f); // 读取
AssignFile(f, 'd:\test');
Reset(f, SizeOf(al)); // 打开文件并设定记录大小
BlockRead(f, al, 1); // 读取整个记录
CloseFile(f);
end;
type
aList=packed record
a:string[255];
b:string[255];
c:boolean;
d:array of [1..100] string[255];
d:array of [1..100] boolean;
end;DataFile: File of aListvar
aList1:aList;
DataFile: File of aList
begin
AssignFile(DataFile,'aList.bat');
Reset(DataFile);
try
if not eof(DataFile) then
Read(DataFile,aList1);
finally
CloseFile(DataFile);
end;
end;
aList=packed record
a:string[255];
b:string[255];
c:Boolean;
d:array [1..100] of string[255];
e:array [1..100] of boolean;
end;var list:TList;
aRecord:^aList;procedure SaveListToFile(FileName: string);
var
i: Integer;
f: file;
begin
AssignFile(f, FileName);
Rewrite(f, SizeOf(aList));
for i := 0 to list.Count - 1 do
BlockWrite(f, list[i]^, 1);
CloseFile(f);
end;procedure LoadListFromFile(FileName: string);
var
numRead: Integer;
f: file;
begin
AssignFile(f, FileName);
Reset(f, SizeOf(aList));
repeat
New(aRecord);
BlockRead(f, aRecord^, 1, numRead);
if numRead = 1 then list.Add(aRecord);
until numRead < 1;
CloseFile(f);
end;
这个问题现在已解决了,特别谢谢大家
特别谢谢sysu(死树)
分不多,大家不要介意