MapWindow 4 - ActiveX Control Programming : MapWindow Discussion Forum
I work with Delphi 2009 and I get a strange thing. The following code: LayerHandle := Map.AddLayer(sf, true); When run from delphi IDE works fine, but when launching application from the drive, it throws an exception (floating point division by zero), and
addLayer bug?
Posted by: huki1 ()
Date: August 18, 2009 03:33AM

I work with Delphi 2009 and I get a strange thing. The following code:
LayerHandle := Map.AddLayer(sf, true);

When run from delphi IDE works fine, but when launching application from the drive, it throws an exception (floating point division by zero), and the map is coloured black.

Any ideas about the reason of that?


shapeFile seems to be loaded correclty, since sf.numShapes shows the actual number of shapes.

I've just created a simple app(just a map on the form) that loads and displays the shapefile in the easiest possible way - sf.open(path), map.addlayer(sf, true) and it worked from outside the IDE.

I'm sure that the exception is thrown by addLayer function.

Any help will be appreciated.



Edited 1 time(s). Last edit at 08/18/2009 08:57AM by huki1.

Options: ReplyQuote
Re: addLayer bug?
Posted by: huki1 ()
Date: August 25, 2009 01:45AM

I tried to deal with the problem I had described and found some interesting behaviour:
- now I create and add the TMap component manually, from the code. It works when the shapefile is rather small: 325 KB. The larger file (above 8MB) results in black map.
- The larger file is displayed properly, after I display initially the smaller one, and afterwards the larger.

Still everything works fine when run from IDE (delphi 2009)

I would be gratefull for any feedback



Edited 1 time(s). Last edit at 08/25/2009 01:46AM by huki1.

Options: ReplyQuote
Re: addLayer bug?
Posted by: pmeems ()
Date: August 26, 2009 12:31AM

What happens if you open the shapefile with MapWindow itself.
Does it open properly?
If so the problem is not with the shapefile or AddLayer().

I'm not a Delphi guy, but could you post some code?

Thanks,

Paul

--
Don't forget to read the new documentation: www.mapwindow.org/documentation/mapwingis4.8
Join us Google+: MapWindow GIS Google+ Community
Join the MapWindow Group on LinkedIn! LinkedIn - MapWindow Group

Download the latest beta installer at:
tinyurl.com/mwMonthly 32-Bit
tinyurl.com/mwMonthlyx64 64-Bit
Follow me on Twitter MapWindow_nl to read when a new installer is published.

---
Paul Meems
The Netherlands
[www.bontepaarden.nl]
Release manager, configuration manager and
forum moderator of MapWindow GIS

Owner of MapWindow.nl - Support for
Dutch speaking users: www.mapwindow.nl

*******
Everything I say or write is my personal opinion and
not the opinion of the company I work for.
*******
View my profile on LinkedIn

Options: ReplyQuote
Re: addLayer bug?
Posted by: huki1 ()
Date: August 26, 2009 02:58AM

MapWindow loads both shapefiles correctly
Code as requested :

 procedure Tfmain.FormShow(Sender: TObject);
var
  sft : IShapeFile;
begin
.....
  try
    sft := CoShapefile.Create;
    if not Assigned(map) then
    begin
      map := TMap.Create(Application);

      map.Align := alClient;
      pVisLeft.InsertControl(map);
      map.OnMouseUp := fmain.mapMouseUp;
      map.OnSelectBoxFinal := fmain.mapSelectBoxFinal;
      map.OnMouseDown := fmain.mapMouseDown;
    end;
    if not sft.Open('C:\0-Work\RR-Tool\out\mapdummy.shp', nil) then
      Exit;
     //sft.numshapes here gives the right number of shapes
    try
      map.AddLayer(sft, true);
    finally
      ShowMessage('Not Again...');  //Floating point division by zero here; not in IDE
    end;

  finally

  end;
end;

I'm using MapWinGIS 4.7RC3. For installing the component I followed the guide from the site: [www.mapwindow.org]. I also used the MapWinGIS_TLB file from there. Maybe that one was for an older, not compatibile release. Or maybe someone knows how to contact with the guy who provided that code?



Edited 1 time(s). Last edit at 08/26/2009 03:59AM by huki1.

Options: ReplyQuote
Re: addLayer bug?
Posted by: huki1 ()
Date: August 26, 2009 06:30AM

I probably found the problem. I guess its not with the addlayer function.
My application requires only specific fields from a shapefile, so I when for the first time one shapefile was loaded, it created its local copy and performed some clean up:
sf.Open(OriginalFileName, nil);
if not FileExists(localCopy) then
begin
  sf.StartEditingShapes(true, nil);
  for I := sf.NumFields - 1 downto 0 do //delete all fields except the one with ID
    if mapFileIdIndex <> i then
      sf.EditDeleteField(i, nil);

  for I := sf.NumShapes - 1 downto 0 do //delete all the shapes not existing in the asset data
    if not IDList.Find(sf.CellValue[0, i], l) then
      sf.EditDeleteShape(i);



  sf.SaveAs(ExtractFilePath(ParamStr(0)) + 'Projects\' + Project.ProjName + '\' + 'Maps\' + Project.ProjName + '.shp', nil); //save the shape file as a local one
  sf.StopEditingShapes(false, true, nil);
end;

The file that code produces could be loaded by other applications. So the question is: Is there somethin wrong with that code? I commented those lines and application works great, but I still would like to perform such cleanup.

I also found that only calling the sf.saveAs function, and right after map.addlayer(sf, true). gives me the black map exception. Are there any actions that should be done after saveAs call?



Edited 2 time(s). Last edit at 08/26/2009 06:39AM by huki1.

Options: ReplyQuote
Re: addLayer bug?
Posted by: pmeems ()
Date: August 27, 2009 01:04PM

I think the problem is with the sequence of StartEditingShapes, StopEditingShapes ans SaveAs.
I would suggest to call SaveAs before StartEditingShapes. Then do your changes and at the end call StopEditingShapes(true, true, nil).

Hope it helps,

Paul

--
Don't forget to read the new documentation: www.mapwindow.org/documentation/mapwingis4.8
Join us Google+: MapWindow GIS Google+ Community
Join the MapWindow Group on LinkedIn! LinkedIn - MapWindow Group

Download the latest beta installer at:
tinyurl.com/mwMonthly 32-Bit
tinyurl.com/mwMonthlyx64 64-Bit
Follow me on Twitter MapWindow_nl to read when a new installer is published.

---
Paul Meems
The Netherlands
[www.bontepaarden.nl]
Release manager, configuration manager and
forum moderator of MapWindow GIS

Owner of MapWindow.nl - Support for
Dutch speaking users: www.mapwindow.nl

*******
Everything I say or write is my personal opinion and
not the opinion of the company I work for.
*******
View my profile on LinkedIn

Options: ReplyQuote
Re: addLayer bug?
Posted by: huki1 ()
Date: August 28, 2009 07:28AM

pmeems Wrote:
-------------------------------------------------------
> I think the problem is with the sequence of
> StartEditingShapes, StopEditingShapes ans SaveAs.
> I would suggest to call SaveAs before
> StartEditingShapes. Then do your changes and at
> the end call StopEditingShapes(true, true, nil).
>
> Hope it helps,
>
> Paul

I may be wrong, but in that case i will have an exact "local" copy of the file and the changes will be performed on the "original" one. Or is it that, after calling SaveAs, the shapeFile variable is associated with the file specified as SaveAs parameter?

Options: ReplyQuote
Re: addLayer bug?
Posted by: pmeems ()
Date: August 28, 2009 09:03AM

I would think the last. But it is good to test.
Another solution is to copy the files first and then open the copied version. Then no need to call saveAs.

--
Paul

--
Don't forget to read the new documentation: www.mapwindow.org/documentation/mapwingis4.8
Join us Google+: MapWindow GIS Google+ Community
Join the MapWindow Group on LinkedIn! LinkedIn - MapWindow Group

Download the latest beta installer at:
tinyurl.com/mwMonthly 32-Bit
tinyurl.com/mwMonthlyx64 64-Bit
Follow me on Twitter MapWindow_nl to read when a new installer is published.

---
Paul Meems
The Netherlands
[www.bontepaarden.nl]
Release manager, configuration manager and
forum moderator of MapWindow GIS

Owner of MapWindow.nl - Support for
Dutch speaking users: www.mapwindow.nl

*******
Everything I say or write is my personal opinion and
not the opinion of the company I work for.
*******
View my profile on LinkedIn

Options: ReplyQuote
Re: addLayer bug?
Posted by: Deeptown12 ()
Date: November 18, 2010 01:12AM

Hello. discovered the same problem with the cards in black

Code:

procedure TForm2.FormCreate(Sender: TObject);
var
Sh : IShapefile;
begin
Sh := CoShapefile.Create;
IF OpenDialog1.Execute then
begin
if not Sh.Open(OpenDialog1.FileName, nil) then
ShowMessage('err!');
try
Map1.AddLayer(sh,true);
Map1.ZoomToMaxExtents;
except

end;
end;
end;

The method Addlayer EDivZero error occurs after the card is black. In C + + Builder SHP-files with the same version of the ActiveX-component open properly and correctly. What should I do?
Version of Delphi - 2009

Options: ReplyQuote
Re: addLayer bug?
Posted by: vannak.chheang ()
Date: December 23, 2010 03:37PM

hi,
I met this issue with Delphi 7 also and the solution is that you need to set the focus on your component Map1 first then you can perform any operations like loading shape files or adding layers ! I remembered that I spent all night long to discover this !!!!!

Hope it can help !

Vannak

Options: ReplyQuote
Re: addLayer bug?
Posted by: Deeptown12 ()
Date: January 11, 2011 05:43AM

vannak.chheang Wrote:
-------------------------------------------------------
> hi,
> I met this issue with Delphi 7 also and the
> solution is that you need to set the focus on your
> component Map1 first then you can perform any
> operations like loading shape files or adding
> layers ! I remembered that I spent all night long
> to discover this !!!!!
>
> Hope it can help !
>
> Vannak

Thanks, are valid after focus installation all have earned as hours. It would Seem as it can influence, and here influences. Miracles.

Options: ReplyQuote


Sorry, only registered users may post in this forum.





Banner Exchange




GISCP.com




Send us your banner logo (160x120) for the space above, and add this MapWindow banner ad to your site:

Just paste this text in your page: