View Single Post
  #5  
Old 02-27-2017, 08:57 PM
Jung Jung is offline
Junior Member
 
Join Date: Oct 2014
Posts: 27
Default

Quote:
Originally Posted by rojam
A function MUST return a value.
Yes indeed.
Sorry I not entirely posted the call of the function which was like this:
Code:
If Not CheckDataType(Source.Fields[IdxSourceField],EmployeDest.Fields[IdxField]) Then
Begin
MessageDlg('Data field must be the same',mtError,[mbOk], 0);
 Abort;
end;
Sorry if I did not understand by what you mean by:
Quote:
Originally Posted by rojam
A function CANNOT have a path through it that does not return a valid value. Your function obviously has too many paths through it that leaves it returning nothing.
Anyway, here is the function code which I corrected and completed because it was in build when open the topic.
Code:
Function CheckDataType(FldSource,FldDest:TField):Boolean;
var
vl:string;
Bool:Boolean;
Year, Month, Day:Word;
v2,i:Integer;
dt:TDateTime;
sl:TstringList;
Begin

Result:=True;

If (FldDest.DataType=ftBoolean) Then
Begin
SL := TStringList.create;
SL.Add('TRUE');
SL.Add('FALSE');
SL.Add('VRAI');
SL.Add('FAUX');

vl:=FldSource.AsVariant;
vl:=AnsiUpperCase(vl);

for i := 0 to SL.Count - 1 do
 Begin
   If vl=SL.Strings[i] Then Bool:=True;
 end;

SL.Free;

If Not Bool Then
Begin
Result:=false;
Exit;
end;

Result:=Bool;
end;


If (FldDest.DataType=ftString) Then
Begin
vl:=FldSource.AsVariant;
vl:= VarToStr(vl);
end;

If (FldDest.DataType=ftInteger) Then
Begin
vl:=FldSource.AsVariant;
v2:= VarToInt(vl);
end;

If (FldDest.DataType=ftDate) Then
Begin

 if Not IsDate(FldSource.AsVariant) then
 Begin
 Result:=false;
 Exit;
 end;

decodedate(FldSource.AsDateTime,year,month,day);
If Not IsValidDate(year, month, day) Then
 Begin 
 Result:=false;
 Exit;
 end;

end;
end;
This is the first step and in the second step there is another function which is the same that the function above and when I do the data post.
Thanks and thanks to Norrit for advising me using VarToStr function.

Last edited by Jung; 02-27-2017 at 09:13 PM.
Reply With Quote