Subject Re: Getting the value of a generator
Author russellbelding
--- In IBObjects@yahoogroups.com, "Craig Cox" <Craig_Cox@...> wrote:
>
> (Firebird 1.5+, Delphi XE, IBOjects)
>
> I'm guessing there is a very simple answer to this problem.
>
> I want to get the current generator value of one table, increment it in Delphi and use the new value in another table. I thought the GeneratorValue() method looked promising, but I may not understand it well enough to use it properly. If you can tell me how to get the value of the generator, I think I can figure out the rest.
>
> Thanks
>


In one project I have mainDatamodule and in a unit I have this function:

function getGenValue(genName: string): integer;
begin
with mainDatamodule.ibdsqlWork do
begin
SQL.Text := 'select gen_id(' + genname + ',1) from RDB$DATABASE';
prepare;
Execute;
result := fields[0].asInteger;
end;
end;

The function can be used outside of any IBO component whereas GeneratorValue() is used only inside some IBO components. With this function and with GeneratorValue() you need to supply the name of the generator.

There are occassions where this function is used and the named generators called also are key value generators for tables. Helen's caution should be noted ...

Kind regards,
Russell