我有一个项目和两个单位和主程序 第一单元在这里它的主要问题是这个类的构造函数:这段代码中的构造函数不好。有人可以帮助我管理这些代码吗?
unit dl_tPA_MailJournal;
interface
uses
Windows,
Generics.Collections,
SysUtils,
uInterfaces;
type
TtPA_MailJournal = class(TInterfacedObject ,ITable)
public
function GetanQId: integer;
procedure SetanQId(const Value: integer);
function GetadDate: TDateTime;
procedure SetadDate(const Value: TDateTime);
function toList: TList<string>;
constructor Create(aId : Integer; aDate : TDateTime);
private
property anQId : integer read GetanQId write SetanQId;
property adDate : TDateTime read GetadDate write SetadDate;
end;
implementation
{ TtPA_MailJournal }
constructor TtPA_MailJournal.Create(aId : Integer; aDate : TDateTime);
begin
SetanQId(aId);
SetadDate(aDate);
end;
function TtPA_MailJournal.GetadDate: TDateTime;
begin
Result := adDate;
end;
function TtPA_MailJournal.GetanQId: integer;
begin
Result := anQId ;
end;
procedure TtPA_MailJournal.SetadDate(const Value: TDateTime);
begin
adDate := Value;
end;
procedure TtPA_MailJournal.SetanQId(const Value: integer);
begin
anQId := Value;
end;
function TtPA_MailJournal.toList: TList<string>;
var aListTable: TList<TtPA_MailJournal>;
var aTable: TtPA_MailJournal;
var aListString: TList<String>;
begin
aTable.Create(1,now);
aListTable.Add(aTable);
aTable.Create(2,now);
aListTable.Add(aTable);
aListString.Add(aListTable.ToString);
Result := aListString;
end;
end.
第二单元是没有多少在这里看到
接口unit uInterfaces;
interface
uses Generics.Collections;
type
ITable = Interface
['{6CED8DCE-9CC7-491F-8D93-996BE8E4D388}']
function toList: TList<String>;
End;
implementation
end.
的主类,在这里我想StringList的仿制药,并放入格:
unit MainUnit;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs,
dl_tPA_MailJournal,uInterfaces, Vcl.StdCtrls,
Generics.Collections, Vcl.Grids;
type
TForm1 = class(TForm)
Button1: TButton;
StringGrid1: TStringGrid;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var MyTable: TtPA_MailJournal;
MyList: TList<String>;
AStringList: TStrings;
StrDate : string;
Fmt: TFormatSettings;
begin
//fmt.ShortDateFormat:='dd/mm/yyyy';
// fmt.DateSeparator :='/';
// StrDate:='23/02/2011' ;
MyTable := TtPA_MailJournal.Create(1,now); //strtodate(strdate,fmt)
MyList := MyTable.toList;
AStringList := TStringList.Create;
AStringList.Add(MyList.ToString);
StringGrid1.Cols[1].Add(MyList.ToString);
FreeAndNil(MyTable);
end;
end.
当我点击程序崩溃的按钮。当我评论这两个 行的构造函数SetanQId(aId);和SetadDate(aDate);这是好的 我做错了什么可以告诉我如何管理这个代码,以显示在网格请。
您设定自己的二传手属性值依次调用一遍传,等我 – TLama
其更改为援助:所以你的构造应进行编码=援助; aDate:= aDate;现在我得到访问冲突错误 – ververicka
编程不是试错过程。你尝试过的改变基本上是一样的。它会为该属性设置一个值,该属性将调用setter方法,在该方法中,您将为将调用setter的属性设置一个值...等等。你已经结束了无限循环。我不知道这些属性的目的是什么,但是根据你的getter和setter做的事情,我会说你想要[将读写私人字段的属性](http://pastebin.com/Rjve1Knp)。 – TLama