Hi Experts,
I'm facing a strange problem in OCX written in Delphi 6.
What I'm trying to do is to send a Jpeg image to the host as array of Variant.
When I time the following code, Graphic.SaveToStream(strmM
em) takes about 600 ms. Is there anything wrong in the way I'm code?
function TPCSTrioPRMV2.GraphicToVar
(Graphic: TGraphic): Variant;
var
strmMem : TMemoryStream;
lpMem : Pointer;
begin
strmMem := TMemoryStream.Create; // Create stream for persisting graphic
try // Resource protection
Graphic.SaveToStream(strmM
em); // Save graphic to stream
TVariantArg(result).vt:=VT
_UI1 or VT_ARRAY; // Set result vt type
TVariantArg(result).parray
:= SafeArrayCreateVector(VT_U
I1, 0, strmMem.Size); // Create safearray for result
lpMem:= VarArrayLock(result); // Lock the array
try // Resource protection
Move(strmMem.Memory^, lpMem^, strmMem.Size); // Move memory from the stream to the array
finally
VarArrayUnlock(result); // Unlock the array
end;
finally
strmMem.Free; // Free the stream
end;
end;
Start Free Trial