為何宣告在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
|
shaofu
高階會員 發表:5 回覆:136 積分:103 註冊:2003-01-07 發送簡訊給我 |
1. Delphi 中是不分大小寫的, 以下三行無實質意義
procedure TSensor.Sensor(Name,Target:string;Interval:integer); begin name:=Name; target:=Target; interval:=Interval; end; //end procedureinterval := Interval 這行被 complier 最佳化掉了, name 跟 target 我想因為是指標操作所以沒被最佳化 建議: class="code"> procedure TForm1.btnDetectClick(Sender: TObject); var Sensor:array[0..2] of TSensor; begin IPSensor1.IPSensor('PingDetect',comboBox1.Text,3); // 除非是 class method Sensor[0]:=IPSensor1.create; Sensor[0].Countdown(); end; procedure TIPSensor.IPSensor(Name,Target:string;Interval:integer); begin inherited sensor(Name,Target,Interval); IPAddress:=Target; end; 因為 IPSensor1 還沒 Create, IPAddress 也並未存在記憶體中, 所以一操作就當了 至於前兩步呼叫 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |