I have been banging my head against the wall to get a TMapControl to show up in Delphi2010 at design time without getting the generic 'ClassFactory cannot supply requested class' error message. I have a partial solution and would like to get feedback from anyone doing similar coding.I am using notes from Roger Dunn's "Working with Delphi and ArcObjects 9.3", and modified his .bat file to import the .obj files into Delphi 2010. http://arcscripts.esri.com/details.asp?dbid=14204I am also using notes from Max Gazuko for the basic licensing code found here: http://forums.arcgis.com/threads/26206-ArcGIS-10-Delphi-and-licensing?p=86977&viewfull=1#post86977After importing the esriControls_TLB.pas and arcGisVersionLib_TLB.pas into a package (see the chat from Max Gazuko for arcGisVersionLib_TLB), I modified the TMapControl constructor to check for and acquire a license from ESRI. This works, but would cause problems at design and run time if you don't have a valid license. I have also 'hard coded' this for ESRI 10.1, but that looks to be a parameter to LoadVersion() method, so it should be easily changeable to 10.0 if you are using that version:Here is the change I made to the TMapControl.Create:
constructor TMapControl.Create(AOwner: TComponent);
var
EsriHelper : TEsriHelper;
begin
// if csDesigning in self.ComponentState then
begin
EsriHelper := TEsriHelper.Create;
try
EsriHelper.AcquireEsriLicense;
finally
EsriHelper.Free;
end;
end;
inherited;
end;
The TEsriHelper class:
uses
esriControls_TLB,
arcGISVersionLib_TLB,
esriSystem_TLB,
ComObj, SysUtils;
type
TEsriHelper = class
private
FverManager: TVersionManager; // arcGISVersionLib_TLB
FIaoInit: IAoInitialize; // esriSystem_TLB
FIagVersion: IArcGISVersion; // arcGISVersionLib_TLB
public
destructor Destroy; override;
procedure AcquireEsriLicense;
end;
procedure TEsriHelper.AcquireEsriLicense;
var
res: HRESULT;
bool_res: WordBool;
Status : esriLicenseStatus;
MapControl : TMapControl; // esriControls_TLB
begin
// basics for this code found here: http://forums.arcgis.com/threads/26206-ArcGIS-10-Delphi-and-licensing?p=146531#post146531
FverManager := TVersionManager.Create(nil);
FiagVersion := FverManager.DefaultInterface as IArcGISVersion;
res := FiagVersion.LoadVersion(ArcGISVersionLib_TLB.esriArcGISEngine,'10.1',bool_res);
if (res <> S_OK) then
begin
comObj.OleError(res);
end;
if (not bool_res) then
begin
raise Exception.Create('ArcGisEngine 10.1 is not available');
end;
FiaoInit := CoAoInitialize.Create as IAoInitialize;
status := FiaoInit.IsProductCodeAvailable(esriSystem_TLB.esriLicenseProductCodeEngineGeoDB);
if (status <> esriSystem_TLB.esriLicenseAvailable) then
begin
raise Exception.Create('license not available');
end
else
begin
status := FiaoInit.Initialize(esriSystem_TLB.esriLicenseProductCodeEngine);
if (status <> esriSystem_TLB.esriLicenseCheckedOut) then
begin
raise Exception.Create('initialization failed');
end;
end;
end;
destructor TEsriHelper.Destroy;
begin
FVerManager.Free;
inherited;
end;
Issues/Questions:The if statement to check the ComponentState is commented out. The ComponentState, even at design mode when the control is dropped on the form, is showing as blank, so the if statement would prevent the license from being acquired. I don't have a work around for this yet, but will continue to work it. Dropping the TMapControl component on the form the first time will cause a few second delay while the license is acquired.I'm not sure if I need to release the license when the component is destroyed - still learning my way around the ESRI components.I'm not sure if a Delphi plug-in/expert would get the same thing done, I may look into that later.If anyone else is having this problem, hopefully this solution will work for you. If you have any suggestions or notice any glaring problems, please let me know. I will update again later once I have the code a little nicer. For now, I just wanted to post this as I was finally able to get TMapControl to show up at design time. Cheers,Leo