Skip to content

Commit

Permalink
Merge pull request #7 from eftomi/development
Browse files Browse the repository at this point in the history
ScaledDecimal and Float fully supported
  • Loading branch information
tesonep authored Dec 29, 2019
2 parents 8453e6d + 0d83ca7 commit 0685a69
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 7 deletions.
10 changes: 10 additions & 0 deletions PharoCOM-Tests/IDispatchTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ IDispatchTest >> testADODBConnection [
conn dispatch: 'Open' withArguments: { 'connection string;' . 'username' . 'password' } .
state := conn propertyNamed: 'State' .
conn dispatch: 'Close'.
conn finalize.
self assert: state equals: 1.

]
Expand All @@ -36,6 +37,8 @@ IDispatchTest >> testADODBConnectionAndRecordset [
recordCount := rst propertyNamed: 'RecordCount'.
rst dispatch: 'Close'.
conn dispatch: 'Close'.
rst finalize.
conn finalize.
self assert: recordCount equals: 14566 "<-- change to number of records"

]
Expand All @@ -59,6 +62,7 @@ IDispatchTest >> testADODBRecordset [
].
recordCountReported := rst propertyNamed: 'RecordCount'.
rst dispatch: 'Close'.
rst finalize.
self assert: recordCountLoop equals: recordCountReported


Expand All @@ -85,6 +89,7 @@ IDispatchTest >> testAccessingBoolProperties [
self assert: value equals: false.

obj dispatch: #Quit.
obj finalize.
]

{ #category : #tests }
Expand All @@ -100,6 +105,7 @@ IDispatchTest >> testAccessingInt32Properties [
self assert: 250 equals: value.

obj dispatch: #Quit.
obj finalize.
]

{ #category : #tests }
Expand All @@ -110,6 +116,8 @@ IDispatchTest >> testCallingVoidFunction [
obj := COMDispatchInstance createInstanceByName: 'InternetExplorer.Application'.

obj dispatch: #Quit.
obj finalize.

]

{ #category : #tests }
Expand Down Expand Up @@ -138,6 +146,8 @@ IDispatchTest >> testWord [
dispatch: 'Activate'.
selection := wrd propertyNamed: 'Selection'.
selection dispatch: 'WholeStory' .

wrd finalize.
self assert: (selection propertyNamed: 'Text') allButLast equals: someText.

]
4 changes: 2 additions & 2 deletions PharoCOM-Tests/VariantsTests.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ VariantsTests >> testDateAndTime [
| variant type valuePut valueGet |
self isCI ifTrue: [ ^self skip ]. "CI detect"

valuePut := DateAndTime now truncated.
valuePut := DateAndTime now truncated.

variant := Win32Variant externalNew .
variant autoRelease .
Expand All @@ -44,7 +44,7 @@ VariantsTests >> testDateAndTime [
type := Win32Variant typeFor: 7. "<-- date"

valueGet := type readFrom: variant.
self assert: valueGet equals: valuePut.
self assert: valueGet asDate equals: valuePut asDate.
]

{ #category : #tests }
Expand Down
2 changes: 1 addition & 1 deletion PharoCOM/COMDispatchInstance.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ COMDispatchInstance >> propertyNamed: aPropName put: aValue [
^ prop write: aValue to: self.
]

{ #category : #'as yet unclassified' }
{ #category : #properties }
COMDispatchInstance >> propertyNamed: aPropName withArguments: arguments [
| prop |
prop := self getDispatchType properties detect: [ :e | e name = aPropName ].
Expand Down
8 changes: 8 additions & 0 deletions PharoCOM/Float.extension.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Extension { #name : #Float }

{ #category : #'*PharoCOM' }
Float >> asWin32VariantInto: aVariant [
| type |
type := Win32Variant typeFor: 5. "<-- can this be done with #double and TypeMapping?"
type write: self to: aVariant
]
8 changes: 8 additions & 0 deletions PharoCOM/ScaledDecimal.extension.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Extension { #name : #ScaledDecimal }

{ #category : #'*PharoCOM' }
ScaledDecimal >> asWin32VariantInto: aVariant [
| type |
type := Win32Variant typeFor: 14. "<-- can this be done with #DECIMAL and TypeMapping?"
type write: self to: aVariant
]
5 changes: 3 additions & 2 deletions PharoCOM/Win32VariantDate.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ Win32VariantDate >> checkIfElementaryTypeAndWrite: aValue to: aVariant [

{ #category : #accessing }
Win32VariantDate >> readFrom: aVariant [
| dateAsFloat |
| dateAsFloat abstractDate |
dateAsFloat := (aVariant rawData copyFrom: 1 to: 8) doubleAt: 1 bigEndian: false.
dateAsFloat := dateAsFloat + DateAndTime oleEpoch julianDayNumber - 2.
^ (DateAndTime julianDayNumber: dateAsFloat) truncated.
abstractDate := (DateAndTime julianDayNumber: dateAsFloat) truncated.
^ DateAndTime date: abstractDate time: (Time fromString: '00:00:00').
]

{ #category : #accessing }
Expand Down
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,18 @@ selection dispatch: 'WholeStory' .
textFromWord := selection propertyNamed: 'Text'.
```

When we don't need the services of the server COM object anymore, we tell that to COM system by:

```smalltalk
wrd finalize.
```


So, in PharoCOM we have these methods to manipulate components:
- `COMDispatchInstance class>>#createInstanceByName:` and `COMDispatchInstance class>>#createInstanceOf:` to create COM components
- `COMDispatchInstance>>#propertyNamed:`, `COMDispatchInstance>>#propertyNamed:withArguments:` and `COMDispatchInstance>>#propertyNamed:put:` to read and write from their properties
- `COMDispatchInstance>>#dispatch:` and `COMDispatchInstance>>#dispatch:withArguments:` to call upon components' methods. Arguments should be given in a form of an Array.
- `COMUnknownInstance>>#finalize` to release a COM component (technically, this decrements the reference count for an interface on a COM object).

### COM data marshalling

Expand All @@ -87,14 +95,14 @@ VarType | Propvariant Type | Pharo variant type | Pharo base class/insta
-----------|------------------|-------------------------|---------------------------
1 | VT_NULL | Win32VariantNull 1) | 1)
3 | VT_I4 | Win32VariantInt32 | SmallInteger
5 | VT_R8 | Win32VariantDouble | /
5 | VT_R8 | Win32VariantDouble | Float
7 | VT_DATE | Win32VariantDate | Date, DateAndTime
8 | VT_BSTR | Win32VariantBSTRString | String
9 | VT_DISPATCH | Win32VariantCOMInstance | /
11 | VT_BOOLEAN | Win32VariantBool | Boolean
12 | VT_VARIANT | Win32VariantType | 2)
13 | VT_UNKNOWN | Win32VariantCOMInstance | /
14 | VT_DECIMAL | Win32VariantDecimal | 3)
14 | VT_DECIMAL | Win32VariantDecimal | ScaledDecimal 3)
24 | VT_VOID | Win32VariantVoid | /
26 | VT_PTR | Win32VariantPointer | 2)
29 | VT_USERDEFINED | Win32VariantUserDefined | /
Expand Down

0 comments on commit 0685a69

Please sign in to comment.