Seite 1 von 1

Type Any als ByRef

Verfasst: 13.05.2009 20:06
von mk-soft
War eine Frage irgendwo ob es ein Type Any in PB gibt. Hab mal eine Idee dazu :allright:

Code: Alles auswählen

;- Any Structure for pb syntax
Structure Any
  StructureUnion
    bVal.b
    wVal.w
    lVal.l
    qVal.q
    iVal.i
    fVal.f
    dVal.d
    *sVal
  EndStructureUnion
EndStructure

ProcedureDLL MyFunction(Type.c, *Arg.any)

  Select Type
    Case 'b'
      Debug "Byte: " + Str(*Arg\bVal)
    Case 'w'
      Debug "Word: " + Str(*Arg\wVal)
    Case 'l'
      Debug "Long: " + Str(*Arg\lVal)
    Case 'q'
      Debug "Quat: " + Str(*Arg\qVal)
    Case 'i'
      Debug "Integer: " + Str(*Arg\iVal)
    Case 'f'
      Debug "float: " + StrF(*Arg\fVal)
    Case 'd'
      Debug "Double: " + Str(*Arg\dVal)
    Case 's'
      Debug "String: " + PeekS(*Arg\sVal)
  EndSelect
EndProcedure

; test

Define.any value

value\lVal = 100
MyFunction('l', value)

value\sVal = @"Hallo Welt"
MyFunction('s', value)

value\fVal = 10.5
MyFunction('f', value)


Verfasst: 13.05.2009 20:22
von sibru
geile Idee...


SiBru

Verfasst: 13.05.2009 21:55
von cxAlex
VARIANT?

Verfasst: 13.05.2009 22:01
von mk-soft
Bekannt :mrgreen:

Code: Alles auswählen


; VariantHelper
;-T_BSTR
Procedure helpSysAllocString(*Value)
  ProcedureReturn SysAllocString_(*Value)
EndProcedure
Prototype.l ProtoSysAllocString(Value.p-unicode)

Global T_BSTR.ProtoSysAllocString = @helpSysAllocString()

ProcedureDLL MyFunction(*ArgData.variant)

  Select *Argdata\vt
    Case #VT_I2 ; signed word
      Debug "Word: " + Str(*ArgData\iVal)
      
    Case #VT_I4 ; signed long
      Debug "Word: " + Str(*ArgData\lVal)
    
    Case #VT_R4 ; signed long
      Debug "Float: " + StrF(*ArgData\fltVal)
    
    Case #VT_R8 ; signed long
      Debug "Double: " + StrD(*ArgData\dblVal)
      
    Case #VT_BSTR ; String (Unicode)
      Debug "String: " + PeekS(*ArgData\bstrVal, #PB_Any, #PB_Unicode)
      
  EndSelect

EndProcedure


; test
Define.Variant value

value\vt = #VT_I2
value\iVal = 100
MyFunction(value)

value\vt = #VT_I4
value\lVal = 444
MyFunction(value)

value\vt = #VT_R4
value\fltVal = 99.9
MyFunction(value)

value\vt = #VT_R8
value\dblVal = 88.1
MyFunction(value)

value\vt = #VT_BSTR
value\bstrVal = T_BSTR("Hallo Welt")
MyFunction(value)
VariantClear_(value)

P.S. Wer mehr mit Variant machen möchte.
VariantHelper_Include
Auch im COMate vorhanden.