Watch, Follow, &
Connect with Us

Please visit our new home
community.embarcadero.com.


Welcome, Guest
Guest Settings
Help

Thread: D10, MySQL, FireDAC



Permlink Replies: 4 - Last Post: Apr 23, 2018 12:42 PM Last Post By: Robert Triest
Jim Sawyer

Posts: 214
Registered: 1/3/10
D10, MySQL, FireDAC
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 22, 2018 6:10 PM
I have a table, 'Master' in which I keep the current value of the
primary key fields for several tables which use primary keys.
When I post a record to a table having a primary key I ask
the Master table to increment the key for that table and
give me the newly incremented value. The following routine
is intended to do that by providing the name of the field to
be incremented. However the line

FieldByName( Key ).AsInteger = Inc( nValue, 1 );

gives an error. Of course 'Key' is the name of the field.
How can I alter this code to make it work?

function GetKey( Key: String ): Integer;
var
  mQuery: TFDQuery;
  nValue: Integer;
begin
  mQuery := TFDQuery.Create( AConnection );
  with mQuery do
  begin
    Connection := AConnection;
    SQL.Add( 'Select * from Master' );
    Open;
    nValue := FieldByName( Key ).AsInteger;
    try
      Edit;
      FieldByName( Key ).AsInteger := Inc( nValue, 1 );
    finally
      Post;
      Result :=  FieldByName( Key ).AsInteger;
    end;
    Free;
  end;
end;


Thanks,
Jim Sawyer
Robert Triest

Posts: 687
Registered: 3/24/05
Re: D10, MySQL, FireDAC
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 23, 2018 12:01 AM   in response to: Jim Sawyer in response to: Jim Sawyer
gives an error.

What error?
Jim Sawyer

Posts: 214
Registered: 1/3/10
Re: D10, MySQL, FireDAC
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 23, 2018 6:27 AM   in response to: Robert Triest in response to: Robert Triest
[dcc64 Error] Wrapper.pas(1198): E2010 Incompatible types: 'Integer' and 'procedure, untyped pointer or untyped parameter'

Robert Triest wrote:
gives an error.

What error?
Jim Sawyer

Posts: 214
Registered: 1/3/10
Re: D10, MySQL, FireDAC
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 23, 2018 6:48 AM   in response to: Jim Sawyer in response to: Jim Sawyer
Although I'm not sure why, I find that the code

FieldByName( Key ).AsInteger := nValue + 1


works.

Jim Sawyer

Jim Sawyer wrote:
[dcc64 Error] Wrapper.pas(1198): E2010 Incompatible types: 'Integer' and 'procedure, untyped pointer or untyped parameter'

Robert Triest wrote:
gives an error.

What error?
Robert Triest

Posts: 687
Registered: 3/24/05
Re: D10, MySQL, FireDAC
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 23, 2018 12:42 PM   in response to: Jim Sawyer in response to: Jim Sawyer
Maybe somewhere you have declared another Inc procedure?

Maybe the "with mQuery do" is doing strange things with Inc?
(btw. I read better not use "with" syntax in Delphi anymore..)
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02