我想在一个文件中存储这样的一个有序列,
序列中一个纪录包括三个字段:显示时排列的顺序号(比如用整数),标题(大约1-30个汉字),内容(最多不超过1000个汉字)。
我不想用数据库来存储,因为我的纪录并不多。但这个有序列要能比较方便的实现:新增,排序,修改,删除操作。请问用什么样的方式来实现最方便编程?
在VB.NET中有现成的SortList类,但Delphi中应当用什么办法?
序列中一个纪录包括三个字段:显示时排列的顺序号(比如用整数),标题(大约1-30个汉字),内容(最多不超过1000个汉字)。
我不想用数据库来存储,因为我的纪录并不多。但这个有序列要能比较方便的实现:新增,排序,修改,删除操作。请问用什么样的方式来实现最方便编程?
在VB.NET中有现成的SortList类,但Delphi中应当用什么办法?
type
type
MyClass= class
No:Integer;
Title:string;
Content:string;
end;
var
MyList:TStrings;
MyList := TStringList.create;
MyList.AddObject("", MyClass对象);
不知是否还有其它方法?
type
MyClass= class
No:Integer;
Title:string;
Content:string;
end;
var
MyList:TList;
MyList := TList.create;
MyList.Add(MyClass对象);抄加改.
TStringList 倒是可以做,但是addobject是把TObject加给TStringlist
Note: The TStringList object does not own the objects you add this way. Objects added to the TStringList object still exist even if the TStringList instance is destroyed. They must be explicitly destroyed by the application.
又如何存盘呢?
TStringList可以有现成的方法直接存盘吗?
请看下面的代码?执行时报错:“stack overflow”我用F7 Trace into,发现执行到fillItem1.Create(0,'test','Test');一句时就会陷入循环,一直执行该句不会往下运行,不知这是为什么啊?unit Unit1;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;type
TFillItem= class
No:Integer;
Title:string;
Content:string;
constructor create(_No: Integer;_Title: String;_Content:String);
end; TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
MyList:TStrings;implementation{$R *.DFM}
Constructor TFillItem.Create(_No: Integer;_Title: String;_Content: String);
begin
No:=_No;
Title:=_Title;
Content:=_Content;
end;procedure TForm1.FormCreate(Sender: TObject);
var
fillItem1: TFillItem;
begin
MyList := TStringList.create;
fillItem1.Create(0,'test','Test');
MyList.AddObject('test0', fillItem1);end;end.
TfillItem1.Create(0,'test','Test');
fillItem1:=TfillItem.Create(0,'test','Test');
MyList.AddObject('0', fillItem1);
MyList.SaveToFile('test.txt');对象无法存入文件,test.txt只存入了'0'这个字符串。
加分!请大家多多指点?
myrecord=record
id:integer;
title:string;
memo:string;
end;var varrecord:myrecord;要是多个记录可定义一个数组:var varrecord:array[0..N] of myrecord 这样就可以了
该控件可以生成一个文件.CDS.当然,也可以用其它的文件名.如果要自己写代码,太麻烦了.用TLIST和TSTRINGLSIT都是一样的,
都要自己用类来保存到文件中去.
保存时按照两个索引的顺序,顺序存储到文件中,可以使用 Record 类型存储。
好,我试试TClientDataSet和 CloneCenter(复制中心)的方法。
非常感谢谢大家。