Hi,
I'm trying to use COFE from a Lazarus (Free Pascal) setup. I guess this will be quite a struggle, as the COM support of Lazarus has not been fully developed yet.
Nevertheless, using the automation documents you provided I've been able to initialize COFE. I even have been able to generate pascal source from the TLB file!
I'm now trying to load an existing flowsheet into the automation object. This should be done by something like GetObject("FileName.fsd").
Does this mean that I should create the COFE COM object directly from a file? Is there a way to directly load a file into an existing COFE Document (LoadFromstring obviously isn't meant for that, it provides me with a typing error)
Regards,
Henk
Using COFE from COM
Moderator: jasper
Re: Using COFE from COM
LoadFromString and SaveToString match each other; these strings are not file names, but string-encoded (b64) versions of the fsd file content. You should not call LoadFromString on documents that have any content in it:
http://cocosimulator.org/index_help.php ... FromString
Note that COFE is not exposed as just a COM object, but as OLE object; this implies that is requires an OLE site to interact with. The OLE machinery to start from an existing file therefore is supported; I suppose this is what GetObject does in Lazarus. Typically environments that support OLE also support document persistence.
http://cocosimulator.org/index_help.php ... FromString
Note that COFE is not exposed as just a COM object, but as OLE object; this implies that is requires an OLE site to interact with. The OLE machinery to start from an existing file therefore is supported; I suppose this is what GetObject does in Lazarus. Typically environments that support OLE also support document persistence.
Re: Using COFE from COM
Hi Jasper,
Thanks for your
I've looked at the OLE implementation within Lazarus and Delphi. With Delphi it's just OK to either create an empty server instance, or create one via an existing document.
Lazarus lacks that support. The server instance is created, and I can e.g. call ValidateFlowsheet, which indeed tells me the flowsheet is empty. But... no way to load and use an existing flowsheet...
Maybe I can create a workaround via Excel : Creating and generating an Excel instance works fine within Lazarus. As the Excel instance offers a way to open and use a worksheetfile.
But... would it also be possible to add a LoadFromFile option to the COFE OLE server?
Below a snippet of code capable of creating a COFE server instance. (late binding).
regards, Henk
Thanks for your
I've looked at the OLE implementation within Lazarus and Delphi. With Delphi it's just OK to either create an empty server instance, or create one via an existing document.
Lazarus lacks that support. The server instance is created, and I can e.g. call ValidateFlowsheet, which indeed tells me the flowsheet is empty. But... no way to load and use an existing flowsheet...
Maybe I can create a workaround via Excel : Creating and generating an Excel instance works fine within Lazarus. As the Excel instance offers a way to open and use a worksheetfile.
But... would it also be possible to add a LoadFromFile option to the COFE OLE server?
Below a snippet of code capable of creating a COFE server instance. (late binding).
Code: Select all
procedure TMain.OpenFlowsheetClick(Sender: TObject);
const
COFEServerName = 'COCO_COFE.Document';
var
Server : Variant;
var
FileName : Variant;
Count : Integer;
Messages : Variant;
begin
try
FileName := 'c:\warmtepomp.rg.h2o.3.1.fsd';
Server := GetActiveOleObject(COFEServer);
except
try
// no active server available, create a new one
Server := CreateOleObject(COFEServerName);
except
ShowMessage('Unable to start '+COFEServerName+'.');
end;
Server.ValidateFlowsheet(Messages);
ShowMessage(VarToStr(Messages[0]));
end;
end;
Re: Using COFE from COM
Not willing to break binary compatibility on the existing interface for that, nor willing to define a new interface for that. Instead, use LoadFromString, and pass "http:///" followed by the file name. Update available via CUP.
Re: Using COFE from COM
Wow Jasper, thanks man!
Sure you shouldn't break the compatibility. Lazarus hasn't been fully matured regarding COM/OLE implementation (it's cross platform, and OLE is a Windows thing), but this will surely help me out.
Recalling the usage: after creating the object I could then use something like Server.LoadFromeString('http:///c:/warmtepomp.rg.h2o.3.1.fsd'); to load an existing flowsheet?
Regards,
Henk

Sure you shouldn't break the compatibility. Lazarus hasn't been fully matured regarding COM/OLE implementation (it's cross platform, and OLE is a Windows thing), but this will surely help me out.
Recalling the usage: after creating the object I could then use something like Server.LoadFromeString('http:///c:/warmtepomp.rg.h2o.3.1.fsd'); to load an existing flowsheet?
Regards,
Henk
Re: Using COFE from COM
Got it! Figured out by your update notes. Entering 'file:///' instead of 'http:///', and now it's running!

Thnx



Thnx
Re: Using COFE from COM
Sorry - typing error. Glad to hear it works.