?
Solved

Making last record new record???

Posted on 2000-03-19
8
Medium Priority
?
143 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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
 
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 300 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses

770 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