[fpc-devel] RFC: customvariant handling in variants.pp and fmtbcd.pp
LacaK
lacak at zoznam.sk
Wed Mar 23 13:21:40 CET 2011
Hi,
I would like ask for your opinion in this case.
I found, that in this sample program is raised "Invalid variant ..."
var bcd1: TBCD;
v,v1: variant;
s: string;
begin
bcd1:=2;
v1:=varfmtbcdcreate(bcd1);
s:=v1; //assigment from customvariant to string is not handled in
sysvartolstr()
end;
I can fix it by following fixs:
1. fmtbcd_castto.diff ... added case when castto varString is requested
... then do not use cast throught varDouble (to avoid lost of
precision), but convert directly from TBCD to string
2. variants.pp ... here we must add handling of customvariants into
sysvartolstr ... I created "helper" function TryCastFromCustomVariant
which can be used multiple times (now in sysvartolstr and sysvartoreal)
... I isolate in this function code which is required multiple times.
I am not sure if
1. is this optimal approach, or is better to put same code repeatedly in
sysvartolstrm sysvartoreal and in future in others sysvarto... ?
2. is the name and place of such function good choosen ?
Can somebody look at it, and commit what is good and change what is not
good ;-) ?
Thanks
-Laco.
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: fmtbcd_castto.diff
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20110323/5bef927c/attachment.ksh>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: variants.diff
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20110323/5bef927c/attachment-0001.ksh>
More information about the fpc-devel
mailing list