我是Delphi 2010的法语用户,所以请原谅我的英语不好。
我已经从一个TCustomControl创建了一个控件。此控件有一个由TOwnedCollection后代填充的TCollectionItem。这些项目具有已发布的自定义列表属性。这个列表是我做的一对整数的列表。我已经为这个属性编写了一个自定义设计时编辑器,它工作得非常完美。所以现在,我想把列表数据写到dfm中,这样就变得有点困难了。
以下是我所做的:
TPedroGraphLineCollectionIem = class(TCollectionItem)
published
property PointList: TPedroIntegerCoupleList read FList write SetList
stored GetStored;
...
procedure TPedroGraphLineCollectionIem.DefineProperties(Filer: TFiler);
begin
inherited;
//'PointList' : the property name
//FList.Count > 0 : Is the list empty ?
Filer.DefineProperty('PointList', ReadListData, WriteListData,
(FList.Count > 0));
end;
...
procedure TPedroGraphLineCollectionIem.ReadListData(Reader: TReader);
var
Val1, Val2: Integer;
begin
with Reader do
begin
ReadListBegin;
while not EndOfList do
begin
Val1 := ReadInteger;
Val2 := ReadInteger;
FList.AddCouple(Val1, Val2);
end;
ReadListEnd;
end;
end;
...
procedure TPedroGraphLineCollectionIem.WriteListData(Writer: TWriter);
var
I: Integer;
begin
with Writer do
begin
WriteListBegin;
for I := 0 to Count - 1 do
begin
WriteInteger(FList[I].Value1);
WriteInteger(FList[I].Value2);
end;
WriteListEnd;
end;
end;WriteListData过程完美地工作,并将值写入dfm。但是,当我试图加载表单时,它总是会崩溃,一个对话框告诉我,这个属性上有一个读取流错误。
FList是在类的构造函数中创建的。
下面是.dfm:
object MainFrm: TMainFrm
Left = 0
Top = 0
Caption = 'MainFrm'
ClientHeight = 425
ClientWidth = 689
Color = clBtnFace
ParentFont = True
OldCreateOrder = False
Position = poScreenCenter
OnCreate = FormCreate
OnDestroy = FormDestroy
PixelsPerInch = 96
TextHeight = 13
object PedroGraph1: TPedroGraph
Left = 120
Top = 136
Width = 313
Height = 209
TitleFont.Charset = DEFAULT_CHARSET
TitleFont.Color = clWindowText
TitleFont.Height = -11
TitleFont.Name = 'Tahoma'
TitleFont.Style = []
Lines = <
item
LinePen.Color = clRed
PointList = (
1
2
3
4)
end>
MarksFont.Charset = DEFAULT_CHARSET
MarksFont.Color = clWindowText
MarksFont.Height = -11
MarksFont.Name = 'Tahoma'
MarksFont.Style = []
end
end错误信息(法文):
1
Erreur lors de la lecture de TPedroGraphLineCollectionItem.PointList: Valeur de propriété incorrecte. Ignorer l'erreur et continuer ?Remarque: ceci peut provoquer la suppression de composants ou la perte de valeurs de propriété2
Erreur lors de la讲座de TPedroGraphLineCollectionItem.-:la propriété--不存在pas.不光彩者L‘’erreur et continuer ?再婚: ceci peut‘erreur la composants ou la perte de valeur de propriété
注意:“-”字符实际上是这样显示的。
3.
4.
埃里尔教授佩德罗石墨线1.线: propriétéincorrecte。不光彩者L‘’erreur et continuer ?再婚: ceci peut‘erreur la composants ou la perte de valeur de propriété
5
非洲之声:流言之声。
TPedroIntegerCoupleList声明:
TPedroIntegerCouple = record
Value1: Integer;
Value2: Integer;
end;
TPedroGenericList<T> = class(TList<T>)
private
FOnChange: TNotifyEvent;
FUpdating: Boolean;
protected
procedure Notify(const Item: T; Action: TCollectionNotification); override;
procedure DoChange;
published
public
constructor Create;
procedure SortCustom; virtual; abstract;
procedure Assign(const Source: TPedroGenericList<T>);
property OnChange: TNotifyEvent read FOnChange write FOnChange;
end;
TPedroIntegerCoupleList = class(TPedroGenericList<TPedroIntegerCouple>)
private
function GetString: String;
procedure SetString(const Value: String);
public
procedure SortCustom; override;
function AddCouple(const Value1, Value2: Integer): Integer;
procedure InsertCouple(const Index, Value1, Value2: Integer);
property AsString: String read GetString write SetString;
end;我哪里错了?
发布于 2013-12-17 10:21:12
我认为您忽略了DefineProperty和published的要点--它们是相互排斥的。
published意味着VCL将通过自己的方式存储不动产。DefineProperty意味着没有这样的不动产,但是如果有虚拟的房产,你会假装的。你的DFM是什么?可能是“PointList”在那里存储了两次--作为列表和组件?
如果是这样的话,您应该只选择一种方法来保存它,例如,让属性公开而不是发布。
或者你也可以试着用非冲突的名字
property PointList: TPedroIntegerCoupleList read FList write SetList stored FALSE;
Filer.DefineProperty('PointList_Virtual_DATA', ....https://stackoverflow.com/questions/20631235
复制相似问题