Subject Re: [IBO] Duplicating rows
Author Helen Borrie (TeamIBO)
At 02:00 PM 04-03-02 +0200, you wrote:
>Hi!
>
>I'm trying to use RowData for creating duplicate record (client selects
>old invoice and creates new one from that).
>Duplication works OK, but I encountered couple of problems:
>
>1. I'm using AfterInsert to fill in some fields (doc.no., statuses etc)
>and I also have generator for ID-s.
>This function is called before I set RowData values, so I have to set ID
>and DOCNO manualy afterward. This means, that
>my generator and document numbering systems loose one value. Can I disable
>generator and AfterInsert during duplication?

Riho-Rene,
This isn't clear enough.

Why do you have to set ID manually at all? Why not use GeneratorLinks for it?
Why are you losing any values in your generators? Do you have triggers
that are forcing new numbers into these fields? You need to make your
Before Insert trigger as

create trigger bi_aTable
active before insert position 0
as
begin
if (new.ID is null) then
new.ID = gen_id(aGenerator, 1);
end

If your trigger omits the null test, then you will get missing numbers.


>2. After duplication (query i still in Insert state) the new data whows ok
>on the grid, but TIB_Edit fields (etc.) are empty. They start showing
>values only when I click on them. Should I call some kind of method to get
>the values visible in Edit fields also?

What happens if you call the UpdateData method of the edit controls?

var
ii: integer;
..
..
with aForm do
for ii := 0 to ComponentCount -1 do
begin
if Components[ii] is TIB_CustomEdit and not(Components[ii] is
TIB_CustomGrid) then
if Datasource = aDatasource then
if Components[ii].Field.FieldName in (['FieldA', 'FieldB',
'FieldC']) then
TIB_CustomEdit(Components[ii]).UpdateData;
end;


regards,
Helen Borrie (TeamIBO Support)

** Please don't email your support questions privately **
Ask on the list and everyone benefits
Don't forget the IB Objects online FAQ - link from any page at
www.ibobjects.com