Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
swdev:howto:develop_com_components_and_automation [2009/10/06 10:55] smayr |
swdev:howto:develop_com_components_and_automation [2009/11/05 11:12] (current) smayr |
||
---|---|---|---|
Line 78: | Line 78: | ||
procedure TfrmClientMain.btnLaunchSvrClick(Sender: | procedure TfrmClientMain.btnLaunchSvrClick(Sender: | ||
begin | begin | ||
- | svr := CoMySvr.Create(); | + | |
+ | svr := CoMySvr.Create(); | ||
+ | end; | ||
if Assigned(svr) then begin | if Assigned(svr) then begin | ||
btnGetSvrVersion.Enabled := True; | btnGetSvrVersion.Enabled := True; | ||
Line 91: | Line 93: | ||
== Wrapping an Existing Application Functionality in an Automation Object == | == Wrapping an Existing Application Functionality in an Automation Object == | ||
+ | Especially use this method for Out-of-process automation servers: | ||
* Open an existing Delphi application project. | * Open an existing Delphi application project. | ||
* Select New > ActiveX > Automation Object. | * Select New > ActiveX > Automation Object. | ||
Line 98: | Line 101: | ||
* Select '' | * Select '' | ||
* Register the COM Server. | * Register the COM Server. | ||
- | * Select Run > Register ActiveX Server. | + | |
- | * Setup project to auto register server, to avoid littering the Windows Registry while developing. | + | |
- | * Select Project > Options > Linker > Auto register type library. | + | * Setup project to auto register server, to avoid littering the Windows Registry while developing. |
+ | * Select Project > Options > Linker > Auto register type library. | ||
+ | * Register from command line: < | ||
+ | * Out-of-process (EXE) automation server: | ||
+ | * To register, run this from command line: < | ||
+ | * To unregister, run this from command line: < | ||
== Linking Multiple Clients to a Single Instance of a COM Object == | == Linking Multiple Clients to a Single Instance of a COM Object == | ||
Line 186: | Line 194: | ||
// return | // return | ||
// | // | ||
- | procedure PrnSafearray(sfArr: | + | procedure PrnSafearray(sfArr: |
var | var | ||
- | LBound, | + | LBound, |
+ | sfArrData: pointer; | ||
+ | ElemData: integer; | ||
+ | i: integer; | ||
+ | str: string; | ||
begin | begin | ||
// get PSafeArray boundaries | // get PSafeArray boundaries | ||
SafeArrayGetLBound(sfArr, | SafeArrayGetLBound(sfArr, | ||
- | SafeArrayGetUBound(sfArr, | + | SafeArrayGetUBound(sfArr, |
- | + | ||
// read data from safearray | // read data from safearray | ||
+ | str := ''; | ||
+ | for i := LBound to UBound do begin | ||
if SafeArrayAccessData( sfArr, sfArrData ) = S_OK then begin | if SafeArrayAccessData( sfArr, sfArrData ) = S_OK then begin | ||
for i := LBound to UBound do begin | for i := LBound to UBound do begin | ||
- | format(' | + | |
+ | str := str + format(' | ||
end; | end; | ||
end; | end; | ||
SafeArrayUnAccessData(sfArr); | SafeArrayUnAccessData(sfArr); | ||
- | | + | |
end; | end; | ||
+ | |||
// | // | ||
- | // description: | + | // description: |
// parameters : sfArr: PSafeArray (assumed the array has been allocated already). | // parameters : sfArr: PSafeArray (assumed the array has been allocated already). | ||
// return | // return | ||
Line 211: | Line 227: | ||
procedure PrnSafearray(sfArr: | procedure PrnSafearray(sfArr: | ||
var | var | ||
- | LBound, | + | LBound, |
ElemData: integer; | ElemData: integer; | ||
+ | i: integer; | ||
+ | str: string; | ||
begin | begin | ||
// get PSafeArray boundaries | // get PSafeArray boundaries | ||
SafeArrayGetLBound(sfArr, | SafeArrayGetLBound(sfArr, | ||
- | SafeArrayGetUBound(sfArr, | + | SafeArrayGetUBound(sfArr, |
// read data from safearray | // read data from safearray | ||
+ | str := ''; | ||
for i := LBound to UBound do begin | for i := LBound to UBound do begin | ||
SafearrayGetElement(sfArr, | SafearrayGetElement(sfArr, | ||
- | format(' | + | |
end; | end; | ||
- | | + | |
end; | end; | ||
</ | </ | ||
Line 236: | Line 255: | ||
function SafeArrayToIntArr(sfArr: | function SafeArrayToIntArr(sfArr: | ||
var | var | ||
- | ArrayBounds: | ||
- | ArrayData: pointer; | ||
- | i: integer; | ||
LBound, UBound: integer; | LBound, UBound: integer; | ||
+ | sfArrData: pointer; | ||
+ | i: integer; | ||
Arr: TIntegerArray; | Arr: TIntegerArray; | ||
begin | begin | ||
Line 250: | Line 268: | ||
// copy data from safearray to integer array | // copy data from safearray to integer array | ||
- | if SafeArrayAccessData( sfArr, | + | if SafeArrayAccessData( sfArr, |
for i:= LBound to UBound do begin | for i:= LBound to UBound do begin | ||
- | | + | |
end; | end; | ||
SafeArrayUnAccessData(sfArr); | SafeArrayUnAccessData(sfArr); | ||
Line 270: | Line 288: | ||
procedure InitSafearrayTo99(var sfArr: PSafeArray); | procedure InitSafearrayTo99(var sfArr: PSafeArray); | ||
var | var | ||
- | LBound, | + | LBound, |
+ | sfArrData: pointer; | ||
begin | begin | ||
// get PSafeArray boundaries | // get PSafeArray boundaries | ||
SafeArrayGetLBound(sfArr, | SafeArrayGetLBound(sfArr, | ||
- | SafeArrayGetUBound(sfArr, | + | SafeArrayGetUBound(sfArr, |
// copy data to safearray | // copy data to safearray | ||
Line 295: | Line 314: | ||
LBound, HBound: integer; | LBound, HBound: integer; | ||
i: integer; | i: integer; | ||
+ | ElemData: integer; | ||
begin | begin | ||
- | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
- | // Fill safearray | ||
- | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
// get PSafeArray boundaries | // get PSafeArray boundaries | ||
SafeArrayGetLBound(sfArr, | SafeArrayGetLBound(sfArr, | ||
Line 304: | Line 321: | ||
// copy data to safearray | // copy data to safearray | ||
+ | ElemData := 99; | ||
for i := LBound to UBound do begin | for i := LBound to UBound do begin | ||
- | SafearrayPutElement(sfArr, | + | SafearrayPutElement(sfArr, |
end; | end; | ||
... | ... | ||
Line 343: | Line 361: | ||
* [[http:// | * [[http:// | ||
* [[http:// | * [[http:// | ||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | * [[http:// |