Skip to content

Support assigning Variants and cross-typed interfaces to interface variables#305

Open
TetzkatLipHoka wants to merge 1 commit into
remobjects:masterfrom
TetzkatLipHoka:feature/variant-interface-casts
Open

Support assigning Variants and cross-typed interfaces to interface variables#305
TetzkatLipHoka wants to merge 1 commit into
remobjects:masterfrom
TetzkatLipHoka:feature/variant-interface-casts

Conversation

@TetzkatLipHoka

Copy link
Copy Markdown

Assigning a Variant that holds an interface reference to a script
variable of an interface type only worked when the destination was
exactly IDispatch; every other interface destination failed with a
plain 'Type Mismatch'. Assignments between differently declared
interface types blindly copied the reference without ever consulting
QueryInterface.

SetVariantValue's btInterface branch now:

  • accepts Variants holding varUnknown/varDispatch values (including
    by-ref variants) for ANY interface destination, casting via
    QueryInterface on the destination's GUID; empty/nil Variants assign
    nil. Destinations declared as IUnknown (or without a GUID) receive
    the reference as-is, preserving existing behaviour.
  • performs interface-to-interface assignments of differently declared
    types via QueryInterface as well; same-GUID (and nil) assignments
    stay plain reference copies.

Failed casts raise a descriptive, script-catchable error that names the
destination type (or its GUID when the type is unnamed) instead of the
generic type mismatch. Pre-Delphi3 builds keep their previous paths.

Note: the companion fix 'Make failing interface/object casts catchable'
covers the explicit cast-import path (CastProc); together they make all
interface conversion failures catchable with descriptive messages.

Note: the "failing cast is catchable" check of the included repro additionally needs the catchable-cast-errors PR; the two branches merge cleanly together.

🤖 Generated with Claude Code

…riables

Assigning a Variant that holds an interface reference to a script
variable of an interface type only worked when the destination was
exactly IDispatch; every other interface destination failed with a
plain 'Type Mismatch'. Assignments between differently declared
interface types blindly copied the reference without ever consulting
QueryInterface.

SetVariantValue's btInterface branch now:
- accepts Variants holding varUnknown/varDispatch values (including
  by-ref variants) for ANY interface destination, casting via
  QueryInterface on the destination's GUID; empty/nil Variants assign
  nil. Destinations declared as IUnknown (or without a GUID) receive
  the reference as-is, preserving existing behaviour.
- performs interface-to-interface assignments of differently declared
  types via QueryInterface as well; same-GUID (and nil) assignments
  stay plain reference copies.

Failed casts raise a descriptive, script-catchable error that names the
destination type (or its GUID when the type is unnamed) instead of the
generic type mismatch. Pre-Delphi3 builds keep their previous paths.

Note: the companion fix 'Make failing interface/object casts catchable'
covers the explicit cast-import path (CastProc); together they make all
interface conversion failures catchable with descriptive messages.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant