Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Record always posted


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 4 - Last Post: Jan 10, 2016 11:15 PM Last Post By: Ertan Kucukoglu
Ertan Kucukoglu

Posts: 49
Registered: 7/4/09
Record always posted  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 8, 2016 3:02 PM
Hi,

I have below code which always posts even I see notification on screen during runtime. When I check in debug mode, I see that Post line is not run. Couldn't find what causes data to be post. Any help is appreciated.

function TCNoDogrula below have nothing to do with dataset.
No code for OnAsyncEnter/OnAsyncExit events of controls on form.

btnKaydet : TIWButton;
edtTCNo: TIWDBEdit;
 
procedure TfrmSporcu.btnKaydetClick(Sender: TObject);
begin
  if not UserSession.TCNoDogrula(Trim(edtTCNo.Text)) then begin
    edtTCNo.SetFocus;
    WebApplication.ShowNotification('TCNo Hatalı!');
  end else begin
    srcSporcu.DataSet.Post;
  end;
end;
Daniel Fields

Posts: 622
Registered: 11/29/04
Re: Record always posted  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 8, 2016 6:40 PM   in response to: Ertan Kucukoglu in response to: Ertan Kucukoglu
There are very few possible errors here.

1. The "if" clause is always false. That would mean something is wrong with TCNoDogrula.
2. btnKaydetClick is being called more than once. You can debug to fond out, and look at the CallStack to make sure nothing abnormal happens there
3. The datassource.AutoEdit property is true, and causing unintended actions.

I cannot think of anything other areas to check.
Ertan Kucukoglu

Posts: 49
Registered: 7/4/09
Re: Record always posted  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 9, 2016 1:41 PM   in response to: Daniel Fields in response to: Daniel Fields
Daniel Fields wrote:
There are very few possible errors here.

1. The "if" clause is always false. That would mean something is wrong with TCNoDogrula.
2. btnKaydetClick is being called more than once. You can debug to fond out, and look at the CallStack to make sure nothing abnormal happens there
3. The datassource.AutoEdit property is true, and causing unintended actions.

I cannot think of anything other areas to check.

Hi Daniel,
Thanks for your post. I know it seems easy to find, but I spend sometime pulling my remaining hair here.

1. I am using this function from some other units. It works as expected. "if" clause is not always false. I am sure of that.
2. I have a break point at the if statement line and running in debug mode. I don't see second stop in the IDE. However, I am not sure where and how to read CallStack. I will look that part again.
3. First thing I do is to disable that property when I drop a DataSource object on form as my personal code writing habit. I double checked, and AutoEdit is set to false.

Additional trials showed me that an error raised from database side, such as posting an empty field which cannot be null, and post command stops for sure. An error message displayed, but post stops.

If I solve that mystery, I will put here what caused it for future reference.
Daniel Fields

Posts: 622
Registered: 11/29/04
Re: Record always posted  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 10, 2016 1:43 PM   in response to: Ertan Kucukoglu in response to: Ertan Kucukoglu
The call stack is accessible in debug mode, View/Debug Windows/Call Stack. I would wrap the code in a try..except block to see if a deeper error is occurring.

procedure TfrmSporcu.btnKaydetClick(Sender: TObject);
begin
  try
    if not UserSession.TCNoDogrula(Trim(edtTCNo.Text)) then begin
      edtTCNo.SetFocus;
      WebApplication.ShowNotification('TCNo Hatalı!');
    end else begin
      srcSporcu.DataSet.Post;
    end;
  except
    on E : Exception do
       begin
         //put your error code here.  The actual error is in E.Message
       end;
  end;
end;
Ertan Kucukoglu

Posts: 49
Registered: 7/4/09
Re: Record always posted  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 10, 2016 11:15 PM   in response to: Daniel Fields in response to: Daniel Fields
I was making some try and see. I see that even below code causes a Post to be performed. I'm just stuck here. All lines are remarked. There is no code to execute, however, DataSet makes a Post for a reason I cannot find.

procedure TfrmSporcu.btnKaydetClick(Sender: TObject);
begin
//  UserSession.TCNoDogrula(Trim(edtTCNo.Text));
//    edtTCNo.SetFocus;
//    WebApplication.ShowNotification('TCNo Hatalı!', ntError);
end;
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02