编译程序时,在下短代码出错了,还没完成主窗体创建.错误如下
Project GIS.exe raised exception class EAccessViolation with message´Access violation at address 00478ac9 in module ´GIS.EXE´.Read address FFFFFFF´.
先说明主要是显示了子窗体中Map的信息,头痛呀 unit addlayerinfo; interface uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,MapXLib_TLB, ComObj; type
Tlayerform = class(TForm)
layerListBox: TListBox;
Label1: TLabel;
addinfo: TButton;
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure addinfoClick(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end; var
layerform: Tlayerform; currentmap:TMap;
implementation uses GisGroup, layerstruce, MdiChild; {$R *.dfm} procedure Tlayerform.FormCreate(Sender: TObject);
var
lyr:mapxlib_tlb.layer;
i:integer;
begin
currentmap := (ActiveMdiChild as TMapwin).Map1; //运行到这报错
layerListBox.Clear;
for i:=1 to currentmap.Layers.Count do
begin
lyr:=currentmap.layers.item(i);
layerListBox.items.Add(lyr.Name);
end;
end; procedure Tlayerform.addinfoClick(Sender: TObject);
begin
addinfolayer.show;
end; procedure Tlayerform.Button1Click(Sender: TObject);
begin
close;
end; end.
Project GIS.exe raised exception class EAccessViolation with message´Access violation at address 00478ac9 in module ´GIS.EXE´.Read address FFFFFFF´.
先说明主要是显示了子窗体中Map的信息,头痛呀 unit addlayerinfo; interface uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,MapXLib_TLB, ComObj; type
Tlayerform = class(TForm)
layerListBox: TListBox;
Label1: TLabel;
addinfo: TButton;
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure addinfoClick(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end; var
layerform: Tlayerform; currentmap:TMap;
implementation uses GisGroup, layerstruce, MdiChild; {$R *.dfm} procedure Tlayerform.FormCreate(Sender: TObject);
var
lyr:mapxlib_tlb.layer;
i:integer;
begin
currentmap := (ActiveMdiChild as TMapwin).Map1; //运行到这报错
layerListBox.Clear;
for i:=1 to currentmap.Layers.Count do
begin
lyr:=currentmap.layers.item(i);
layerListBox.items.Add(lyr.Name);
end;
end; procedure Tlayerform.addinfoClick(Sender: TObject);
begin
addinfolayer.show;
end; procedure Tlayerform.Button1Click(Sender: TObject);
begin
close;
end; end.
var
lyr:mapxlib_tlb.layer;
i:integer;
begin
currentmap := (ActiveMdiChild as TMapwin).Map1; //运行到这报错
layerListBox.Clear;
for i:=1 to currentmap.Layers.Count do
begin
lyr:=currentmap.layers.item(i);
layerListBox.items.Add(lyr.Name);
end;
end;
你把上这段代码写在FORM的ONSHOW事件中看一看?
riff ur life
----------------------------------------------
riff ur life
currentmap:=(form1.activeMDIChild as Tmapwin).map1
就可以了。form1是你的主窗体
----------------------------------------------
riff ur life
----------------------------------------------
riff ur life
----------------------------------------------
riff ur life
有谁能解释一下为什么这里不需要写Currentmap:=Tmap.create么?
----------------------------------------------
riff ur life
----------------------------------------------
riff ur life
----------------------------------------------
riff ur life