Re: TZF - Copy a record to virtual file - another help
Pierre Wittwer <[email protected]> Fri, 15 Aug 2003 11:25:26 +0200
| Newsgroups | gmane.comp.lang.delphi.topaz |
|---|---|
| Message-ID | <[email protected]> |
Hi
For your interest, I found in a email June 2002 from Ken Philipps this Procedure
Procedure AppendFromVfile(vfile: TtzVfile; Dbf: TTzDbf);
.
Very helpful and thanks to all of you for helping me.
Pierre Wittwer
---------------------------------------------------------------------------------------------
Ken Philipps :
Here's something I wrote a while back. It was originally made to copy
a single record from one dbf to another, but I adapted it for
appending records from a vfile to a dbf. Seems to work ok, but test
it to make sure.
Procedure AppendFromVfile(vfile: TtzVfile; Dbf: TTzDbf);
Var
x: integer;
FldName: string;
begin
vfile.GoTop;
while not vfile.dEOF do begin
Dbf.ClearRecord;
//Iterate through all fields of current record.
for x := 1 to vfile.FieldCount do begin
FldName := vfile.Field(x); //Get current field name.
case vfile.FieldType(x) of
'C' : Dbf.SetCField( FldName, vfile.GetCField(FldName) );
'N' : Dbf.SetLongField( FldName, vfile.GetLongField(FldName)
);
'L' : Dbf.SetLField( FldName, vfile.GetLField(FldName) );
'D' : Dbf.SetDField( FldName, vfile.GetDField(FldName) );
'F' : Dbf.SetRealField( FldName, vfile.GetRealField(FldName)
);
end;
end;
Dbf.AppendRec;
vfile.Skip(1);
end;
end;
----- Original Message -----
From: [email protected]
To: [email protected]
Sent: Thursday, August 14, 2003 10:01 PM
Subject: Re: TZF - Copy a record to virtual file
Thanks Phil - this solves an ongoing problem for
me also. It gets a lot simpler when someone
points you to the correct page in the book.
Bob
Pierre,
Look at the AssignUserPointer method.
You said that both databases have the same structure so you need to create only one type statement defining the structure of a Customer record. Then define two pointers one for the customer database (CustomerPtr) and one for the virtual database (VCustomerPtr). Use the AssignUserPtr method to initialize the pointer to their corresponding databases. Then VCustomerPtr^ := CustomerPtr^ should copy the record to the virtual databases record structure. Finally you need to do an append in the virtual database.
The code would look something like this:
type
Customer_Record = record
_Deleted : boolean;
First_Name : string[20];
Last_Name : string [20];
.
.
.
end;
var
CustomerPtr : ^Customer_Record;
VCustomerPtr : ^Customer_Record;
begin
Customer.AssignUserPtr (CustomerPtr);
VCustomer.AssignUserPtr (VCustomerPtr);
{ find the record to copy to the virtual database }
VCustomerPtr^ := CustomerPtr^;
VCustomer.Append;
Give this a try.
Phil Kidder
--^^---------------------------------------------------------------
This email was sent to: [email protected]
EASY UNSUBSCRIBE click here: http://topica.com/u/?clvXPN.clBgGE.cGF3QHRp
Or send an email to: [email protected]
TOPICA - Start your own email discussion group. FREE!
http://www.topica.com/partner/tag02/create/index2.html
--^^---------------------------------------------------------------
--^----------------------------------------------------------------
This email was sent to: [email protected]
EASY UNSUBSCRIBE click here: http://topica.com/u/?clvXPN.a5kvff.Z2NsZHQt
Or send an email to: [email protected]
TOPICA - Start your own email discussion group. FREE!
http://www.topica.com/partner/tag02/create/index2.html
--^----------------------------------------------------------------