為何在private與protected裡宣告的變數無法被assign值? |
尚未結案
|
aAlan
一般會員 ![]() ![]() 發表:38 回覆:24 積分:12 註冊:2004-07-23 發送簡訊給我 |
各位大大:
煩請幫小弟一下,此問題有兩個地方標有●的標示。
程式由procedure TForm1.btnDetectClick(Sender: TObject);開始執行:
1●.檔程式轉移到父類別Sensor後執行到居然會自動跳過interval:=Interval,why ?
2●.當執行到IPAddress:=Target的時候程式就出現「Project prjSensor.exe raised exception class EAccessViolation with message 'Access violation at address 00403EC8 in module prjsensor.exe.......」為何會如此呢? 以上兩個問題,我已經debug好久了,都無法解決,還望各位大大教我.......... unit uIPSensor; interface uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, uSensor, ExtCtrls; type
TForm1 = class(TForm)
ComboBox1: TComboBox;
btnDetect: TButton;
Memo1: TMemo;
Panel1: TPanel;
procedure btnDetectClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end; TIPSensor = class(TSensor) //IPSensor繼承自Sensor
private
IPAddress:string;
protected
function Detect():boolean; override;
function ShellApplication(AppName:String;AMemo:TMemo):string;
public
constructor create();
procedure IPSensor(Name,Target:string;Interval:integer);
end; var
Form1: TForm1;
IPSensor1: TIPSensor;
implementation {$R *.dfm} constructor TIPSensor.create;
begin
inherited Create;
ShowMessage('TIPSensor.Create執行');
end; procedure TIPSensor.IPSensor(Name,Target:string;Interval:integer);
begin
●inherited sensor(Name,Target,Interval);
●IPAddress:=Target;
end; procedure TForm1.btnDetectClick(Sender: TObject);
var
Sensor:array[0..2] of TSensor;
begin
IPSensor1.IPSensor('PingDetect',comboBox1.Text,3);
Sensor[0]:=IPSensor1.create;
Sensor[0].Countdown();
end; unit uSensor; interface uses Classes,Dialogs; type
TSensor = Class
private
timer:integer;
procedure StatusChangeAlert();
protected
name:string;
target:string;
status:boolean;
interval:integer;
function Detect():boolean; virtual;
public
constructor Create();
procedure Sensor(Name,Target:string;Interval:integer);
procedure Countdown();
end; implementation constructor TSensor.Create();
begin
inherited Create;
ShowMessage('TSensor.Create執行');
status:=False;
interval:=-1;
timer:=-1;
end; procedure TSensor.Sensor(Name,Target:string;Interval:integer);
begin
name:=Name;
target:=Target;
interval:=Interval;
end; //end procedure
|
william
版主 ![]() ![]() ![]() ![]() ![]() 發表:66 回覆:2535 積分:3048 註冊:2002-07-11 發送簡訊給我 |
|
RogerHer
一般會員 ![]() ![]() 發表:11 回覆:39 積分:10 註冊:2002-03-13 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |