从C#背景发送我想学Delphi。 我在我的表单中遇到访问冲突,我按下了一个创建TLight实例的按钮。 无论我尝试访问我的私人FState,我都会遇到访问冲突。初始化私人变量创建AccessViolation
我错过了什么?
unit Light;
interface
uses sysUtils;
type
TLightStates = (Red, Orange, Green);
type
TLight = class
private
Fstate : TLightStates;
published
Constructor Create(); overload;
procedure SetState(const Value: TLightStates);
Property State : TLightStates
read Fstate
write SetState;
end;
implementation
{ TLight }
constructor TLight.Create;
begin
Fstate := TLightStates.Red;
end;
procedure TLight.SetState(const Value: TLightStates);
begin
Fstate := Value;
end;
end.
啊哈,我没有初始化它在C#枚举不需要创建。我压倒一切的原因是因为我在教程中看到了这种情况;)我现在看到这是毫无意义的。 Thx – 2010-02-01 12:35:35
@Ritsaert - 你其实意味着重写而不是重载;覆盖会导致应用于非虚拟方法时的语法错误;超载可以应用于任何方法,这里只是没有意义。 – kludg 2010-02-01 13:03:18
>我没有初始化它,因为在C#中不需要创建枚举。 delphi枚举不需要被实例化。在C#中,您可以声明一个对象,以便它自动创建(并销毁)。令人遗憾的是,德尔福没有这个。 – 2010-02-01 13:34:50