"shotokan99" <soft_devjava@[EMAIL PROTECTED]
> wrote in message
news:1140576538.076030.228620@[EMAIL PROTECTED]
> im working with delphi 4..using .dbf and .mdx files.. try to look at
> this code:
>
> procedure TTimeForm.sekTime(Sender: TObject;
> regin:string;regout:string;
> regin2:string;regout2:string);
> var
> //some var here..
> begin
> with dmod.ETIME do
> begin
> open;
>
> // if record is existing... no insertion will be done instead it
> will edit the
> // remaining field of the same record...
> if locate('idno;wdate',vararrayof([id,curdate.caption]),[]) then
> begin
> if fieldbyname('timeout').asstring='' then //time out ..1st
> begin
> //if timeout field is empty or null.. edit and place value
>
> end
> else if fieldbyname('timein2').asstring='' then //time in..2nd
> begin
> //if timein2 field is empty or null.. edit and place value
> end
> else if fieldbyname('timeout2').asstring='' then //time
> out..2nd
> begin
> //if timeout2 field is empty or null.. edit and place value
> end;
> end;
>
> //if record does not exist... it will insert a record.
> if not locate('idno;wdate',vararrayof([id,curdate.caption]),[]) then
> begin
> // insert idno, date...make new record here...
> end;
> close;
> end;
> end;
>
> ----------------------------
> im totally novice to delphi...for me this algo make sense. my
> problem..sometimes if the record is existing already, instead of doing
> some editing, it inserts new record.
There is no obvious problem, at least not obvious to me. However, I note
that a With statement encomp***** the statements. This is a big no no. Its
legal but can lead to all sorts of subtle problems. I'd suggest that you
eliminate the With.
Also, the logic should be something like
if Locate (. . .)
then begin
. . .
end
else begin
// insert the record
end;
It appears that you are using a string for the Locate key. Unless the data
is case sensitive you should probably include loCaseInsensitive in the
locate options. This may or may not contribute to your problem.
The date field in the locate is suspicious. First, is the field in the
table of type date? Second, is curDate.Caption a string or a date? If
either the date field or .Caption is of type string you may have a problem
with date formats.


|