两个子程序都属于Public类型
procedure creattantou(); //该函数可以访问mytantou的成员变量
procedure data_init();//出现错误:提示信息Inaccessible value
var
Mainfrm: TMainfrm;
.........
mytantou:array[1..64,1..18] of tmyclass ;//里面涉及的成员变量都是Public
.........procedure TMainfrm.creattantou (); //建立探头并初始化其属性HWM
var
ini:tinifile;
a,l,m,j,x,y:integer;
begin
....
mytantou[l][m]:=tmyclass.Create(self);
mytantou[l][m].Parent:=scrollbox1;
mytantou[l][m].Picture.Icon.Handle:=htan;
mytantou[2][2].station := mybyte[3]; //站号
mytantou[1][1].port := mybyte[4] ; //端口号
....
end;procedure TMainfrm.data_init()
begin
mytantou[2][2].station := mybyte[3]; //站号
mytantou[1][1].port := mybyte[4] ; //端口号
.....
end;
各位师兄师姐帮忙看看 原因是什么?自己是学习C++的,刚接手这个程序 有点不明白
procedure creattantou(); //该函数可以访问mytantou的成员变量
procedure data_init();//出现错误:提示信息Inaccessible value
var
Mainfrm: TMainfrm;
.........
mytantou:array[1..64,1..18] of tmyclass ;//里面涉及的成员变量都是Public
.........procedure TMainfrm.creattantou (); //建立探头并初始化其属性HWM
var
ini:tinifile;
a,l,m,j,x,y:integer;
begin
....
mytantou[l][m]:=tmyclass.Create(self);
mytantou[l][m].Parent:=scrollbox1;
mytantou[l][m].Picture.Icon.Handle:=htan;
mytantou[2][2].station := mybyte[3]; //站号
mytantou[1][1].port := mybyte[4] ; //端口号
....
end;procedure TMainfrm.data_init()
begin
mytantou[2][2].station := mybyte[3]; //站号
mytantou[1][1].port := mybyte[4] ; //端口号
.....
end;
各位师兄师姐帮忙看看 原因是什么?自己是学习C++的,刚接手这个程序 有点不明白
A variable MyMatrix of type TMatrix can be indexed like this: MyMatrix[2,45]; or like this: MyMatrix[2][45].
这是Delphi上面的原话。而且creattantou已经用过[][]的形式了,而且很正常。
mytantou:array[1..64,1..18] of tmyclass ;//里面涉及的成员变量都是Public
要放在单元的接口部分,而非实现部分,更不要放在过程或函数内部。
unit myclass;interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, ComCtrls;type
tmyclass=class(timage)public
station,port,ddynumber,x,y,flag,flag1,sflag,cut_flag,kui_flag,fu_flag,bj,yw:Byte;
//坐标,类型标记 Flag 含义:0表示无烟否则表示有烟,BJ含义:0为报警,2为 停止报警,kui_flag:0表示有电,反之没有电。
value,alarm1,alarm2,cutdown,fudian,max:Double ;
address,leixing,danwei:string;
riqi:Variant ;
kt:integer;//开停次数
kui_st,kui_port:integer;
ddyqu:string;
end;implementation
end.
procedure myktequipclick(sender:tobject);
procedure creatfan();//
procedure myfanclick(sender:tobject);
procedure creatdoor();
procedure mydoorclick(sender:tobject);
procedure creattantou(); //使用该函数正常
procedure mytantouclick(sender:tobject);
procedure myclear(); procedure mcheckalarm();
procedure ywcheckalarm(var bb,cc:integer);
procedure ktcheckalarm();
procedure fancheckalarm();
procedure fengcheckalarm(); procedure myalarmclear();
procedure malarm_list
procedure data_init(); //这个函数不可以
procedure kalarm_list();
procedure save_alarm();
procedure save_kalarm();
procedure crc_check();
procedure senddata(command:string);
//procedure kuidian_check
var
ini:tinifile;
a,l,m,j,x,y:integer;
begin
ini:= TIniFile.Create(mypath+'StationSetup.ini');
mt:=0;
for a:=1 to 64 do
begin
j:=ini.Readinteger('DetectorCode'+inttostr(a-1),'show',0);
l:=ini.Readinteger('DetectorCode'+inttostr(a-1),'station',0);
m:=ini.Readinteger('DetectorCode'+inttostr(a-1),'port',0) ;
x:=ini.Readinteger('DetectorCode'+inttostr(a-1),'x',-1);
y:=ini.Readinteger('DetectorCode'+inttostr(a-1),'y',-1);
if(j<>0)and(l<>0) and (m<>0) and (x<>-1)and (y<>-1) then
begin
with datafrm.fenzhQuery do
begin
close;
SQL.Clear ;
SQL.Add('select * from tb_fenzhan where');
SQL.Add('(st_number=:station) and (port_number=:port) and (tantou_name<>''风'+'门'')');
Parameters.ParamByName('station').Value :=l;
parameters.ParamByName('port').Value :=m;
open;
if recordcount<>0 then
begin
mt:=mt+1;
itantou[mt]:=l;
itantou1[mt]:=m;
mytantou[l][m]:=tmyclass.Create(self);
mytantou[l][m].Parent:=scrollbox1;
mytantou[l][m].Picture.Icon.Handle:=htan;
mytantou[l][m].Left :=x;
mytantou[l][m].Top :=y;
mytantou[l][m].station :=l;
mytantou[l][m].port :=m;
mytantou[l][m].address :=fieldbyname('tantou_address').AsString;
mytantou[l][m].leixing :=fieldbyname('tantou_name').AsString;
mytantou[l][m].alarm1:=fieldbyname('alarm1').AsFloat ;
mytantou[l][m].cutdown :=fieldbyname('cutdown_v').AsFloat ;
mytantou[l][m].ddynumber:=fieldbyname('ddy_number').AsInteger ;
mytantou[l][m].fudian :=fieldbyname('fudian_v').AsFloat ;
mytantou[l][m].Tag :=mt;
mytantou[l][m].max :=0; //初始最大值
mytantou[l][m].OnClick :=mytantouclick;
mytantou[l][m].flag :=0;
mytantou[l][m].sflag :=0; //0:标签不闪烁1:闪烁
mytantou[l][m].cut_flag :=0;
mytantou[l][m].kui_flag:=1;
mytantou[l][m].fu_flag :=0;
mytantou[l][m].bj:=2;
mytantou[l][m].AutoSize :=true ;
//标签
mytantoutxt[l][m]:=TLabel .Create(self);
mytantoutxt[l][m].Parent :=scrollbox1;
mytantoutxt[l][m].Height :=33;
mytantoutxt[l][m].Width :=80;
mytantoutxt[l][m].AutoSize :=false;
mytantoutxt[l][m].Left :=x+20;
mytantoutxt[l][m].Top:=y+10;
mytantoutxt[l][m].Font.Color:=clHighlightText ;
mytantoutxt[l][m].Font.Size :=8;
mytantoutxt[l][m].Caption :=mytantou[l][m].leixing+inttostr(mytantou[l][m].station)+'-'+inttostr(mytantou[l][m].port); mytantoushap[l][m]:=TShape.Create(self);
mytantoushap[l][m].Parent:=ScrollBox1 ;
mytantoushap[l][m].Width :=17;
mytantoushap[l][m].Height :=25;
mytantoushap[l][m].Shape:=stcircle;
mytantoushap[l][m].Brush.Color :=clLime ;
mytantoushap[l][m].Left :=x+76;
mytantoushap[l][m].Top:=y+5;
with Datafrm.view_quyu do //视图中断电区域
begin
close;
sql.Clear ;
sql.Add('select * from view_quyu where') ;
sql.Add('st_number=:st_number and port_number=:port_number');
Parameters.ParamByName('st_number').Value := l;
Parameters.ParamByName('port_number').Value := m;
open;
if recordcount <>0 then
begin
mytantou[l][m].kui_st:=fieldbyname('kui_st').AsInteger;
mytantou[l][m].kui_port:=fieldbyname('kui_port').AsInteger;
mytantou[l][m].ddyqu:=fieldbyname('ctr_quyu').Asstring;
end;
end;
end;
end;
end ;
end;
ini.Free ;
end;
这个函数内Mytantou数组可以使用;
============
这样的构造函数的调用,data_init()中是否漏掉了?
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, ComCtrls, XPMan, ImgList, ToolWin, Menus,
Grids, DBGrids,inifiles, OleCtrls,myclass, MSCommLib_TLB;type
TMainfrm = class(TForm)
XPManifest1: TXPManifest;
StatusBar1: TStatusBar;
MainMenu1: TMainMenu;
N1: TMenuItem;
N3: TMenuItem;
N4: TMenuItem;
N5: TMenuItem;
N6: TMenuItem;
N7: TMenuItem;
dd: TMenuItem;
N9: TMenuItem;
cedian: TMenuItem;
N2: TMenuItem;
N11: TMenuItem;
N12: TMenuItem;
N13: TMenuItem;
N14: TMenuItem;
N15: TMenuItem;
N16: TMenuItem;
N18: TMenuItem;
N19: TMenuItem;
Image1: TImage;
N17: TMenuItem;
N20: TMenuItem;
N21: TMenuItem;
ToolBar1: TToolBar;
N22: TMenuItem;
N23: TMenuItem;
N24: TMenuItem;
N25: TMenuItem;
tool: TMenuItem;
Timer1: TTimer;
Panel2: TPanel;
N8: TMenuItem;
N10: TMenuItem;
N26: TMenuItem;
ScrollBox1: TScrollBox;
Splitter1: TSplitter;
Panel1: TPanel;
N27: TMenuItem;
ToolButton1: TToolButton;
ImageList1: TImageList;
ToolButton2: TToolButton;
ToolButton3: TToolButton;
ToolButton4: TToolButton;
ToolButton5: TToolButton;
ToolButton6: TToolButton;
ToolButton8: TToolButton;
ToolButton9: TToolButton;
ToolButton10: TToolButton;
ToolButton11: TToolButton;
ToolButton12: TToolButton;
N29: TMenuItem;
N30: TMenuItem;
N28: TMenuItem;
ToolButton13: TToolButton;
N31: TMenuItem;
Button1: TButton;
Button2: TButton;
Timer2: TTimer;
StaticText1: TStaticText;
Button3: TButton;
ToolButton14: TToolButton;
Timer3: TTimer;
StringGrid1: TStringGrid;
StringGrid2: TStringGrid;
N32: TMenuItem;
N33: TMenuItem;
Button4: TButton;
MSComm1: TMSComm;
procedure FormCreate(Sender: TObject);
procedure N19Click(Sender: TObject);
procedure N4Click(Sender: TObject);
procedure toolClick(Sender: TObject);
procedure N7Click(Sender: TObject);
procedure N11Click(Sender: TObject);
procedure N20Click(Sender: TObject);
procedure N21Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure N8Click(Sender: TObject);
procedure creatmenu();
procedure bmp_click(Sender: TObject);
procedure N13Click(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure ToolButton1Click(Sender: TObject);
procedure ToolButton2Click(Sender: TObject);
procedure ToolButton4Click(Sender: TObject);
procedure N26Click(Sender: TObject);
procedure N12Click(Sender: TObject);
procedure ToolButton13Click(Sender: TObject);
procedure N31Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Timer2Timer(Sender: TObject);
procedure cedianClick(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
procedure StringGrid2DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
procedure Timer3Timer(Sender: TObject);
procedure MSComm1Comm(Sender: TObject);
procedure ToolButton14Click(Sender: TObject);
procedure N33Click(Sender: TObject);
procedure ddClick(Sender: TObject);
procedure ToolButton3Click(Sender: TObject);
procedure Button4Click(Sender: TObject); public
procedure creatfenzhan(); //创建分站 procedure creatktequip();//kai ting
procedure myktequipclick(sender:tobject);
procedure creatfan();//风机
procedure myfanclick(sender:tobject);
procedure creatdoor();//风门
procedure mydoorclick(sender:tobject);
procedure creattantou(); //探头{ch4.co.co2.水位.风速...}
procedure mytantouclick(sender:tobject);
procedure myclear(); procedure mcheckalarm(); //模拟两
procedure ywcheckalarm(var bb,cc:integer); //烟雾
procedure ktcheckalarm(); //开停设备
procedure fancheckalarm(); //风机
procedure fengcheckalarm(); //风门
procedure myalarmclear();
procedure malarm_list();//模拟两报警列表显示
procedure data_init(); //接收数据分类
procedure kalarm_list();//开关量报警列表显示
procedure save_alarm();
procedure save_kalarm();
procedure crc_check();//CRC校验 (实际上并没有使用)
procedure senddata(command:string);
//procedure kuidian_check();//馈电状态检测{ Private declarations } public
procedure mykuiclear();
procedure creatkuidian();//kui dian { Public declarations }
end;
const
dwname:array[0..10] of string =('%CH4','%CH4','Ppm','Ppm','M/S','℃','KPa','KPa','VOL','M','次');
ny:array[0..1] of string=('有','无');
var
Mainfrm: TMainfrm;
mypath:string;
item:TMenuItem;
i:integer; //菜单的tag
b,d,k:integer;// 风机、风门,开停图替换控制
data1:TStringList ; //动态菜单名称存放
mystation:array of tmyclass ;
ms,mf,md,mt,mkt,mkui:integer; //ICO数量
myfan:array[1..64,1..18] of tmyclass ;
mytantou:array[1..64,1..18] of tmyclass ; //探头 (容量:64个分站,18个端口)
mydoor:array[1..64,1..18] of tmyclass ;
myktequip:array[1..64,1..18] of tmyclass ;
mykuidian:array[1..64,1..18] of tmyclass ;
itantou,itantou1,idoor,idoor1,ifan,ifan1,ikt,ikt1,ikd,ikd1,istation,
ikui,ikui1:array[1..64]of integer; //itantou分站序列
hzhan:HICON; //分站图标
htan:HICON; //探头
myfantxt:array[1..64,1..16] of TLabel;
mytantoutxt:array[1..64,1..16] of TLabel;
mytantoushap:array[1..64,1..16] of TShape ; //state
myfanshap: array[1..64,1..16] of TShape;
mydoortxt:array[1..64,1..16] of TLabel;
myktequiptxt:array[1..64,1..16] of TLabel;
mystationtxt:array of TLabel;
hfan:array[1..3] of HICON;
hdoor:array[1..3 ]of HICON;
hkt:array[1..2 ]of HICON;
mrowcount,krowcount:integer; //模拟、开关报警行数
mstation,mport:integer;
mvalue,maverage:DOUBLE;
malarm_name,mmax,malarm,mcut,mcutqu,mcuoshi,mbj:string; //模拟量报警内容
kalarm_name,kalarm,kcut,kcutqu,kcuoshi,kbj:string;
lx:integer;//接受的数据类型;
mybyte:array[0..9] of Byte ; //串口数据
implementation
uses cedian,login,data,jb,duan,GIS,adduser,DateUtils,shellapi,cx,stationinfo,
ADODB, DB,alarm, ComConst,comm,curve;
那个函数好像在Data_init不能使用吧?
因为一旦使用了 Creattantou里面很多属性都丢失了。