Board index » delphi » TTable mystery - where am I?

TTable mystery - where am I?

Quote
Philip Cain wrote:

> This one is all about what mode you're in and what do we know about
> it.

> There is a table/datasource/grid combination.

> The table (MyTable) has three fields, call them Name, Count, and Base.

> Currently, the grid shows the following Name values (Count and Base
> don't matter here)

> Name
> a
> b
> c
> d
> e

> I navigate to the bottom of the grid and the indicator shows me
> changing from one record to another. Now, down at 'e' I press the down
> button to start and insert row and in the name column I put the value
> 'bb' and move to the count column where I put the value '1'.

> Now the fun starts. In the OnColExit event I check to see if the value
> is '1' and then I automatically set the Base column to the value
> 'Base'. (If the count is any other value, I let the user set it).

> So in the OnColExit event I say:
>         with MyTable do
>         if (MyTableNAME.Text = 1) and (MyTableBASE.Text <> 'Base') then
>         begin
>         Edit;
>         MyTableBASE := 'Base';
>         Post;
>         end;

> But it wasn't working. Turns out MyTableBASE was already set to base.
> That's because MyTableName turned out to be 'b'.

> So I have two questions and I'd be very grateful for answers to both
> if anyone has them.

> First, How did the currrent record get way up there at 'b'? Last I
> knew I was just below 'e'.

> Second, if this is not the way to set up a new value, what is?

> BTW, I'm using interbase through the BDE, if that makes a difference.

> TIA

> Phil Cain

When you enter data in a grid, and switch columns your don't change edit
modes.  You are calling Table.Edit while you are editing!
 

Re:TTable mystery - where am I?


"Timothy J. Kelly" <tj...@flash.net> wrote:

Quote
>When you enter data in a grid, and switch columns your don't change edit
>modes.  You are calling Table.Edit while you are editing!

I thank you for the response, but I don't know what it means.

That's because, when it comes to Delphi's dataset actions, I am
probably the most stupid programmer you have met. I don't get it. I've
never really gotten it. I wish I could get it.

For example, I would have thought I was in insert mode, not in edit
mode as you say. I mean, I'm on a grid line with a star indicator and
the BeforeInsert event fires before I move into it.

Anyhow, if you can help me figure out what I need to do in order to
accomplish what I need to accomplish, I would be very grateful and I
promise to take that knowledge back to the documentation and make
another earnest effort to understand Delphi datasets.

Thanks again.

Phil Cain

Re:TTable mystery - where am I?


from teh original post:

Now the fun starts. In the OnColExit event I check to see if the value
is '1' and then I automatically set the Base column to the value
'Base'. (If the count is any other value, I let the user set it).

So in the OnColExit event I say:
        with MyTable do
        if (MyTableNAME.Text = 1) and (MyTableBASE.Text <> 'Base') then
        begin
        Edit;
        MyTableBASE := 'Base';
        Post;
        end;

Since you are still in insert mode, just change the field value like
this:

(Assuming MyTableName and MyTableBase are DBEdits)

 if MyTable.FieldByName('Count').AsString:= '1' then
 begin
   MyTable.FieldByName('Base').AsString:= 'Base';
// When you leave the record it will do the Post.  If you want to you
can
// call MyTable.Post.
 end;

Other Threads