Hi Sergei,
Doing what you propose isn't good. Checking for custom variant type is expensive because it involves locking, therefore custom variant handling should be done *after* the standard types.
Both committed in r17170, with some changes:

great thanks!

In fmtbcd.pp, I used VarDataFromStr method instead of assigning individual fields of TVarData; if I understand things correctly, this method exist precisely for such cases.
ok thanks,
I have attached minor "rearangement", consider them please


In variants.pp, I used an individual function, with an out-parameter of type AnsiString. Such approach allows to avoid finalization of the intermediate Variant.

ok, thank you very much

I have looked again at function FindCustomVariantType and I see there :

3590     Result:=(aVarType>=CMinVarType);
3591     if Result then

So it seems to me, that for standard variant types is control immediately 
returned, so no performance problem should exist there with entering critical 
section and so on.
Or I missed something ?

Laco.


procedure TFMTBcdFactory.CastTo(var Dest: TVarData; const Source: TVarData; 
const aVarType: TVarType);
var v: TVarData;
begin
  if Source.vType=VarType then
    if aVarType = varString then
      VarDataFromStr(Dest, BCDToStr(TFMTBcdVarData(Source.vPointer).BCD))
    else
    begin
      VarDataInit(v);
      try
        v.vType:=varDouble;
        v.vDouble:=BCDToDouble(TFMTBcdVarData(Source.vPointer).BCD);
        VarDataCastTo(Dest, v, aVarType); //now cast Double to any requested 
type
      finally
        VarDataClear(v);
      end;
    end
  else
    inherited;
end;
_______________________________________________
fpc-devel maillist  -  [email protected]
http://lists.freepascal.org/mailman/listinfo/fpc-devel

Reply via email to