Solved

Making last record new record???

Posted on 2000-03-19
8
134 Views
Last Modified: 2010-04-04
Hi all,

After saving a record to a table, I want to make the values saved the defaults of a new (yet to be posted) record and have those values displayed in the data-aware components?

Any ideas?

Thanx, fats
0
Comment
Question by:ffelaar
8 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 2633082
hi ffelaar,

from my paq, a bit modified



                   a sample (table1 = Workingtable, table2 = get last values)

                         procedure TForm1.Button1Click(Sender: TObject);
                         var i : Integer;
                         begin
                           table2.last;
                           table1.Append;
                           for i := 0 to table2.FieldCount - 1 do
                             table1.Fields[i].Assign(table2.Fields[i]);
                           //table1.post; //do not post yet, maybe the user want to modify
                         end;
remark table1 and table2 can pointed to the same table or to two tables with same structure,

meikl
0
 

Expert Comment

by:binho
ID: 2633094
ffelaar:
I use to do that by 2 ways:
1. If the number of columns is not that big (about 10), I use Delphi variables (var) to keep the values BEFORE posting the first record. Then, after I call the Post method and the Insert (to insert the new record), I set the new record fields using the values stored in the variables.

2. In the AfterInsert of the TTable or TQuery, use a auxiliary TQuery to search for the last posted record (if you have a Primary key created with a sequence, use the SQL:
SELECT * FROM TABLE_NAME
WHERE KEY_FIELD IN
(SELECT MAX(KEY_FIELD
 FROM TABLE_NAME)

After getting the last record, set the new fields by
Query1.FieldByName('FIELD1').AsType := QueryAux.FieldByName('FIELD1).AsType;
Query1.FieldByName('FIELD2').AsType := QueryAux.FieldByName('FIELD2).AsType;

and so on...

Fabio
0
 
LVL 9

Expert Comment

by:ITugay
ID: 2633179
to kretzschmar.
Sorry all for disturbing, but it's one way to access Meikl.

Meikl, something wrong with your e-mail, I get a message:
-------------
"The message that you sent was undeliverable to the following:
        meikl@abcdef.de (access denied)"
-------------
where abcdef = your host. Do I need to try agan it later or may be you have another e-mail?

0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 2633317
to igor,
didn't know, where this come from (abcdef)

my eMail is
meikl@spektracom.de

meikl
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 9

Expert Comment

by:ITugay
ID: 2633329
to meikl,
I get it again:
----
The message that you sent was undeliverable to the following:
        meikl@spektracom.de (access denied)
-----

Ok, i will consult with me sysadmin, it look like we get troubles.

By Igor.
0
 
LVL 2

Accepted Solution

by:
kubeerja earned 75 total points
ID: 2633477

-Before post save the values of the last record Inserted.
-On new record read the field values.

try this code :

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ExtCtrls, DBCtrls, Db, StdCtrls, Mask, DBTables;

type
  TForm1 = class(TForm)
    Table1: TTable;
    Label1: TLabel;
    DBEdit1: TDBEdit;
    DataSource1: TDataSource;
    Label2: TLabel;
    DBEdit2: TDBEdit;
    Label3: TLabel;
    DBEdit3: TDBEdit;
    Label4: TLabel;
    DBEdit4: TDBEdit;
    Label5: TLabel;
    DBEdit5: TDBEdit;
    Label6: TLabel;
    DBEdit6: TDBEdit;
    DBNavigator1: TDBNavigator;
    procedure Table1NewRecord(DataSet: TDataSet);
    procedure Table1BeforePost(DataSet: TDataSet);
  private
    { Private declarations }
    LastRec:Variant ;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Table1NewRecord(DataSet: TDataSet);
var
 I:Integer ;
begin
  if VarIsArray(LastRec) then
    For I:=0 to DataSet.FieldCount-1 do
    begin
      DataSet.Fields[I].Value := LastRec[I] ;
    end;
end;

procedure TForm1.Table1BeforePost(DataSet: TDataSet);
var
 I:Integer ;
begin
  if DataSet.State = dsInsert then
  begin
   if not VarIsArray(LastRec) then
    LastRec :=VarArrayCreate([0,DataSet.FieldCount], varVariant);
   For I:=0 to DataSet.FieldCount-1 do
   LastRec[I] :=  DataSet.Fields[I].Value;
  end ;
end;

end.
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 2633998
Listening
0
 

Author Comment

by:ffelaar
ID: 2683335
Well what can I say, exactly what I needed. I am sorry I took so long to respond ... I was kind of down and out wiht the flu ... but hey, better late than never hey

Thank you, thank you once again ...

fats
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now