Page Index Toggle Pages: 1 Send TopicPrint
Hot Topic (More than 10 Replies) FlowChartX dynamic creation with Delphi (Read 6880 times)
Fred P.
Guest


FlowChartX dynamic creation with Delphi
Jul 25th, 2006 at 11:10am
Print Post  
Hello,

I'm trying to dynamically create instances of FlowChartX on a Delphi 5 program.

If I simple use the TFlowChart.Create method, I get a license error message (on computer where the program & dll are deployed) because the control runtime key has not been specified.

I certainly need to use API calls.
Actually, it seems it can get an IFlowChart interface instance with the code below,
but I do not know how to convert it to a regular TFlowChart object...

Does anyone have managed to create dynamical instances of FlowChartX in Delphi?

???

Thank you for your help.


uses
FLOWCHARTLib_TLB,
ActiveX,
Ole2,
olectl,
....


function CreateLicensed :IFlowChart;
var
  fc :IFlowChart ;
  key :String;
  icf : IClassFactory2;

begin
  key := '<put license key here>';

  icf := nil;
  fc := nil;
  if (S_OK = CoGetClassObject(OLE2.TGUID(Class_FlowChart),
                  CLSCTX_ALL, 0,
                  OLE2.TGUID(IID_IClassFactory2),
                  icf)) then
  begin

    icf.CreateInstanceLic(nil, nil,
                         OLE2.TGUID(IID_IFlowChart),
                         StringToOleStr(key), fc);
  end;
  Result := fc;
end;

  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3176
Joined: Oct 19th, 2005
Re: FlowChartX dynamic creation with Delphi
Reply #1 - Jul 25th, 2006 at 11:21am
Print Post  
Hi,

If Delphi has some concept similar to the VB user controls, you might create a user control that hosts FlowChartX and create instances of the user control instead directly of FlowChartX. Add one property to the user control that returns the TFlowChart. If you proceed like this, Delphi should take care of embedding the runtime key into the user control and passing it to FlowChartX when needed.

HTH
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3176
Joined: Oct 19th, 2005
Re: FlowChartX dynamic creation with Delphi
Reply #2 - Jul 25th, 2006 at 11:37am
Print Post  
If you have the source code of the TFlowChart wrapper class, try finding where CreateInstance is called and replace it with CreateInstanceLic(... key ...)
  
Back to top
 
IP Logged
 
jp
Guest


Re: FlowChartX dynamic creation with Delphi
Reply #3 - Jul 25th, 2006 at 11:51am
Print Post  
We have the same problem and the source code.
We don't find CreateInstance in the TLB file.
Is there an another soluce where we don't need a user control that hosts FlowchartX ?
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3176
Joined: Oct 19th, 2005
Re: FlowChartX dynamic creation with Delphi
Reply #4 - Jul 25th, 2006 at 12:09pm
Print Post  
By TLB do you mean the FlowchartX type library file?

I meant the TFlowChart wrapper class, in a TFlowChart.pas or some similar file generated by Delphi, should use a CreateInstance call to get an IFlowChart pointer to the new flowchart. If you replace that part of TFlowChart with the code Fred posted above, TFlowChart.Create should work fine.
  
Back to top
 
IP Logged
 
Fred P.
Guest


Re: FlowChartX dynamic creation with Delphi
Reply #5 - Jul 25th, 2006 at 12:19pm
Print Post  
Thank you glavcho,

Of course this trick works
(
1- using the Delphi IDE I've drawn a Frame where I put the TFlowChart control;
2- this Frame can in turn be instanciated dynamically...
3- ...and the hosted TFlowChart can then be reused elsewhere).
Wink

The problem is that I wrote my own class which derives from TFlowChart,
but this class is not a Delphi component itself (i.e. it can not be used as it in the Delphi IDE).

So with the trick proposed, I MUST transform each class derived from TFlowChart into a new component and create a specific Frame to host it :
I find the whole process a bit annoying,
Cry
so I am seeking any other way to do it...

  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3176
Joined: Oct 19th, 2005
Re: FlowChartX dynamic creation with Delphi
Reply #6 - Jul 25th, 2006 at 2:27pm
Print Post  
Can't you derive from the Frame component that hosts the flowchart Grin ? And what's there in the TFlowChart.Create method ? I can install an old Delphi copy here and play with that, but not before we release the new FlowChart.NET version in a couple of days because we're quite busy with it...
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3176
Joined: Oct 19th, 2005
Re: FlowChartX dynamic creation with Delphi
Reply #7 - Jul 25th, 2006 at 2:36pm
Print Post  
Oh, and if TFlowChart is a Delphi component, how the class that derives from it isn't?
  
Back to top
 
IP Logged
 
Fred_P.
YaBB Newbies
*
Offline



Posts: 5
Joined: Jul 25th, 2006
Re: FlowChartX dynamic creation with Delphi
Reply #8 - Jul 26th, 2006 at 5:57am
Print Post  
Hello,

glavcho :
1- Yes I can derive and extend the Frame, but of course not the Flowchart class embeded in it.
So it means that my object is now a Frame+FlowChart combo : I guess I can go on with that.


2- When I said the class I wrote is not a component, I mean it can not be used directly within the Delphi IDE in design mode to draw forms (it must be a bit extended to be registered in the IDE).
Embarrassed

I do not say that your solution doesn't work, but that I feel it is just a work around;
I thought it would be possible to simply create the licensed component itself!
but it's ok if there is no other way.
Undecided

Just for info, about the TLB file you mentionned earlier : it also contains the TFlowChart class and the connection with the ActiveX interfaces, but there is no CreateInstance in it (and no TFlowChart.Create method literally).
It's because it derives from a TOleControl Delphi Class; and I don't known now what I must/can add to the final class to create licensed component. But maybe it is here that we must dig...

thank you.
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3176
Joined: Oct 19th, 2005
Re: FlowChartX dynamic creation with Delphi
Reply #9 - Jul 26th, 2006 at 12:27pm
Print Post  
Don't you get the VCL source code with Delphi ? Try copying the Create method from TOleControl.pas to TFlowChart and there use the IOleClassFactory2->CreateInstanceLic method.
  
Back to top
 
IP Logged
 
Fred_P.
YaBB Newbies
*
Offline



Posts: 5
Joined: Jul 25th, 2006
Re: FlowChartX dynamic creation with Delphi
Reply #10 - Jul 27th, 2006 at 10:29am
Print Post  
Embarrassed I'm a fool I guess !!!!!!!!

After looking into the VCL source code, and not understanding why the dynamic instanciation was not working,
I did the test again and I found eventually that there is no problem : Delphi seems to correctly handles dynamic creation of licensed ActiveX.
???


The final explanation is simple : I was fooled by our first test program which was somehow compiled on a computer where the ActiveX was incorrectly installed!!! Angry


Glavcho, I am sorry about the time you may have lost on this "false" problem (and believe me, I more sorry about the time I lost myself).

thank you for your help anyway.
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3176
Joined: Oct 19th, 2005
Re: FlowChartX dynamic creation with Delphi
Reply #11 - Jul 27th, 2006 at 11:44am
Print Post  
Do you mean there's a Create method that takes a runtime key parameter, or the key is somehow embedded in the generated TFlowChart ? If not, the control might still load on your development PC because of the design-time registry license key, but refuse to load on clients PC where it is not installed for design-time use.
  
Back to top
 
IP Logged
 
Fred_P.
YaBB Newbies
*
Offline



Posts: 5
Joined: Jul 25th, 2006
Re: FlowChartX dynamic creation with Delphi
Reply #12 - Jul 27th, 2006 at 12:39pm
Print Post  
No, there is no Create method with a key parameter.
Yes, the license key is actually embedded in the TFlowChart (FLOWCHARTLib_TLB.pas unit) generated by Delphi when you import the ActiveX in the IDE.

Of course, this key is present on FLOWCHARTLib_TLB.pas only on computers where the ActiveX has been correctly installed;
Thus, programs compiled on computer with developper licence will work fine on deployement computers (provided that you've copied and registered the FlowChartPro.dll there)

On the other hand, on deployement computer (or if you uninstall the developper license), you can compile you program but it will raise an exception at runtime!!!!



  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3176
Joined: Oct 19th, 2005
Re: FlowChartX dynamic creation with Delphi
Reply #13 - Jul 27th, 2006 at 12:53pm
Print Post  
ok, that's good to know  Grin
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint