Bekkerus
asked on
Add data to a Tlist and compare with 2nd Tlist
Hello,
I have some data from a txt file that I am reading in and I want to add three fields to a Tlist. Lastname, firstname, Phonenumber. Now this data has thousands of names. In the text file there is dublicate info. What I need is to have unique rows. Do I need to have two list and compare them and remove the dublicate one? Then last I want to write the info to my DB, tblPerson a Paradox table. Can I do this by tlWD.Add (ln,fn,phone); ???
Thanks
Mark
I have some data from a txt file that I am reading in and I want to add three fields to a Tlist. Lastname, firstname, Phonenumber. Now this data has thousands of names. In the text file there is dublicate info. What I need is to have unique rows. Do I need to have two list and compare them and remove the dublicate one? Then last I want to write the info to my DB, tblPerson a Paradox table. Can I do this by tlWD.Add (ln,fn,phone); ???
Thanks
Mark
You could write the info directly to the table without using lists:
procedure TForm1.Append_Person(first name, lastname, phone: String);
var DoAppend: Boolean;
begin
with tblPerson do
begin
if not Locate('LastName', name, []) then
DoAppend := true
else
if (FieldByName('FirstName'). AsString <> firstname) then
DoAppend := true
else
DoAppend := false;
if DoAppend then
begin
Append;
FieldByName('FirstName').A sString := firstname;
FieldByName('LastName').As String := lastname;
FieldByName('Phone').AsStr ing := phone;
Post;
end;
end;
end;
Regards,
Epsylon.
procedure TForm1.Append_Person(first
var DoAppend: Boolean;
begin
with tblPerson do
begin
if not Locate('LastName', name, []) then
DoAppend := true
else
if (FieldByName('FirstName').
DoAppend := true
else
DoAppend := false;
if DoAppend then
begin
Append;
FieldByName('FirstName').A
FieldByName('LastName').As
FieldByName('Phone').AsStr
Post;
end;
end;
end;
Regards,
Epsylon.
ASKER
Epsylon,
I use fn, ln, ph as global variables because these are the values that I want to write into the talbe. If I use them in this private proceudre will it get the correct data? I get four errors Undeclared idetinfier 'Locate'. and Undeclared idnetifier 'Post'. When I try and call this procedure like this AppendPerson;
I get 'not enought actual parameters'. The last one I marked in the code.
procedure TfrmMain.AppendPerson(fn, ln, ph: String);
var
DoAppend: Boolean;
begin
with tblMgr.tblPerson do begin
if not Locate('Last_name', name, []) then
DoAppend := true
else
if (qryQry.FieldByName('First _name').As String <> fn) then
DoAppend := true
else
DoAppend := false;
end;
if DoAppend then begin
Append; //I also get an error here '(' expected but ';' found.
(qryQry.FieldByName('Last_ name').AsS tring := ln);
(qryQry.FieldByName('First _name').As String := fn);
(qryQry.FieldByName('Phone ').AsStrin g := ph);
Post;
end;
end;
end;
Regards,
Mark
I use fn, ln, ph as global variables because these are the values that I want to write into the talbe. If I use them in this private proceudre will it get the correct data? I get four errors Undeclared idetinfier 'Locate'. and Undeclared idnetifier 'Post'. When I try and call this procedure like this AppendPerson;
I get 'not enought actual parameters'. The last one I marked in the code.
procedure TfrmMain.AppendPerson(fn, ln, ph: String);
var
DoAppend: Boolean;
begin
with tblMgr.tblPerson do begin
if not Locate('Last_name', name, []) then
DoAppend := true
else
if (qryQry.FieldByName('First
DoAppend := true
else
DoAppend := false;
end;
if DoAppend then begin
Append; //I also get an error here '(' expected but ';' found.
(qryQry.FieldByName('Last_
(qryQry.FieldByName('First
(qryQry.FieldByName('Phone
Post;
end;
end;
end;
Regards,
Mark
ASKER
Epsylon,
I use fn, ln, ph as global variables because these are the values that I want to write into the talbe. If I use them in this private proceudre will it get the correct data? I get four errors Undeclared idetinfier 'Locate'. and Undeclared idnetifier 'Post'. When I try and call this procedure like this AppendPerson;
I get 'not enought actual parameters'. The last one I marked in the code.
procedure TfrmMain.AppendPerson(fn, ln, ph: String);
var
DoAppend: Boolean;
begin
with tblMgr.tblPerson do begin
if not Locate('Last_name', name, []) then
DoAppend := true
else
if (qryQry.FieldByName('First _name').As String <> fn) then
DoAppend := true
else
DoAppend := false;
end;
if DoAppend then begin
Append; //I also get an error here '(' expected but ';' found.
(qryQry.FieldByName('Last_ name').AsS tring := ln);
(qryQry.FieldByName('First _name').As String := fn);
(qryQry.FieldByName('Phone ').AsStrin g := ph);
Post;
end;
end;
end;
Regards,
Mark
I use fn, ln, ph as global variables because these are the values that I want to write into the talbe. If I use them in this private proceudre will it get the correct data? I get four errors Undeclared idetinfier 'Locate'. and Undeclared idnetifier 'Post'. When I try and call this procedure like this AppendPerson;
I get 'not enought actual parameters'. The last one I marked in the code.
procedure TfrmMain.AppendPerson(fn, ln, ph: String);
var
DoAppend: Boolean;
begin
with tblMgr.tblPerson do begin
if not Locate('Last_name', name, []) then
DoAppend := true
else
if (qryQry.FieldByName('First
DoAppend := true
else
DoAppend := false;
end;
if DoAppend then begin
Append; //I also get an error here '(' expected but ';' found.
(qryQry.FieldByName('Last_
(qryQry.FieldByName('First
(qryQry.FieldByName('Phone
Post;
end;
end;
end;
Regards,
Mark
ASKER
Ahh
Doe!!! I posted the same message twice.
Mark
Doe!!! I posted the same message twice.
Mark
You should not modify the function I gave you. The only thing you have to do is call the function like this:
AppendPerson(fn, ln, ph);
Next to that you need a TTable component on your form with the name tblPerson.
The line
with tblPerson do
refers to that table.
Well, Maybe it easier to use this:
procedure Append_Person(thetable: TTable; firstname, lastname, phone: String);
var DoAppend: Boolean;
begin
with thetable do
begin
if not Locate('LastName', name, []) then
DoAppend := true
else
if (FieldByName('FirstName'). AsString <> firstname) then
DoAppend := true
else
DoAppend := false;
if DoAppend then
begin
Append;
FieldByName('FirstName').A sString := firstname;
FieldByName('LastName').As String := lastname;
FieldByName('Phone').AsStr ing := phone;
Post;
end;
end;
end;
Now call it with AppendPerson(tblPerson, fn, ln, ph);
where tblPerson is a TTable.
Epsylon.
AppendPerson(fn, ln, ph);
Next to that you need a TTable component on your form with the name tblPerson.
The line
with tblPerson do
refers to that table.
Well, Maybe it easier to use this:
procedure Append_Person(thetable: TTable; firstname, lastname, phone: String);
var DoAppend: Boolean;
begin
with thetable do
begin
if not Locate('LastName', name, []) then
DoAppend := true
else
if (FieldByName('FirstName').
DoAppend := true
else
DoAppend := false;
if DoAppend then
begin
Append;
FieldByName('FirstName').A
FieldByName('LastName').As
FieldByName('Phone').AsStr
Post;
end;
end;
end;
Now call it with AppendPerson(tblPerson, fn, ln, ph);
where tblPerson is a TTable.
Epsylon.
ASKER
Epsylon,
Ok I changed it back to the way you gave it to me and I get more errors...
Undeclared identifier 'Locate'. and Undeclared identifier 'Post'.
procedure TfrmMain.AppendPerson(fn, ln, dist: String);
var
DoAppend: Boolean;
begin
with tblMgr.tblPhone do begin //I have tblPhone in described in tblMgr But I did try it with a TTable called tblPhone
if not Locate('Last_name', name, []) then //Undeclared identifier: 'Locate'.
DoAppend := true
else
if FieldByName('First_name'). AsString <> fn then //'THEN' expected but identifier 'AsString' found
DoAppend := true
else // I use this line of code alot in other programs
DoAppend := false; //qryQry.FieldByName(First _name').As DateTime);
if DoAppend then begin
Append; //'(' expected but ':' found.
FieldByName('Last_name').A sString := ln; //missing operator or semicolon
FieldByName('First_name'). AsString := fn; //missing operator or semicolon
FieldByName('Phone').AsStr ing := phone; //missing operator or semicolon
Post; //Undeclared identifier: 'Post'.
end;
end;
end;
Regards,
Mark
Ok I changed it back to the way you gave it to me and I get more errors...
Undeclared identifier 'Locate'. and Undeclared identifier 'Post'.
procedure TfrmMain.AppendPerson(fn, ln, dist: String);
var
DoAppend: Boolean;
begin
with tblMgr.tblPhone do begin //I have tblPhone in described in tblMgr But I did try it with a TTable called tblPhone
if not Locate('Last_name', name, []) then //Undeclared identifier: 'Locate'.
DoAppend := true
else
if FieldByName('First_name').
DoAppend := true
else // I use this line of code alot in other programs
DoAppend := false; //qryQry.FieldByName(First
if DoAppend then begin
Append; //'(' expected but ':' found.
FieldByName('Last_name').A
FieldByName('First_name').
FieldByName('Phone').AsStr
Post; //Undeclared identifier: 'Post'.
end;
end;
end;
Regards,
Mark
What Delphi version are you using and how did you set up your table? How is tblMgr.tblPhone defined?
ASKER
Epsylon,
I have delphi3. I have a unit called Comimp here it is in its' entirety:
unit ComImp;
interface
uses Windows, Classes, Dialogs, SysUtils, Messages, DB, DBTables,
Forms, dmImp;
// Define Types for tbl object statuses
type TtblState = (NewObject,ExistingObject) ;
type TtblStatus = (OK,Added,Modified,Deleted ,New);
type TCheckBoxState = (cbUnchecked,cbChecked);
// Define base object for tbl object
type TtblObj = class(TObject)
private
{ Private declarations }
fOID : Integer;
fState : TtblState;
fStatus : TtblStatus;
fSelected : Boolean;
public
{ Public declarations }
property OID : Integer read fOID write fOID;
property ObjState : TtblState read fState write fState;
property ObjStatus : TtblStatus read fStatus write fStatus;
property Selected : Boolean read fSelected write fSelected;
constructor create;
procedure Initialize;
end;
type TtblVolunteer = class(TtblObj)
Private
{ Private declarations }
fVolunteer_id : String;
fCall_number : String;
fLast_name : String;
fFirst_name : String;
fMiddle_name : String;
fName_suffix : String;
fDOB : String;
fHouse_number : String;
fStreet : String;
fStreet_suffix : String;
fDirection : String;
fApt_number : String;
fCity : String;
fState : String;
fZip : String;
fHome_phone : String;
fWork_phone : String;
fCell_phone : String;
fPager_number : String;
fDistrict : String;
fEntry_date : String;
fModify_date : String;
Public
{ Public declarations }
property Volunteer_id : String read fVolunteer_id write fVolunteer_id;
property Call_number : String read fCall_number write fCall_number;
property Last_name : String read fLast_name write fLast_name;
property First_name : String read fFirst_name write fFirst_name;
property Middle_name : String read fMiddle_name write fMiddle_name;
property Name_suffix : String read fName_suffix write fName_suffix;
property DOB : String read fDOB write fDOB;
property House_number : String read fHouse_number write fHouse_number;
property Street : String read fStreet write fStreet;
property Street_suffix : String read fStreet_suffix write fStreet_suffix;
property Direction : String read fDirection write fDirection;
property Apt_number : String read fApt_number write fApt_number;
property City : String read fCity write fCity;
property State : String read fState write fState;
property Zip : String read fZip write fZip;
property Home_phone : String read fHome_phone write fHome_phone;
property Work_phone : String read fWork_phone write fWork_phone;
property Cell_phone : String read fCell_phone write fCell_phone;
property Pager_number : String read fPager_number write fPager_number;
property District : String read fDistrict write fDistrict;
property Entry_date : String read fEntry_date write fEntry_date;
property Modify_date : String read fModify_date write fModify_date;
constructor create;
procedure Initialize;
end;
type TtblMgr = class(TObject)
Private
{ Private declarations }
fWhereClause : String;
ftblVolunteer : TList;
Public
{ Public declarations }
property WhereClause : String read fWhereClause write fWhereClause;
property tblvolunteer : TList read ftblvolunteer write ftblvolunteer;
procedure CleartblMgr;
procedure LoadtblvolunteerObj;
procedure SavetblvolunteerObj;
constructor Create;
destructor Destroy; override;
end;
var
GlobalOID : integer;
SortInActive : integer;
display : integer;
tblMgr : TtblMgr;
qryQry : TQuery;
tslCallNo, tslVolunteerName,
tslActivityNo, tslActivityName : TStringList;
//function GetR : Integer;
procedure InitApplication;
procedure CloseApplication;
implementation
{function GetR : Integer;
Var
i : integer;
begin
result := -1;
with dm do begin
qryQry.Sql.clear;
qryQry.Sql.Add ( 'SELECT Gen_no ');
qryQry.Sql.Add ( 'FROM tblNos ' );
qryQry.Sql.Add ( 'Where Id = ''Range'' ' );
qryQry.open;
end;
i := qryQry.FieldByName('Gen_no ').AsInteg er;
RVar:= i;
qryQry.close;
result := 1;
end; }
procedure InitApplication;
begin
tblMgr := TtblMgr.Create;
//Application.CreateForm(T DM, DM);
GlobalOID := 0;
//OrderType := 0;
//SortActive := 0;
//SortInActive := 0;
tslActivityName := tstringlist.Create;
tslActivityNo := tstringlist.create;
end;
procedure CloseApplication;
begin
tblMgr.CleartblMgr;
tblMgr.Destroy;
qryQry.Destroy;
//DM.Destroy;
tslActivityNo.Destroy;
tslActivityName.Destroy;
end;
constructor TtblObj.create;
begin
inherited create;
OID := 0;
end;
procedure TtblObj.Initialize;
begin
GlobalOID := GlobalOID + 1;
OID := GlobalOID;
Selected := False;
end;
constructor TtblMgr.create;
begin
inherited create;
tblVolunteer := TList.Create;
end;
destructor TtblMgr.Destroy;
begin
CleartblMgr;
tblVolunteer.Destroy;
inherited destroy;
end;
procedure TtblMgr.CleartblMgr;
var
x : integer;
begin
for x := tblVolunteer.Count -1 downto 0 do
tblVolunteer.Delete(x);
end;
constructor TtblVolunteer.create;
begin
inherited create;
Initialize;
end;
procedure Ttblvolunteer.Initialize;
begin
inherited Initialize;
Volunteer_id := '';
Call_number := '';
Last_name := '';
First_name := '';
Middle_name := '';
Name_suffix := '';
DOB := '';
House_number := '';
Street := '';
Street_suffix := '';
Direction := '';
Apt_number := '';
City := '';
State := '';
Zip := '';
Home_phone := '';
Work_phone := '';
Cell_phone := '';
Pager_number := '';
District := '';
Entry_date := '';
Modify_date := '';
ObjState := NewObject;
ObjStatus := New;
end;
procedure TtblMgr.LoadtblvolunteerOb j;
var
otblvolunteer : Ttblvolunteer;
begin
otblvolunteer := Nil;
qryQry.Sql.Clear;
qryQry.Sql.Add ( 'select Volunteer_id, Call_number, Last_name, First_name, ' );
qryQry.Sql.Add ( ' Middle_name, Name_suffix, DOB, ' );
qryQry.Sql.Add ( ' House_number, Street, Street_suffix, Direction, ' );
qryQry.Sql.Add ( ' Apt_number, City, State, Zip, Home_phone, ' );
qryQry.Sql.Add ( ' Work_phone, Cell_phone, Pager_number, District, ' );
qryQry.Sql.Add ( ' Entry_date, Modify_date ' );
qryQry.Sql.Add ( 'from tblvolunteer ' );
qryQry.Sql.Add ( WhereClause );
qryQry.Open;
qryQry.first;
while not qryQry.eof do begin
otblvolunteer := Ttblvolunteer.Create;
otblVolunteer.Volunteer_id := qryQry.FieldByName('Volunt eer_id').A sString;
otblVolunteer.Call_number := qryQry.FieldByName('Call_n umber').As String;
otblVolunteer.Last_name := qryQry.FieldByName('Last_n ame').AsSt ring;
otblVolunteer.First_name := qryQry.FieldByName('First_ name').AsS tring;
otblVolunteer.Middle_name := qryQry.FieldByName('Middle _name').As String;
otblVolunteer.Name_suffix := qryQry.FieldByName('Name_s uffix').As String;
otblVolunteer.DOB := qryQry.FieldByName('DOB'). AsString;
otblVolunteer.House_number := qryQry.FieldByName('House_ number').A sString;
otblVolunteer.Street := qryQry.FieldByName('Street ').AsStrin g;
otblVolunteer.Street_suffi x := qryQry.FieldByName('Street _suffix'). AsString;
otblVolunteer.Direction := qryQry.FieldByName('Direct ion').AsSt ring;
otblVolunteer.Apt_number := qryQry.FieldByName('Apt_nu mber').AsS tring;
otblVolunteer.City := qryQry.FieldByName('City') .AsString;
otblVolunteer.State := qryQry.FieldByName('State' ).AsString ;
otblVolunteer.Zip := qryQry.FieldByName('Zip'). AsString;
otblVolunteer.Home_phone := qryQry.FieldByName('Home_p hone').AsS tring;
otblVolunteer.Work_phone := qryQry.FieldByName('Work_p hone').AsS tring;
otblVolunteer.Cell_phone := qryQry.FieldByName('Cell_p hone').AsS tring;
otblVolunteer.Pager_number := qryQry.FieldByName('Pager_ number').A sString;
otblVolunteer.District := qryQry.FieldByName('Distri ct').AsStr ing;
otblVolunteer.Entry_date := qryQry.FieldByName('Entry_ date').AsS tring;
otblVolunteer.Modify_date := qryQry.FieldByName('Modify _date').As String;
otblVolunteer.ObjStatus := OK;
otblVolunteer.ObjState := ExistingObject;
tblvolunteer.Add ( otblvolunteer );
qryQry.Next;
end;
qryQry.Close;
end;
procedure TtblMgr.SavetblvolunteerOb j;
var
x : integer;
otblvolunteer : Ttblvolunteer;
begin
for x := 0 to tblvolunteer.Count - 1 do begin
if x >= tblvolunteer.Count then break;
otblvolunteer := tblvolunteer[x];
if otblvolunteer.ObjStatus = OK then continue;
tblMgr.WhereClause := 'where Volunteer_id = ''' + otblVolunteer.Volunteer_id + ''' ';
qryQry.Sql.Clear;
case otblvolunteer.ObjStatus of
Added,New: begin
qryQry.Sql.Add ( 'insert into tblVolunteer values ( ' );
if length(trim( otblVolunteer.Volunteer_id ) ) > 0 then
qryQry.Sql.Add ( '''' + otblVolunteer.Volunteer_id + ''', ' )
else
qryQry.Sql.Add ( 'null, ' );
if length(trim( otblVolunteer.Call_number ) ) > 0 then
qryQry.Sql.Add ( '''' + otblVolunteer.Call_number + ''', ' )
else
qryQry.Sql.Add ( 'null, ' );
if length(trim( otblVolunteer.Last_name ) ) > 0 then
qryQry.Sql.Add ( '''' + otblVolunteer.Last_name + ''', ' )
else
qryQry.Sql.Add ( 'null, ' );
if length(trim( otblVolunteer.First_name ) ) > 0 then
qryQry.Sql.Add ( '''' + otblVolunteer.First_name + ''', ' )
else
qryQry.Sql.Add ( 'null, ' );
if length(trim( otblVolunteer.Middle_name ) ) > 0 then
qryQry.Sql.Add ( '''' + otblVolunteer.Middle_name + ''', ' )
else
qryQry.Sql.Add ( 'null, ' );
if length(trim( otblVolunteer.Name_suffix ) ) > 0 then
qryQry.Sql.Add ( '''' + otblVolunteer.Name_suffix + ''', ' )
else
qryQry.Sql.Add ( 'null, ' );
if length(trim( otblVolunteer.DOB ) ) > 0 then
qryQry.Sql.Add ( '''' + otblVolunteer.DOB + ''', ' )
else
qryQry.Sql.Add ( 'null, ' );
if length(trim( otblVolunteer.House_number ) ) > 0 then
qryQry.Sql.Add ( '''' + otblVolunteer.House_number + ''', ' )
else
qryQry.Sql.Add ( 'null, ' );
if length(trim( otblVolunteer.Street ) ) > 0 then
qryQry.Sql.Add ( '''' + otblVolunteer.Street + ''', ' )
else
qryQry.Sql.Add ( 'null, ' );
if length(trim( otblVolunteer.Street_suffi x ) ) > 0 then
qryQry.Sql.Add ( '''' + otblVolunteer.Street_suffi x + ''', ' )
else
qryQry.Sql.Add ( 'null, ' );
if length(trim( otblVolunteer.Direction ) ) > 0 then
qryQry.Sql.Add ( '''' + otblVolunteer.Direction + ''', ' )
else
qryQry.Sql.Add ( 'null, ' );
if length(trim( otblVolunteer.Apt_number ) ) > 0 then
qryQry.Sql.Add ( '''' + otblVolunteer.Apt_number + ''', ' )
else
qryQry.Sql.Add ( 'null, ' );
if length(trim( otblVolunteer.City ) ) > 0 then
qryQry.Sql.Add ( '''' + otblVolunteer.City + ''', ' )
else
qryQry.Sql.Add ( 'null, ' );
if length(trim( otblVolunteer.State ) ) > 0 then
qryQry.Sql.Add ( '''' + otblVolunteer.State + ''', ' )
else
qryQry.Sql.Add ( 'null, ' );
if length(trim( otblVolunteer.Zip ) ) > 0 then
qryQry.Sql.Add ( '''' + otblVolunteer.Zip + ''', ' )
else
qryQry.Sql.Add ( 'null, ' );
if length(trim( otblVolunteer.Home_phone ) ) > 0 then
qryQry.Sql.Add ( '''' + otblVolunteer.Home_phone + ''', ' )
else
qryQry.Sql.Add ( 'null, ' );
if length(trim( otblVolunteer.Work_phone ) ) > 0 then
qryQry.Sql.Add ( '''' + otblVolunteer.Work_phone + ''', ' )
else
qryQry.Sql.Add ( 'null, ' );
if length(trim( otblVolunteer.Cell_phone ) ) > 0 then
qryQry.Sql.Add ( '''' + otblVolunteer.Cell_phone + ''', ' )
else
qryQry.Sql.Add ( 'null, ' );
if length(trim( otblVolunteer.Pager_number ) ) > 0 then
qryQry.Sql.Add ( '''' + otblVolunteer.Pager_number + ''', ' )
else
qryQry.Sql.Add ( 'null, ' );
if length(trim( otblVolunteer.District ) ) > 0 then
qryQry.Sql.Add ( '''' + otblVolunteer.District + ''', ' )
else
qryQry.Sql.Add ( 'null, ' );
if length(trim( otblVolunteer.Entry_date ) ) > 0 then
qryQry.Sql.Add ( '''' + otblVolunteer.Entry_date + ''', ' )
else
qryQry.Sql.Add ( 'null, ' );
if length(trim( otblVolunteer.Modify_date ) ) > 0 then
qryQry.Sql.Add ( '''' + otblVolunteer.Modify_date + ''' ) ' )
else
qryQry.Sql.Add ( 'null ) ' );
end;
Modified: begin
qryQry.Sql.Add ( 'update tblVolunteer set ' );
if length(trim( otblVolunteer.Volunteer_id ) ) > 0 then
qryQry.Sql.Add ( 'Volunteer_id = ''' + otblVolunteer.Volunteer_id + ''', ' )
else
qryQry.Sql.Add ( 'Volunteer_id = null, ' );
if length(trim( otblVolunteer.Call_number ) ) > 0 then
qryQry.Sql.Add ( 'Call_number = ''' + otblVolunteer.Call_number + ''', ' )
else
qryQry.Sql.Add ( 'Call_number = null, ' );
if length(trim( otblVolunteer.Last_name ) ) > 0 then
qryQry.Sql.Add ( 'Last_name = ''' + otblVolunteer.Last_name + ''', ' )
else
qryQry.Sql.Add ( 'Last_name = null, ' );
if length(trim( otblVolunteer.First_name ) ) > 0 then
qryQry.Sql.Add ( 'First_name = ''' + otblVolunteer.First_name + ''', ' )
else
qryQry.Sql.Add ( 'First_name = null, ' );
if length(trim( otblVolunteer.Middle_name ) ) > 0 then
qryQry.Sql.Add ( 'Middle_name = ''' + otblVolunteer.Middle_name + ''', ' )
else
qryQry.Sql.Add ( 'Middle_name = null, ' );
if length(trim( otblVolunteer.Name_suffix ) ) > 0 then
qryQry.Sql.Add ( 'Name_suffix = ''' + otblVolunteer.Name_suffix + ''', ' )
else
qryQry.Sql.Add ( 'Name_suffix = null, ' );
if length(trim( otblVolunteer.DOB ) ) > 0 then
qryQry.Sql.Add ( 'DOB = ''' + otblVolunteer.DOB + ''', ' )
else
qryQry.Sql.Add ( 'DOB = null, ' );
if length(trim( otblVolunteer.House_number ) ) > 0 then
qryQry.Sql.Add ( 'House_number = ''' + otblVolunteer.House_number + ''', ' )
else
qryQry.Sql.Add ( 'House_number = null, ' );
if length(trim( otblVolunteer.Street ) ) > 0 then
qryQry.Sql.Add ( 'Street = ''' + otblVolunteer.Street + ''', ' )
else
qryQry.Sql.Add ( 'Street = null, ' );
if length(trim( otblVolunteer.Street_suffi x ) ) > 0 then
qryQry.Sql.Add ( 'Street_suffix = ''' + otblVolunteer.Street_suffi x + ''', ' )
else
qryQry.Sql.Add ( 'Street_suffix = null, ' );
if length(trim( otblVolunteer.Direction ) ) > 0 then
qryQry.Sql.Add ( 'Direction = ''' + otblVolunteer.Direction + ''', ' )
else
qryQry.Sql.Add ( 'Direction = null, ' );
if length(trim( otblVolunteer.Apt_number ) ) > 0 then
qryQry.Sql.Add ( 'Apt_number = ''' + otblVolunteer.Apt_number + ''', ' )
else
qryQry.Sql.Add ( 'Apt_number = null, ' );
if length(trim( otblVolunteer.City ) ) > 0 then
qryQry.Sql.Add ( 'City = ''' + otblVolunteer.City + ''', ' )
else
qryQry.Sql.Add ( 'City = null, ' );
if length(trim( otblVolunteer.State ) ) > 0 then
qryQry.Sql.Add ( 'State = ''' + otblVolunteer.State + ''', ' )
else
qryQry.Sql.Add ( 'State = null, ' );
if length(trim( otblVolunteer.Zip ) ) > 0 then
qryQry.Sql.Add ( 'Zip = ''' + otblVolunteer.Zip + ''', ' )
else
qryQry.Sql.Add ( 'Zip = null, ' );
if length(trim( otblVolunteer.Home_phone ) ) > 0 then
qryQry.Sql.Add ( 'Home_phone = ''' + otblVolunteer.Home_phone + ''', ' )
else
qryQry.Sql.Add ( 'Home_phone = null, ' );
if length(trim( otblVolunteer.Work_phone ) ) > 0 then
qryQry.Sql.Add ( 'Work_phone = ''' + otblVolunteer.Work_phone + ''', ' )
else
qryQry.Sql.Add ( 'Work_phone = null, ' );
if length(trim( otblVolunteer.Cell_phone ) ) > 0 then
qryQry.Sql.Add ( 'Cell_phone = ''' + otblVolunteer.Cell_phone + ''', ' )
else
qryQry.Sql.Add ( 'Cell_phone = null, ' );
if length(trim( otblVolunteer.Pager_number ) ) > 0 then
qryQry.Sql.Add ( 'Pager_number = ''' + otblVolunteer.Pager_number + ''', ' )
else
qryQry.Sql.Add ( 'Pager_number = null, ' );
if length(trim( otblVolunteer.District ) ) > 0 then
qryQry.Sql.Add ( 'District = ''' + otblVolunteer.District + ''', ' )
else
qryQry.Sql.Add ( 'District = null, ' );
if length(trim( otblVolunteer.Entry_date ) ) > 0 then
qryQry.Sql.Add ( 'Entry_date = ''' + otblVolunteer.Entry_date + ''', ' )
else
qryQry.Sql.Add ( 'Entry_date = null, ' );
if length(trim( otblVolunteer.Modify_date ) ) > 0 then
qryQry.Sql.Add ( 'Modify_date = ''' + otblVolunteer.Modify_date + '''' )
else
qryQry.Sql.Add ( 'Modify_date = null ' );
qryQry.Sql.Add ( WhereClause );
end;
Deleted: begin
qryQry.Sql.Add ( 'delete from tblVolunteer ' );
qryQry.Sql.Add ( WhereClause );
end;
end;
try
//qryQry.SQL.SaveToFile('H :\Vol.sql' );
qryQry.ExecSql;
if otblvolunteer.ObjStatus <> Deleted then begin
Ttblvolunteer(tblvolunteer [x]).ObjSt ate := ExistingObject;
Ttblvolunteer(tblvolunteer [x]).ObjSt atus := OK;
end else
tblvolunteer.Delete(x);
qryQry.Close;
except
on e: Exception do begin
MessageDlg(e.Message, mtError, [mbOK],0);
qryQry.Close;
end;
end;
end;
end;
end.
If you have more questions please ask,
Mark
I have delphi3. I have a unit called Comimp here it is in its' entirety:
unit ComImp;
interface
uses Windows, Classes, Dialogs, SysUtils, Messages, DB, DBTables,
Forms, dmImp;
// Define Types for tbl object statuses
type TtblState = (NewObject,ExistingObject)
type TtblStatus = (OK,Added,Modified,Deleted
type TCheckBoxState = (cbUnchecked,cbChecked);
// Define base object for tbl object
type TtblObj = class(TObject)
private
{ Private declarations }
fOID : Integer;
fState : TtblState;
fStatus : TtblStatus;
fSelected : Boolean;
public
{ Public declarations }
property OID : Integer read fOID write fOID;
property ObjState : TtblState read fState write fState;
property ObjStatus : TtblStatus read fStatus write fStatus;
property Selected : Boolean read fSelected write fSelected;
constructor create;
procedure Initialize;
end;
type TtblVolunteer = class(TtblObj)
Private
{ Private declarations }
fVolunteer_id : String;
fCall_number : String;
fLast_name : String;
fFirst_name : String;
fMiddle_name : String;
fName_suffix : String;
fDOB : String;
fHouse_number : String;
fStreet : String;
fStreet_suffix : String;
fDirection : String;
fApt_number : String;
fCity : String;
fState : String;
fZip : String;
fHome_phone : String;
fWork_phone : String;
fCell_phone : String;
fPager_number : String;
fDistrict : String;
fEntry_date : String;
fModify_date : String;
Public
{ Public declarations }
property Volunteer_id : String read fVolunteer_id write fVolunteer_id;
property Call_number : String read fCall_number write fCall_number;
property Last_name : String read fLast_name write fLast_name;
property First_name : String read fFirst_name write fFirst_name;
property Middle_name : String read fMiddle_name write fMiddle_name;
property Name_suffix : String read fName_suffix write fName_suffix;
property DOB : String read fDOB write fDOB;
property House_number : String read fHouse_number write fHouse_number;
property Street : String read fStreet write fStreet;
property Street_suffix : String read fStreet_suffix write fStreet_suffix;
property Direction : String read fDirection write fDirection;
property Apt_number : String read fApt_number write fApt_number;
property City : String read fCity write fCity;
property State : String read fState write fState;
property Zip : String read fZip write fZip;
property Home_phone : String read fHome_phone write fHome_phone;
property Work_phone : String read fWork_phone write fWork_phone;
property Cell_phone : String read fCell_phone write fCell_phone;
property Pager_number : String read fPager_number write fPager_number;
property District : String read fDistrict write fDistrict;
property Entry_date : String read fEntry_date write fEntry_date;
property Modify_date : String read fModify_date write fModify_date;
constructor create;
procedure Initialize;
end;
type TtblMgr = class(TObject)
Private
{ Private declarations }
fWhereClause : String;
ftblVolunteer : TList;
Public
{ Public declarations }
property WhereClause : String read fWhereClause write fWhereClause;
property tblvolunteer : TList read ftblvolunteer write ftblvolunteer;
procedure CleartblMgr;
procedure LoadtblvolunteerObj;
procedure SavetblvolunteerObj;
constructor Create;
destructor Destroy; override;
end;
var
GlobalOID : integer;
SortInActive : integer;
display : integer;
tblMgr : TtblMgr;
qryQry : TQuery;
tslCallNo, tslVolunteerName,
tslActivityNo, tslActivityName : TStringList;
//function GetR : Integer;
procedure InitApplication;
procedure CloseApplication;
implementation
{function GetR : Integer;
Var
i : integer;
begin
result := -1;
with dm do begin
qryQry.Sql.clear;
qryQry.Sql.Add ( 'SELECT Gen_no ');
qryQry.Sql.Add ( 'FROM tblNos ' );
qryQry.Sql.Add ( 'Where Id = ''Range'' ' );
qryQry.open;
end;
i := qryQry.FieldByName('Gen_no
RVar:= i;
qryQry.close;
result := 1;
end; }
procedure InitApplication;
begin
tblMgr := TtblMgr.Create;
//Application.CreateForm(T
GlobalOID := 0;
//OrderType := 0;
//SortActive := 0;
//SortInActive := 0;
tslActivityName := tstringlist.Create;
tslActivityNo := tstringlist.create;
end;
procedure CloseApplication;
begin
tblMgr.CleartblMgr;
tblMgr.Destroy;
qryQry.Destroy;
//DM.Destroy;
tslActivityNo.Destroy;
tslActivityName.Destroy;
end;
constructor TtblObj.create;
begin
inherited create;
OID := 0;
end;
procedure TtblObj.Initialize;
begin
GlobalOID := GlobalOID + 1;
OID := GlobalOID;
Selected := False;
end;
constructor TtblMgr.create;
begin
inherited create;
tblVolunteer := TList.Create;
end;
destructor TtblMgr.Destroy;
begin
CleartblMgr;
tblVolunteer.Destroy;
inherited destroy;
end;
procedure TtblMgr.CleartblMgr;
var
x : integer;
begin
for x := tblVolunteer.Count -1 downto 0 do
tblVolunteer.Delete(x);
end;
constructor TtblVolunteer.create;
begin
inherited create;
Initialize;
end;
procedure Ttblvolunteer.Initialize;
begin
inherited Initialize;
Volunteer_id := '';
Call_number := '';
Last_name := '';
First_name := '';
Middle_name := '';
Name_suffix := '';
DOB := '';
House_number := '';
Street := '';
Street_suffix := '';
Direction := '';
Apt_number := '';
City := '';
State := '';
Zip := '';
Home_phone := '';
Work_phone := '';
Cell_phone := '';
Pager_number := '';
District := '';
Entry_date := '';
Modify_date := '';
ObjState := NewObject;
ObjStatus := New;
end;
procedure TtblMgr.LoadtblvolunteerOb
var
otblvolunteer : Ttblvolunteer;
begin
otblvolunteer := Nil;
qryQry.Sql.Clear;
qryQry.Sql.Add ( 'select Volunteer_id, Call_number, Last_name, First_name, ' );
qryQry.Sql.Add ( ' Middle_name, Name_suffix, DOB, ' );
qryQry.Sql.Add ( ' House_number, Street, Street_suffix, Direction, ' );
qryQry.Sql.Add ( ' Apt_number, City, State, Zip, Home_phone, ' );
qryQry.Sql.Add ( ' Work_phone, Cell_phone, Pager_number, District, ' );
qryQry.Sql.Add ( ' Entry_date, Modify_date ' );
qryQry.Sql.Add ( 'from tblvolunteer ' );
qryQry.Sql.Add ( WhereClause );
qryQry.Open;
qryQry.first;
while not qryQry.eof do begin
otblvolunteer := Ttblvolunteer.Create;
otblVolunteer.Volunteer_id
otblVolunteer.Call_number := qryQry.FieldByName('Call_n
otblVolunteer.Last_name := qryQry.FieldByName('Last_n
otblVolunteer.First_name := qryQry.FieldByName('First_
otblVolunteer.Middle_name := qryQry.FieldByName('Middle
otblVolunteer.Name_suffix := qryQry.FieldByName('Name_s
otblVolunteer.DOB := qryQry.FieldByName('DOB').
otblVolunteer.House_number
otblVolunteer.Street := qryQry.FieldByName('Street
otblVolunteer.Street_suffi
otblVolunteer.Direction := qryQry.FieldByName('Direct
otblVolunteer.Apt_number := qryQry.FieldByName('Apt_nu
otblVolunteer.City := qryQry.FieldByName('City')
otblVolunteer.State := qryQry.FieldByName('State'
otblVolunteer.Zip := qryQry.FieldByName('Zip').
otblVolunteer.Home_phone := qryQry.FieldByName('Home_p
otblVolunteer.Work_phone := qryQry.FieldByName('Work_p
otblVolunteer.Cell_phone := qryQry.FieldByName('Cell_p
otblVolunteer.Pager_number
otblVolunteer.District := qryQry.FieldByName('Distri
otblVolunteer.Entry_date := qryQry.FieldByName('Entry_
otblVolunteer.Modify_date := qryQry.FieldByName('Modify
otblVolunteer.ObjStatus := OK;
otblVolunteer.ObjState := ExistingObject;
tblvolunteer.Add ( otblvolunteer );
qryQry.Next;
end;
qryQry.Close;
end;
procedure TtblMgr.SavetblvolunteerOb
var
x : integer;
otblvolunteer : Ttblvolunteer;
begin
for x := 0 to tblvolunteer.Count - 1 do begin
if x >= tblvolunteer.Count then break;
otblvolunteer := tblvolunteer[x];
if otblvolunteer.ObjStatus = OK then continue;
tblMgr.WhereClause := 'where Volunteer_id = ''' + otblVolunteer.Volunteer_id
qryQry.Sql.Clear;
case otblvolunteer.ObjStatus of
Added,New: begin
qryQry.Sql.Add ( 'insert into tblVolunteer values ( ' );
if length(trim( otblVolunteer.Volunteer_id
qryQry.Sql.Add ( '''' + otblVolunteer.Volunteer_id
else
qryQry.Sql.Add ( 'null, ' );
if length(trim( otblVolunteer.Call_number ) ) > 0 then
qryQry.Sql.Add ( '''' + otblVolunteer.Call_number + ''', ' )
else
qryQry.Sql.Add ( 'null, ' );
if length(trim( otblVolunteer.Last_name ) ) > 0 then
qryQry.Sql.Add ( '''' + otblVolunteer.Last_name + ''', ' )
else
qryQry.Sql.Add ( 'null, ' );
if length(trim( otblVolunteer.First_name ) ) > 0 then
qryQry.Sql.Add ( '''' + otblVolunteer.First_name + ''', ' )
else
qryQry.Sql.Add ( 'null, ' );
if length(trim( otblVolunteer.Middle_name ) ) > 0 then
qryQry.Sql.Add ( '''' + otblVolunteer.Middle_name + ''', ' )
else
qryQry.Sql.Add ( 'null, ' );
if length(trim( otblVolunteer.Name_suffix ) ) > 0 then
qryQry.Sql.Add ( '''' + otblVolunteer.Name_suffix + ''', ' )
else
qryQry.Sql.Add ( 'null, ' );
if length(trim( otblVolunteer.DOB ) ) > 0 then
qryQry.Sql.Add ( '''' + otblVolunteer.DOB + ''', ' )
else
qryQry.Sql.Add ( 'null, ' );
if length(trim( otblVolunteer.House_number
qryQry.Sql.Add ( '''' + otblVolunteer.House_number
else
qryQry.Sql.Add ( 'null, ' );
if length(trim( otblVolunteer.Street ) ) > 0 then
qryQry.Sql.Add ( '''' + otblVolunteer.Street + ''', ' )
else
qryQry.Sql.Add ( 'null, ' );
if length(trim( otblVolunteer.Street_suffi
qryQry.Sql.Add ( '''' + otblVolunteer.Street_suffi
else
qryQry.Sql.Add ( 'null, ' );
if length(trim( otblVolunteer.Direction ) ) > 0 then
qryQry.Sql.Add ( '''' + otblVolunteer.Direction + ''', ' )
else
qryQry.Sql.Add ( 'null, ' );
if length(trim( otblVolunteer.Apt_number ) ) > 0 then
qryQry.Sql.Add ( '''' + otblVolunteer.Apt_number + ''', ' )
else
qryQry.Sql.Add ( 'null, ' );
if length(trim( otblVolunteer.City ) ) > 0 then
qryQry.Sql.Add ( '''' + otblVolunteer.City + ''', ' )
else
qryQry.Sql.Add ( 'null, ' );
if length(trim( otblVolunteer.State ) ) > 0 then
qryQry.Sql.Add ( '''' + otblVolunteer.State + ''', ' )
else
qryQry.Sql.Add ( 'null, ' );
if length(trim( otblVolunteer.Zip ) ) > 0 then
qryQry.Sql.Add ( '''' + otblVolunteer.Zip + ''', ' )
else
qryQry.Sql.Add ( 'null, ' );
if length(trim( otblVolunteer.Home_phone ) ) > 0 then
qryQry.Sql.Add ( '''' + otblVolunteer.Home_phone + ''', ' )
else
qryQry.Sql.Add ( 'null, ' );
if length(trim( otblVolunteer.Work_phone ) ) > 0 then
qryQry.Sql.Add ( '''' + otblVolunteer.Work_phone + ''', ' )
else
qryQry.Sql.Add ( 'null, ' );
if length(trim( otblVolunteer.Cell_phone ) ) > 0 then
qryQry.Sql.Add ( '''' + otblVolunteer.Cell_phone + ''', ' )
else
qryQry.Sql.Add ( 'null, ' );
if length(trim( otblVolunteer.Pager_number
qryQry.Sql.Add ( '''' + otblVolunteer.Pager_number
else
qryQry.Sql.Add ( 'null, ' );
if length(trim( otblVolunteer.District ) ) > 0 then
qryQry.Sql.Add ( '''' + otblVolunteer.District + ''', ' )
else
qryQry.Sql.Add ( 'null, ' );
if length(trim( otblVolunteer.Entry_date ) ) > 0 then
qryQry.Sql.Add ( '''' + otblVolunteer.Entry_date + ''', ' )
else
qryQry.Sql.Add ( 'null, ' );
if length(trim( otblVolunteer.Modify_date ) ) > 0 then
qryQry.Sql.Add ( '''' + otblVolunteer.Modify_date + ''' ) ' )
else
qryQry.Sql.Add ( 'null ) ' );
end;
Modified: begin
qryQry.Sql.Add ( 'update tblVolunteer set ' );
if length(trim( otblVolunteer.Volunteer_id
qryQry.Sql.Add ( 'Volunteer_id = ''' + otblVolunteer.Volunteer_id
else
qryQry.Sql.Add ( 'Volunteer_id = null, ' );
if length(trim( otblVolunteer.Call_number ) ) > 0 then
qryQry.Sql.Add ( 'Call_number = ''' + otblVolunteer.Call_number + ''', ' )
else
qryQry.Sql.Add ( 'Call_number = null, ' );
if length(trim( otblVolunteer.Last_name ) ) > 0 then
qryQry.Sql.Add ( 'Last_name = ''' + otblVolunteer.Last_name + ''', ' )
else
qryQry.Sql.Add ( 'Last_name = null, ' );
if length(trim( otblVolunteer.First_name ) ) > 0 then
qryQry.Sql.Add ( 'First_name = ''' + otblVolunteer.First_name + ''', ' )
else
qryQry.Sql.Add ( 'First_name = null, ' );
if length(trim( otblVolunteer.Middle_name ) ) > 0 then
qryQry.Sql.Add ( 'Middle_name = ''' + otblVolunteer.Middle_name + ''', ' )
else
qryQry.Sql.Add ( 'Middle_name = null, ' );
if length(trim( otblVolunteer.Name_suffix ) ) > 0 then
qryQry.Sql.Add ( 'Name_suffix = ''' + otblVolunteer.Name_suffix + ''', ' )
else
qryQry.Sql.Add ( 'Name_suffix = null, ' );
if length(trim( otblVolunteer.DOB ) ) > 0 then
qryQry.Sql.Add ( 'DOB = ''' + otblVolunteer.DOB + ''', ' )
else
qryQry.Sql.Add ( 'DOB = null, ' );
if length(trim( otblVolunteer.House_number
qryQry.Sql.Add ( 'House_number = ''' + otblVolunteer.House_number
else
qryQry.Sql.Add ( 'House_number = null, ' );
if length(trim( otblVolunteer.Street ) ) > 0 then
qryQry.Sql.Add ( 'Street = ''' + otblVolunteer.Street + ''', ' )
else
qryQry.Sql.Add ( 'Street = null, ' );
if length(trim( otblVolunteer.Street_suffi
qryQry.Sql.Add ( 'Street_suffix = ''' + otblVolunteer.Street_suffi
else
qryQry.Sql.Add ( 'Street_suffix = null, ' );
if length(trim( otblVolunteer.Direction ) ) > 0 then
qryQry.Sql.Add ( 'Direction = ''' + otblVolunteer.Direction + ''', ' )
else
qryQry.Sql.Add ( 'Direction = null, ' );
if length(trim( otblVolunteer.Apt_number ) ) > 0 then
qryQry.Sql.Add ( 'Apt_number = ''' + otblVolunteer.Apt_number + ''', ' )
else
qryQry.Sql.Add ( 'Apt_number = null, ' );
if length(trim( otblVolunteer.City ) ) > 0 then
qryQry.Sql.Add ( 'City = ''' + otblVolunteer.City + ''', ' )
else
qryQry.Sql.Add ( 'City = null, ' );
if length(trim( otblVolunteer.State ) ) > 0 then
qryQry.Sql.Add ( 'State = ''' + otblVolunteer.State + ''', ' )
else
qryQry.Sql.Add ( 'State = null, ' );
if length(trim( otblVolunteer.Zip ) ) > 0 then
qryQry.Sql.Add ( 'Zip = ''' + otblVolunteer.Zip + ''', ' )
else
qryQry.Sql.Add ( 'Zip = null, ' );
if length(trim( otblVolunteer.Home_phone ) ) > 0 then
qryQry.Sql.Add ( 'Home_phone = ''' + otblVolunteer.Home_phone + ''', ' )
else
qryQry.Sql.Add ( 'Home_phone = null, ' );
if length(trim( otblVolunteer.Work_phone ) ) > 0 then
qryQry.Sql.Add ( 'Work_phone = ''' + otblVolunteer.Work_phone + ''', ' )
else
qryQry.Sql.Add ( 'Work_phone = null, ' );
if length(trim( otblVolunteer.Cell_phone ) ) > 0 then
qryQry.Sql.Add ( 'Cell_phone = ''' + otblVolunteer.Cell_phone + ''', ' )
else
qryQry.Sql.Add ( 'Cell_phone = null, ' );
if length(trim( otblVolunteer.Pager_number
qryQry.Sql.Add ( 'Pager_number = ''' + otblVolunteer.Pager_number
else
qryQry.Sql.Add ( 'Pager_number = null, ' );
if length(trim( otblVolunteer.District ) ) > 0 then
qryQry.Sql.Add ( 'District = ''' + otblVolunteer.District + ''', ' )
else
qryQry.Sql.Add ( 'District = null, ' );
if length(trim( otblVolunteer.Entry_date ) ) > 0 then
qryQry.Sql.Add ( 'Entry_date = ''' + otblVolunteer.Entry_date + ''', ' )
else
qryQry.Sql.Add ( 'Entry_date = null, ' );
if length(trim( otblVolunteer.Modify_date ) ) > 0 then
qryQry.Sql.Add ( 'Modify_date = ''' + otblVolunteer.Modify_date + '''' )
else
qryQry.Sql.Add ( 'Modify_date = null ' );
qryQry.Sql.Add ( WhereClause );
end;
Deleted: begin
qryQry.Sql.Add ( 'delete from tblVolunteer ' );
qryQry.Sql.Add ( WhereClause );
end;
end;
try
//qryQry.SQL.SaveToFile('H
qryQry.ExecSql;
if otblvolunteer.ObjStatus <> Deleted then begin
Ttblvolunteer(tblvolunteer
Ttblvolunteer(tblvolunteer
end else
tblvolunteer.Delete(x);
qryQry.Close;
except
on e: Exception do begin
MessageDlg(e.Message, mtError, [mbOK],0);
qryQry.Close;
end;
end;
end;
end;
end.
If you have more questions please ask,
Mark
ASKER
Epsylon,
I have delphi3. I have a unit called Comimp here it is in its' entirety:
unit ComImp;
interface
uses Windows, Classes, Dialogs, SysUtils, Messages, DB, DBTables,
Forms, dmImp;
// Define Types for tbl object statuses
type TtblState = (NewObject,ExistingObject) ;
type TtblStatus = (OK,Added,Modified,Deleted ,New);
type TCheckBoxState = (cbUnchecked,cbChecked);
// Define base object for tbl object
type TtblObj = class(TObject)
private
{ Private declarations }
fOID : Integer;
fState : TtblState;
fStatus : TtblStatus;
fSelected : Boolean;
public
{ Public declarations }
property OID : Integer read fOID write fOID;
property ObjState : TtblState read fState write fState;
property ObjStatus : TtblStatus read fStatus write fStatus;
property Selected : Boolean read fSelected write fSelected;
constructor create;
procedure Initialize;
end;
type TtblVolunteer = class(TtblObj)
Private
{ Private declarations }
fVolunteer_id : String;
fCall_number : String;
fLast_name : String;
fFirst_name : String;
fMiddle_name : String;
fName_suffix : String;
fDOB : String;
fHouse_number : String;
fStreet : String;
fStreet_suffix : String;
fDirection : String;
fApt_number : String;
fCity : String;
fState : String;
fZip : String;
fHome_phone : String;
fWork_phone : String;
fCell_phone : String;
fPager_number : String;
fDistrict : String;
fEntry_date : String;
fModify_date : String;
Public
{ Public declarations }
property Volunteer_id : String read fVolunteer_id write fVolunteer_id;
property Call_number : String read fCall_number write fCall_number;
property Last_name : String read fLast_name write fLast_name;
property First_name : String read fFirst_name write fFirst_name;
property Middle_name : String read fMiddle_name write fMiddle_name;
property Name_suffix : String read fName_suffix write fName_suffix;
property DOB : String read fDOB write fDOB;
property House_number : String read fHouse_number write fHouse_number;
property Street : String read fStreet write fStreet;
property Street_suffix : String read fStreet_suffix write fStreet_suffix;
property Direction : String read fDirection write fDirection;
property Apt_number : String read fApt_number write fApt_number;
property City : String read fCity write fCity;
property State : String read fState write fState;
property Zip : String read fZip write fZip;
property Home_phone : String read fHome_phone write fHome_phone;
property Work_phone : String read fWork_phone write fWork_phone;
property Cell_phone : String read fCell_phone write fCell_phone;
property Pager_number : String read fPager_number write fPager_number;
property District : String read fDistrict write fDistrict;
property Entry_date : String read fEntry_date write fEntry_date;
property Modify_date : String read fModify_date write fModify_date;
constructor create;
procedure Initialize;
end;
type TtblMgr = class(TObject)
Private
{ Private declarations }
fWhereClause : String;
ftblVolunteer : TList;
Public
{ Public declarations }
property WhereClause : String read fWhereClause write fWhereClause;
property tblvolunteer : TList read ftblvolunteer write ftblvolunteer;
procedure CleartblMgr;
procedure LoadtblvolunteerObj;
procedure SavetblvolunteerObj;
constructor Create;
destructor Destroy; override;
end;
var
GlobalOID : integer;
SortInActive : integer;
display : integer;
tblMgr : TtblMgr;
qryQry : TQuery;
tslCallNo, tslVolunteerName,
tslActivityNo, tslActivityName : TStringList;
//function GetR : Integer;
procedure InitApplication;
procedure CloseApplication;
implementation
{function GetR : Integer;
Var
i : integer;
begin
result := -1;
with dm do begin
qryQry.Sql.clear;
qryQry.Sql.Add ( 'SELECT Gen_no ');
qryQry.Sql.Add ( 'FROM tblNos ' );
qryQry.Sql.Add ( 'Where Id = ''Range'' ' );
qryQry.open;
end;
i := qryQry.FieldByName('Gen_no ').AsInteg er;
RVar:= i;
qryQry.close;
result := 1;
end; }
procedure InitApplication;
begin
tblMgr := TtblMgr.Create;
//Application.CreateForm(T DM, DM);
GlobalOID := 0;
//OrderType := 0;
//SortActive := 0;
//SortInActive := 0;
tslActivityName := tstringlist.Create;
tslActivityNo := tstringlist.create;
end;
procedure CloseApplication;
begin
tblMgr.CleartblMgr;
tblMgr.Destroy;
qryQry.Destroy;
//DM.Destroy;
tslActivityNo.Destroy;
tslActivityName.Destroy;
end;
constructor TtblObj.create;
begin
inherited create;
OID := 0;
end;
procedure TtblObj.Initialize;
begin
GlobalOID := GlobalOID + 1;
OID := GlobalOID;
Selected := False;
end;
constructor TtblMgr.create;
begin
inherited create;
tblVolunteer := TList.Create;
end;
destructor TtblMgr.Destroy;
begin
CleartblMgr;
tblVolunteer.Destroy;
inherited destroy;
end;
procedure TtblMgr.CleartblMgr;
var
x : integer;
begin
for x := tblVolunteer.Count -1 downto 0 do
tblVolunteer.Delete(x);
end;
constructor TtblVolunteer.create;
begin
inherited create;
Initialize;
end;
procedure Ttblvolunteer.Initialize;
begin
inherited Initialize;
Volunteer_id := '';
Call_number := '';
Last_name := '';
First_name := '';
Middle_name := '';
Name_suffix := '';
DOB := '';
House_number := '';
Street := '';
Street_suffix := '';
Direction := '';
Apt_number := '';
City := '';
State := '';
Zip := '';
Home_phone := '';
Work_phone := '';
Cell_phone := '';
Pager_number := '';
District := '';
Entry_date := '';
Modify_date := '';
ObjState := NewObject;
ObjStatus := New;
end;
procedure TtblMgr.LoadtblvolunteerOb j;
var
otblvolunteer : Ttblvolunteer;
begin
otblvolunteer := Nil;
qryQry.Sql.Clear;
qryQry.Sql.Add ( 'select Volunteer_id, Call_number, Last_name, First_name, ' );
qryQry.Sql.Add ( ' Middle_name, Name_suffix, DOB, ' );
qryQry.Sql.Add ( ' House_number, Street, Street_suffix, Direction, ' );
qryQry.Sql.Add ( ' Apt_number, City, State, Zip, Home_phone, ' );
qryQry.Sql.Add ( ' Work_phone, Cell_phone, Pager_number, District, ' );
qryQry.Sql.Add ( ' Entry_date, Modify_date ' );
qryQry.Sql.Add ( 'from tblvolunteer ' );
qryQry.Sql.Add ( WhereClause );
qryQry.Open;
qryQry.first;
while not qryQry.eof do begin
otblvolunteer := Ttblvolunteer.Create;
otblVolunteer.Volunteer_id := qryQry.FieldByName('Volunt eer_id').A sString;
otblVolunteer.Call_number := qryQry.FieldByName('Call_n umber').As String;
otblVolunteer.Last_name := qryQry.FieldByName('Last_n ame').AsSt ring;
otblVolunteer.First_name := qryQry.FieldByName('First_ name').AsS tring;
otblVolunteer.Middle_name := qryQry.FieldByName('Middle _name').As String;
otblVolunteer.Name_suffix := qryQry.FieldByName('Name_s uffix').As String;
otblVolunteer.DOB := qryQry.FieldByName('DOB'). AsString;
otblVolunteer.House_number := qryQry.FieldByName('House_ number').A sString;
otblVolunteer.Street := qryQry.FieldByName('Street ').AsStrin g;
otblVolunteer.Street_suffi x := qryQry.FieldByName('Street _suffix'). AsString;
otblVolunteer.Direction := qryQry.FieldByName('Direct ion').AsSt ring;
otblVolunteer.Apt_number := qryQry.FieldByName('Apt_nu mber').AsS tring;
otblVolunteer.City := qryQry.FieldByName('City') .AsString;
otblVolunteer.State := qryQry.FieldByName('State' ).AsString ;
otblVolunteer.Zip := qryQry.FieldByName('Zip'). AsString;
otblVolunteer.Home_phone := qryQry.FieldByName('Home_p hone').AsS tring;
otblVolunteer.Work_phone := qryQry.FieldByName('Work_p hone').AsS tring;
otblVolunteer.Cell_phone := qryQry.FieldByName('Cell_p hone').AsS tring;
otblVolunteer.Pager_number := qryQry.FieldByName('Pager_ number').A sString;
otblVolunteer.District := qryQry.FieldByName('Distri ct').AsStr ing;
otblVolunteer.Entry_date := qryQry.FieldByName('Entry_ date').AsS tring;
otblVolunteer.Modify_date := qryQry.FieldByName('Modify _date').As String;
otblVolunteer.ObjStatus := OK;
otblVolunteer.ObjState := ExistingObject;
tblvolunteer.Add ( otblvolunteer );
qryQry.Next;
end;
qryQry.Close;
end;
procedure TtblMgr.SavetblvolunteerOb j;
var
x : integer;
otblvolunteer : Ttblvolunteer;
begin
for x := 0 to tblvolunteer.Count - 1 do begin
if x >= tblvolunteer.Count then break;
otblvolunteer := tblvolunteer[x];
if otblvolunteer.ObjStatus = OK then continue;
tblMgr.WhereClause := 'where Volunteer_id = ''' + otblVolunteer.Volunteer_id + ''' ';
qryQry.Sql.Clear;
case otblvolunteer.ObjStatus of
Added,New: begin
qryQry.Sql.Add ( 'insert into tblVolunteer values ( ' );
if length(trim( otblVolunteer.Volunteer_id ) ) > 0 then
qryQry.Sql.Add ( '''' + otblVolunteer.Volunteer_id + ''', ' )
else
qryQry.Sql.Add ( 'null, ' );
if length(trim( otblVolunteer.Call_number ) ) > 0 then
qryQry.Sql.Add ( '''' + otblVolunteer.Call_number + ''', ' )
else
qryQry.Sql.Add ( 'null, ' );
if length(trim( otblVolunteer.Last_name ) ) > 0 then
qryQry.Sql.Add ( '''' + otblVolunteer.Last_name + ''', ' )
else
qryQry.Sql.Add ( 'null, ' );
if length(trim( otblVolunteer.First_name ) ) > 0 then
qryQry.Sql.Add ( '''' + otblVolunteer.First_name + ''', ' )
else
qryQry.Sql.Add ( 'null, ' );
if length(trim( otblVolunteer.Middle_name ) ) > 0 then
qryQry.Sql.Add ( '''' + otblVolunteer.Middle_name + ''', ' )
else
qryQry.Sql.Add ( 'null, ' );
if length(trim( otblVolunteer.Name_suffix ) ) > 0 then
qryQry.Sql.Add ( '''' + otblVolunteer.Name_suffix + ''', ' )
else
qryQry.Sql.Add ( 'null, ' );
if length(trim( otblVolunteer.DOB ) ) > 0 then
qryQry.Sql.Add ( '''' + otblVolunteer.DOB + ''', ' )
else
qryQry.Sql.Add ( 'null, ' );
if length(trim( otblVolunteer.House_number ) ) > 0 then
qryQry.Sql.Add ( '''' + otblVolunteer.House_number + ''', ' )
else
qryQry.Sql.Add ( 'null, ' );
if length(trim( otblVolunteer.Street ) ) > 0 then
qryQry.Sql.Add ( '''' + otblVolunteer.Street + ''', ' )
else
qryQry.Sql.Add ( 'null, ' );
if length(trim( otblVolunteer.Street_suffi x ) ) > 0 then
qryQry.Sql.Add ( '''' + otblVolunteer.Street_suffi x + ''', ' )
else
qryQry.Sql.Add ( 'null, ' );
if length(trim( otblVolunteer.Direction ) ) > 0 then
qryQry.Sql.Add ( '''' + otblVolunteer.Direction + ''', ' )
else
qryQry.Sql.Add ( 'null, ' );
if length(trim( otblVolunteer.Apt_number ) ) > 0 then
qryQry.Sql.Add ( '''' + otblVolunteer.Apt_number + ''', ' )
else
qryQry.Sql.Add ( 'null, ' );
if length(trim( otblVolunteer.City ) ) > 0 then
qryQry.Sql.Add ( '''' + otblVolunteer.City + ''', ' )
else
qryQry.Sql.Add ( 'null, ' );
if length(trim( otblVolunteer.State ) ) > 0 then
qryQry.Sql.Add ( '''' + otblVolunteer.State + ''', ' )
else
qryQry.Sql.Add ( 'null, ' );
if length(trim( otblVolunteer.Zip ) ) > 0 then
qryQry.Sql.Add ( '''' + otblVolunteer.Zip + ''', ' )
else
qryQry.Sql.Add ( 'null, ' );
if length(trim( otblVolunteer.Home_phone ) ) > 0 then
qryQry.Sql.Add ( '''' + otblVolunteer.Home_phone + ''', ' )
else
qryQry.Sql.Add ( 'null, ' );
if length(trim( otblVolunteer.Work_phone ) ) > 0 then
qryQry.Sql.Add ( '''' + otblVolunteer.Work_phone + ''', ' )
else
qryQry.Sql.Add ( 'null, ' );
if length(trim( otblVolunteer.Cell_phone ) ) > 0 then
qryQry.Sql.Add ( '''' + otblVolunteer.Cell_phone + ''', ' )
else
qryQry.Sql.Add ( 'null, ' );
if length(trim( otblVolunteer.Pager_number ) ) > 0 then
qryQry.Sql.Add ( '''' + otblVolunteer.Pager_number + ''', ' )
else
qryQry.Sql.Add ( 'null, ' );
if length(trim( otblVolunteer.District ) ) > 0 then
qryQry.Sql.Add ( '''' + otblVolunteer.District + ''', ' )
else
qryQry.Sql.Add ( 'null, ' );
if length(trim( otblVolunteer.Entry_date ) ) > 0 then
qryQry.Sql.Add ( '''' + otblVolunteer.Entry_date + ''', ' )
else
qryQry.Sql.Add ( 'null, ' );
if length(trim( otblVolunteer.Modify_date ) ) > 0 then
qryQry.Sql.Add ( '''' + otblVolunteer.Modify_date + ''' ) ' )
else
qryQry.Sql.Add ( 'null ) ' );
end;
Modified: begin
qryQry.Sql.Add ( 'update tblVolunteer set ' );
if length(trim( otblVolunteer.Volunteer_id ) ) > 0 then
qryQry.Sql.Add ( 'Volunteer_id = ''' + otblVolunteer.Volunteer_id + ''', ' )
else
qryQry.Sql.Add ( 'Volunteer_id = null, ' );
if length(trim( otblVolunteer.Call_number ) ) > 0 then
qryQry.Sql.Add ( 'Call_number = ''' + otblVolunteer.Call_number + ''', ' )
else
qryQry.Sql.Add ( 'Call_number = null, ' );
if length(trim( otblVolunteer.Last_name ) ) > 0 then
qryQry.Sql.Add ( 'Last_name = ''' + otblVolunteer.Last_name + ''', ' )
else
qryQry.Sql.Add ( 'Last_name = null, ' );
if length(trim( otblVolunteer.First_name ) ) > 0 then
qryQry.Sql.Add ( 'First_name = ''' + otblVolunteer.First_name + ''', ' )
else
qryQry.Sql.Add ( 'First_name = null, ' );
if length(trim( otblVolunteer.Middle_name ) ) > 0 then
qryQry.Sql.Add ( 'Middle_name = ''' + otblVolunteer.Middle_name + ''', ' )
else
qryQry.Sql.Add ( 'Middle_name = null, ' );
if length(trim( otblVolunteer.Name_suffix ) ) > 0 then
qryQry.Sql.Add ( 'Name_suffix = ''' + otblVolunteer.Name_suffix + ''', ' )
else
qryQry.Sql.Add ( 'Name_suffix = null, ' );
if length(trim( otblVolunteer.DOB ) ) > 0 then
qryQry.Sql.Add ( 'DOB = ''' + otblVolunteer.DOB + ''', ' )
else
qryQry.Sql.Add ( 'DOB = null, ' );
if length(trim( otblVolunteer.House_number ) ) > 0 then
qryQry.Sql.Add ( 'House_number = ''' + otblVolunteer.House_number + ''', ' )
else
qryQry.Sql.Add ( 'House_number = null, ' );
if length(trim( otblVolunteer.Street ) ) > 0 then
qryQry.Sql.Add ( 'Street = ''' + otblVolunteer.Street + ''', ' )
else
qryQry.Sql.Add ( 'Street = null, ' );
if length(trim( otblVolunteer.Street_suffi x ) ) > 0 then
qryQry.Sql.Add ( 'Street_suffix = ''' + otblVolunteer.Street_suffi x + ''', ' )
else
qryQry.Sql.Add ( 'Street_suffix = null, ' );
if length(trim( otblVolunteer.Direction ) ) > 0 then
qryQry.Sql.Add ( 'Direction = ''' + otblVolunteer.Direction + ''', ' )
else
qryQry.Sql.Add ( 'Direction = null, ' );
if length(trim( otblVolunteer.Apt_number ) ) > 0 then
qryQry.Sql.Add ( 'Apt_number = ''' + otblVolunteer.Apt_number + ''', ' )
else
qryQry.Sql.Add ( 'Apt_number = null, ' );
if length(trim( otblVolunteer.City ) ) > 0 then
qryQry.Sql.Add ( 'City = ''' + otblVolunteer.City + ''', ' )
else
qryQry.Sql.Add ( 'City = null, ' );
if length(trim( otblVolunteer.State ) ) > 0 then
qryQry.Sql.Add ( 'State = ''' + otblVolunteer.State + ''', ' )
else
qryQry.Sql.Add ( 'State = null, ' );
if length(trim( otblVolunteer.Zip ) ) > 0 then
qryQry.Sql.Add ( 'Zip = ''' + otblVolunteer.Zip + ''', ' )
else
qryQry.Sql.Add ( 'Zip = null, ' );
if length(trim( otblVolunteer.Home_phone ) ) > 0 then
qryQry.Sql.Add ( 'Home_phone = ''' + otblVolunteer.Home_phone + ''', ' )
else
qryQry.Sql.Add ( 'Home_phone = null, ' );
if length(trim( otblVolunteer.Work_phone ) ) > 0 then
qryQry.Sql.Add ( 'Work_phone = ''' + otblVolunteer.Work_phone + ''', ' )
else
qryQry.Sql.Add ( 'Work_phone = null, ' );
if length(trim( otblVolunteer.Cell_phone ) ) > 0 then
qryQry.Sql.Add ( 'Cell_phone = ''' + otblVolunteer.Cell_phone + ''', ' )
else
qryQry.Sql.Add ( 'Cell_phone = null, ' );
if length(trim( otblVolunteer.Pager_number ) ) > 0 then
qryQry.Sql.Add ( 'Pager_number = ''' + otblVolunteer.Pager_number + ''', ' )
else
qryQry.Sql.Add ( 'Pager_number = null, ' );
if length(trim( otblVolunteer.District ) ) > 0 then
qryQry.Sql.Add ( 'District = ''' + otblVolunteer.District + ''', ' )
else
qryQry.Sql.Add ( 'District = null, ' );
if length(trim( otblVolunteer.Entry_date ) ) > 0 then
qryQry.Sql.Add ( 'Entry_date = ''' + otblVolunteer.Entry_date + ''', ' )
else
qryQry.Sql.Add ( 'Entry_date = null, ' );
if length(trim( otblVolunteer.Modify_date ) ) > 0 then
qryQry.Sql.Add ( 'Modify_date = ''' + otblVolunteer.Modify_date + '''' )
else
qryQry.Sql.Add ( 'Modify_date = null ' );
qryQry.Sql.Add ( WhereClause );
end;
Deleted: begin
qryQry.Sql.Add ( 'delete from tblVolunteer ' );
qryQry.Sql.Add ( WhereClause );
end;
end;
try
//qryQry.SQL.SaveToFile('H :\Vol.sql' );
qryQry.ExecSql;
if otblvolunteer.ObjStatus <> Deleted then begin
Ttblvolunteer(tblvolunteer [x]).ObjSt ate := ExistingObject;
Ttblvolunteer(tblvolunteer [x]).ObjSt atus := OK;
end else
tblvolunteer.Delete(x);
qryQry.Close;
except
on e: Exception do begin
MessageDlg(e.Message, mtError, [mbOK],0);
qryQry.Close;
end;
end;
end;
end;
end.
If you have more questions please ask,
Mark
I have delphi3. I have a unit called Comimp here it is in its' entirety:
unit ComImp;
interface
uses Windows, Classes, Dialogs, SysUtils, Messages, DB, DBTables,
Forms, dmImp;
// Define Types for tbl object statuses
type TtblState = (NewObject,ExistingObject)
type TtblStatus = (OK,Added,Modified,Deleted
type TCheckBoxState = (cbUnchecked,cbChecked);
// Define base object for tbl object
type TtblObj = class(TObject)
private
{ Private declarations }
fOID : Integer;
fState : TtblState;
fStatus : TtblStatus;
fSelected : Boolean;
public
{ Public declarations }
property OID : Integer read fOID write fOID;
property ObjState : TtblState read fState write fState;
property ObjStatus : TtblStatus read fStatus write fStatus;
property Selected : Boolean read fSelected write fSelected;
constructor create;
procedure Initialize;
end;
type TtblVolunteer = class(TtblObj)
Private
{ Private declarations }
fVolunteer_id : String;
fCall_number : String;
fLast_name : String;
fFirst_name : String;
fMiddle_name : String;
fName_suffix : String;
fDOB : String;
fHouse_number : String;
fStreet : String;
fStreet_suffix : String;
fDirection : String;
fApt_number : String;
fCity : String;
fState : String;
fZip : String;
fHome_phone : String;
fWork_phone : String;
fCell_phone : String;
fPager_number : String;
fDistrict : String;
fEntry_date : String;
fModify_date : String;
Public
{ Public declarations }
property Volunteer_id : String read fVolunteer_id write fVolunteer_id;
property Call_number : String read fCall_number write fCall_number;
property Last_name : String read fLast_name write fLast_name;
property First_name : String read fFirst_name write fFirst_name;
property Middle_name : String read fMiddle_name write fMiddle_name;
property Name_suffix : String read fName_suffix write fName_suffix;
property DOB : String read fDOB write fDOB;
property House_number : String read fHouse_number write fHouse_number;
property Street : String read fStreet write fStreet;
property Street_suffix : String read fStreet_suffix write fStreet_suffix;
property Direction : String read fDirection write fDirection;
property Apt_number : String read fApt_number write fApt_number;
property City : String read fCity write fCity;
property State : String read fState write fState;
property Zip : String read fZip write fZip;
property Home_phone : String read fHome_phone write fHome_phone;
property Work_phone : String read fWork_phone write fWork_phone;
property Cell_phone : String read fCell_phone write fCell_phone;
property Pager_number : String read fPager_number write fPager_number;
property District : String read fDistrict write fDistrict;
property Entry_date : String read fEntry_date write fEntry_date;
property Modify_date : String read fModify_date write fModify_date;
constructor create;
procedure Initialize;
end;
type TtblMgr = class(TObject)
Private
{ Private declarations }
fWhereClause : String;
ftblVolunteer : TList;
Public
{ Public declarations }
property WhereClause : String read fWhereClause write fWhereClause;
property tblvolunteer : TList read ftblvolunteer write ftblvolunteer;
procedure CleartblMgr;
procedure LoadtblvolunteerObj;
procedure SavetblvolunteerObj;
constructor Create;
destructor Destroy; override;
end;
var
GlobalOID : integer;
SortInActive : integer;
display : integer;
tblMgr : TtblMgr;
qryQry : TQuery;
tslCallNo, tslVolunteerName,
tslActivityNo, tslActivityName : TStringList;
//function GetR : Integer;
procedure InitApplication;
procedure CloseApplication;
implementation
{function GetR : Integer;
Var
i : integer;
begin
result := -1;
with dm do begin
qryQry.Sql.clear;
qryQry.Sql.Add ( 'SELECT Gen_no ');
qryQry.Sql.Add ( 'FROM tblNos ' );
qryQry.Sql.Add ( 'Where Id = ''Range'' ' );
qryQry.open;
end;
i := qryQry.FieldByName('Gen_no
RVar:= i;
qryQry.close;
result := 1;
end; }
procedure InitApplication;
begin
tblMgr := TtblMgr.Create;
//Application.CreateForm(T
GlobalOID := 0;
//OrderType := 0;
//SortActive := 0;
//SortInActive := 0;
tslActivityName := tstringlist.Create;
tslActivityNo := tstringlist.create;
end;
procedure CloseApplication;
begin
tblMgr.CleartblMgr;
tblMgr.Destroy;
qryQry.Destroy;
//DM.Destroy;
tslActivityNo.Destroy;
tslActivityName.Destroy;
end;
constructor TtblObj.create;
begin
inherited create;
OID := 0;
end;
procedure TtblObj.Initialize;
begin
GlobalOID := GlobalOID + 1;
OID := GlobalOID;
Selected := False;
end;
constructor TtblMgr.create;
begin
inherited create;
tblVolunteer := TList.Create;
end;
destructor TtblMgr.Destroy;
begin
CleartblMgr;
tblVolunteer.Destroy;
inherited destroy;
end;
procedure TtblMgr.CleartblMgr;
var
x : integer;
begin
for x := tblVolunteer.Count -1 downto 0 do
tblVolunteer.Delete(x);
end;
constructor TtblVolunteer.create;
begin
inherited create;
Initialize;
end;
procedure Ttblvolunteer.Initialize;
begin
inherited Initialize;
Volunteer_id := '';
Call_number := '';
Last_name := '';
First_name := '';
Middle_name := '';
Name_suffix := '';
DOB := '';
House_number := '';
Street := '';
Street_suffix := '';
Direction := '';
Apt_number := '';
City := '';
State := '';
Zip := '';
Home_phone := '';
Work_phone := '';
Cell_phone := '';
Pager_number := '';
District := '';
Entry_date := '';
Modify_date := '';
ObjState := NewObject;
ObjStatus := New;
end;
procedure TtblMgr.LoadtblvolunteerOb
var
otblvolunteer : Ttblvolunteer;
begin
otblvolunteer := Nil;
qryQry.Sql.Clear;
qryQry.Sql.Add ( 'select Volunteer_id, Call_number, Last_name, First_name, ' );
qryQry.Sql.Add ( ' Middle_name, Name_suffix, DOB, ' );
qryQry.Sql.Add ( ' House_number, Street, Street_suffix, Direction, ' );
qryQry.Sql.Add ( ' Apt_number, City, State, Zip, Home_phone, ' );
qryQry.Sql.Add ( ' Work_phone, Cell_phone, Pager_number, District, ' );
qryQry.Sql.Add ( ' Entry_date, Modify_date ' );
qryQry.Sql.Add ( 'from tblvolunteer ' );
qryQry.Sql.Add ( WhereClause );
qryQry.Open;
qryQry.first;
while not qryQry.eof do begin
otblvolunteer := Ttblvolunteer.Create;
otblVolunteer.Volunteer_id
otblVolunteer.Call_number := qryQry.FieldByName('Call_n
otblVolunteer.Last_name := qryQry.FieldByName('Last_n
otblVolunteer.First_name := qryQry.FieldByName('First_
otblVolunteer.Middle_name := qryQry.FieldByName('Middle
otblVolunteer.Name_suffix := qryQry.FieldByName('Name_s
otblVolunteer.DOB := qryQry.FieldByName('DOB').
otblVolunteer.House_number
otblVolunteer.Street := qryQry.FieldByName('Street
otblVolunteer.Street_suffi
otblVolunteer.Direction := qryQry.FieldByName('Direct
otblVolunteer.Apt_number := qryQry.FieldByName('Apt_nu
otblVolunteer.City := qryQry.FieldByName('City')
otblVolunteer.State := qryQry.FieldByName('State'
otblVolunteer.Zip := qryQry.FieldByName('Zip').
otblVolunteer.Home_phone := qryQry.FieldByName('Home_p
otblVolunteer.Work_phone := qryQry.FieldByName('Work_p
otblVolunteer.Cell_phone := qryQry.FieldByName('Cell_p
otblVolunteer.Pager_number
otblVolunteer.District := qryQry.FieldByName('Distri
otblVolunteer.Entry_date := qryQry.FieldByName('Entry_
otblVolunteer.Modify_date := qryQry.FieldByName('Modify
otblVolunteer.ObjStatus := OK;
otblVolunteer.ObjState := ExistingObject;
tblvolunteer.Add ( otblvolunteer );
qryQry.Next;
end;
qryQry.Close;
end;
procedure TtblMgr.SavetblvolunteerOb
var
x : integer;
otblvolunteer : Ttblvolunteer;
begin
for x := 0 to tblvolunteer.Count - 1 do begin
if x >= tblvolunteer.Count then break;
otblvolunteer := tblvolunteer[x];
if otblvolunteer.ObjStatus = OK then continue;
tblMgr.WhereClause := 'where Volunteer_id = ''' + otblVolunteer.Volunteer_id
qryQry.Sql.Clear;
case otblvolunteer.ObjStatus of
Added,New: begin
qryQry.Sql.Add ( 'insert into tblVolunteer values ( ' );
if length(trim( otblVolunteer.Volunteer_id
qryQry.Sql.Add ( '''' + otblVolunteer.Volunteer_id
else
qryQry.Sql.Add ( 'null, ' );
if length(trim( otblVolunteer.Call_number ) ) > 0 then
qryQry.Sql.Add ( '''' + otblVolunteer.Call_number + ''', ' )
else
qryQry.Sql.Add ( 'null, ' );
if length(trim( otblVolunteer.Last_name ) ) > 0 then
qryQry.Sql.Add ( '''' + otblVolunteer.Last_name + ''', ' )
else
qryQry.Sql.Add ( 'null, ' );
if length(trim( otblVolunteer.First_name ) ) > 0 then
qryQry.Sql.Add ( '''' + otblVolunteer.First_name + ''', ' )
else
qryQry.Sql.Add ( 'null, ' );
if length(trim( otblVolunteer.Middle_name ) ) > 0 then
qryQry.Sql.Add ( '''' + otblVolunteer.Middle_name + ''', ' )
else
qryQry.Sql.Add ( 'null, ' );
if length(trim( otblVolunteer.Name_suffix ) ) > 0 then
qryQry.Sql.Add ( '''' + otblVolunteer.Name_suffix + ''', ' )
else
qryQry.Sql.Add ( 'null, ' );
if length(trim( otblVolunteer.DOB ) ) > 0 then
qryQry.Sql.Add ( '''' + otblVolunteer.DOB + ''', ' )
else
qryQry.Sql.Add ( 'null, ' );
if length(trim( otblVolunteer.House_number
qryQry.Sql.Add ( '''' + otblVolunteer.House_number
else
qryQry.Sql.Add ( 'null, ' );
if length(trim( otblVolunteer.Street ) ) > 0 then
qryQry.Sql.Add ( '''' + otblVolunteer.Street + ''', ' )
else
qryQry.Sql.Add ( 'null, ' );
if length(trim( otblVolunteer.Street_suffi
qryQry.Sql.Add ( '''' + otblVolunteer.Street_suffi
else
qryQry.Sql.Add ( 'null, ' );
if length(trim( otblVolunteer.Direction ) ) > 0 then
qryQry.Sql.Add ( '''' + otblVolunteer.Direction + ''', ' )
else
qryQry.Sql.Add ( 'null, ' );
if length(trim( otblVolunteer.Apt_number ) ) > 0 then
qryQry.Sql.Add ( '''' + otblVolunteer.Apt_number + ''', ' )
else
qryQry.Sql.Add ( 'null, ' );
if length(trim( otblVolunteer.City ) ) > 0 then
qryQry.Sql.Add ( '''' + otblVolunteer.City + ''', ' )
else
qryQry.Sql.Add ( 'null, ' );
if length(trim( otblVolunteer.State ) ) > 0 then
qryQry.Sql.Add ( '''' + otblVolunteer.State + ''', ' )
else
qryQry.Sql.Add ( 'null, ' );
if length(trim( otblVolunteer.Zip ) ) > 0 then
qryQry.Sql.Add ( '''' + otblVolunteer.Zip + ''', ' )
else
qryQry.Sql.Add ( 'null, ' );
if length(trim( otblVolunteer.Home_phone ) ) > 0 then
qryQry.Sql.Add ( '''' + otblVolunteer.Home_phone + ''', ' )
else
qryQry.Sql.Add ( 'null, ' );
if length(trim( otblVolunteer.Work_phone ) ) > 0 then
qryQry.Sql.Add ( '''' + otblVolunteer.Work_phone + ''', ' )
else
qryQry.Sql.Add ( 'null, ' );
if length(trim( otblVolunteer.Cell_phone ) ) > 0 then
qryQry.Sql.Add ( '''' + otblVolunteer.Cell_phone + ''', ' )
else
qryQry.Sql.Add ( 'null, ' );
if length(trim( otblVolunteer.Pager_number
qryQry.Sql.Add ( '''' + otblVolunteer.Pager_number
else
qryQry.Sql.Add ( 'null, ' );
if length(trim( otblVolunteer.District ) ) > 0 then
qryQry.Sql.Add ( '''' + otblVolunteer.District + ''', ' )
else
qryQry.Sql.Add ( 'null, ' );
if length(trim( otblVolunteer.Entry_date ) ) > 0 then
qryQry.Sql.Add ( '''' + otblVolunteer.Entry_date + ''', ' )
else
qryQry.Sql.Add ( 'null, ' );
if length(trim( otblVolunteer.Modify_date ) ) > 0 then
qryQry.Sql.Add ( '''' + otblVolunteer.Modify_date + ''' ) ' )
else
qryQry.Sql.Add ( 'null ) ' );
end;
Modified: begin
qryQry.Sql.Add ( 'update tblVolunteer set ' );
if length(trim( otblVolunteer.Volunteer_id
qryQry.Sql.Add ( 'Volunteer_id = ''' + otblVolunteer.Volunteer_id
else
qryQry.Sql.Add ( 'Volunteer_id = null, ' );
if length(trim( otblVolunteer.Call_number ) ) > 0 then
qryQry.Sql.Add ( 'Call_number = ''' + otblVolunteer.Call_number + ''', ' )
else
qryQry.Sql.Add ( 'Call_number = null, ' );
if length(trim( otblVolunteer.Last_name ) ) > 0 then
qryQry.Sql.Add ( 'Last_name = ''' + otblVolunteer.Last_name + ''', ' )
else
qryQry.Sql.Add ( 'Last_name = null, ' );
if length(trim( otblVolunteer.First_name ) ) > 0 then
qryQry.Sql.Add ( 'First_name = ''' + otblVolunteer.First_name + ''', ' )
else
qryQry.Sql.Add ( 'First_name = null, ' );
if length(trim( otblVolunteer.Middle_name ) ) > 0 then
qryQry.Sql.Add ( 'Middle_name = ''' + otblVolunteer.Middle_name + ''', ' )
else
qryQry.Sql.Add ( 'Middle_name = null, ' );
if length(trim( otblVolunteer.Name_suffix ) ) > 0 then
qryQry.Sql.Add ( 'Name_suffix = ''' + otblVolunteer.Name_suffix + ''', ' )
else
qryQry.Sql.Add ( 'Name_suffix = null, ' );
if length(trim( otblVolunteer.DOB ) ) > 0 then
qryQry.Sql.Add ( 'DOB = ''' + otblVolunteer.DOB + ''', ' )
else
qryQry.Sql.Add ( 'DOB = null, ' );
if length(trim( otblVolunteer.House_number
qryQry.Sql.Add ( 'House_number = ''' + otblVolunteer.House_number
else
qryQry.Sql.Add ( 'House_number = null, ' );
if length(trim( otblVolunteer.Street ) ) > 0 then
qryQry.Sql.Add ( 'Street = ''' + otblVolunteer.Street + ''', ' )
else
qryQry.Sql.Add ( 'Street = null, ' );
if length(trim( otblVolunteer.Street_suffi
qryQry.Sql.Add ( 'Street_suffix = ''' + otblVolunteer.Street_suffi
else
qryQry.Sql.Add ( 'Street_suffix = null, ' );
if length(trim( otblVolunteer.Direction ) ) > 0 then
qryQry.Sql.Add ( 'Direction = ''' + otblVolunteer.Direction + ''', ' )
else
qryQry.Sql.Add ( 'Direction = null, ' );
if length(trim( otblVolunteer.Apt_number ) ) > 0 then
qryQry.Sql.Add ( 'Apt_number = ''' + otblVolunteer.Apt_number + ''', ' )
else
qryQry.Sql.Add ( 'Apt_number = null, ' );
if length(trim( otblVolunteer.City ) ) > 0 then
qryQry.Sql.Add ( 'City = ''' + otblVolunteer.City + ''', ' )
else
qryQry.Sql.Add ( 'City = null, ' );
if length(trim( otblVolunteer.State ) ) > 0 then
qryQry.Sql.Add ( 'State = ''' + otblVolunteer.State + ''', ' )
else
qryQry.Sql.Add ( 'State = null, ' );
if length(trim( otblVolunteer.Zip ) ) > 0 then
qryQry.Sql.Add ( 'Zip = ''' + otblVolunteer.Zip + ''', ' )
else
qryQry.Sql.Add ( 'Zip = null, ' );
if length(trim( otblVolunteer.Home_phone ) ) > 0 then
qryQry.Sql.Add ( 'Home_phone = ''' + otblVolunteer.Home_phone + ''', ' )
else
qryQry.Sql.Add ( 'Home_phone = null, ' );
if length(trim( otblVolunteer.Work_phone ) ) > 0 then
qryQry.Sql.Add ( 'Work_phone = ''' + otblVolunteer.Work_phone + ''', ' )
else
qryQry.Sql.Add ( 'Work_phone = null, ' );
if length(trim( otblVolunteer.Cell_phone ) ) > 0 then
qryQry.Sql.Add ( 'Cell_phone = ''' + otblVolunteer.Cell_phone + ''', ' )
else
qryQry.Sql.Add ( 'Cell_phone = null, ' );
if length(trim( otblVolunteer.Pager_number
qryQry.Sql.Add ( 'Pager_number = ''' + otblVolunteer.Pager_number
else
qryQry.Sql.Add ( 'Pager_number = null, ' );
if length(trim( otblVolunteer.District ) ) > 0 then
qryQry.Sql.Add ( 'District = ''' + otblVolunteer.District + ''', ' )
else
qryQry.Sql.Add ( 'District = null, ' );
if length(trim( otblVolunteer.Entry_date ) ) > 0 then
qryQry.Sql.Add ( 'Entry_date = ''' + otblVolunteer.Entry_date + ''', ' )
else
qryQry.Sql.Add ( 'Entry_date = null, ' );
if length(trim( otblVolunteer.Modify_date ) ) > 0 then
qryQry.Sql.Add ( 'Modify_date = ''' + otblVolunteer.Modify_date + '''' )
else
qryQry.Sql.Add ( 'Modify_date = null ' );
qryQry.Sql.Add ( WhereClause );
end;
Deleted: begin
qryQry.Sql.Add ( 'delete from tblVolunteer ' );
qryQry.Sql.Add ( WhereClause );
end;
end;
try
//qryQry.SQL.SaveToFile('H
qryQry.ExecSql;
if otblvolunteer.ObjStatus <> Deleted then begin
Ttblvolunteer(tblvolunteer
Ttblvolunteer(tblvolunteer
end else
tblvolunteer.Delete(x);
qryQry.Close;
except
on e: Exception do begin
MessageDlg(e.Message, mtError, [mbOK],0);
qryQry.Close;
end;
end;
end;
end;
end.
If you have more questions please ask,
Mark
Why are you using Queries to add records? This is a little bit out of proportion. Besides, I have 'dmImp' nor the tables so I can't test.
The only thing you need to do is create a TTable object:
MyTable := TTable.Create(nil);
MyTable.DatabaseName := <the name of the database>;
MyTable.TableName := <the name of the table>;
MyTable.Active := true;
And when the app closes:
MyTable.Free;
Use AppendPerson(MyTable, fn, ln, ph) to add records.
Make sure that the fieldnames in the 'AppendPerson' function have the correct names.
Epsylon.
The only thing you need to do is create a TTable object:
MyTable := TTable.Create(nil);
MyTable.DatabaseName := <the name of the database>;
MyTable.TableName := <the name of the table>;
MyTable.Active := true;
And when the app closes:
MyTable.Free;
Use AppendPerson(MyTable, fn, ln, ph) to add records.
Make sure that the fieldnames in the 'AppendPerson' function have the correct names.
Epsylon.
ASKER
Epsylon,
Ok I changed it adding in that bit of code you just sent but I still get these errors...
Undeclared identifier 'Locate'. and
Undeclared identifier 'Post'.
I looked for info on locate and found this:
TChartValueList component //do I need to declare this in my uses
// I tried declaring it and it gave error msg
Declaration // file not found: TChartValueList.dcu'.
function Locate (Const Value:Double):Longint;
Description
This new function returns the corresponding point index which has the specified “Value”. You can use it to calculate X co-ordinates based on Y values or vice-versa:
Mark
Ok I changed it adding in that bit of code you just sent but I still get these errors...
Undeclared identifier 'Locate'. and
Undeclared identifier 'Post'.
I looked for info on locate and found this:
TChartValueList component //do I need to declare this in my uses
// I tried declaring it and it gave error msg
Declaration // file not found: TChartValueList.dcu'.
function Locate (Const Value:Double):Longint;
Description
This new function returns the corresponding point index which has the specified “Value”. You can use it to calculate X co-ordinates based on Y values or vice-versa:
Mark
Post and Locate are methods in TTable.
The 'with' statement of the 'AppendPerson' function refers to a TTable object, so 'Post' and 'Locate' should not give errors.
The 'with' statement of the 'AppendPerson' function refers to a TTable object, so 'Post' and 'Locate' should not give errors.
In case I don't understand what I mean I'll summarize it:
Create the TTable like this:
MyTable := TTable.Create(nil);
MyTable.DatabaseName := <the name of the database>;
MyTable.TableName := <the name of the table>;
MyTable.Active := true;
Add a record to the database like this:
AppendPerson(MyTable, fn, ln, ph);
Use this function:
procedure Append_Person(thetable: TTable; firstname, lastname, phone: String);
var DoAppend: Boolean;
begin
with thetable do
begin
if not Locate('LastName', name, []) then
DoAppend := true
else
if (FieldByName('FirstName'). AsString <> firstname) then
DoAppend := true
else
DoAppend := false;
if DoAppend then
begin
Append;
FieldByName('FirstName').A sString := firstname;
FieldByName('LastName').As String := lastname;
FieldByName('Phone').AsStr ing := phone;
Post;
end;
end;
end;
Create the TTable like this:
MyTable := TTable.Create(nil);
MyTable.DatabaseName := <the name of the database>;
MyTable.TableName := <the name of the table>;
MyTable.Active := true;
Add a record to the database like this:
AppendPerson(MyTable, fn, ln, ph);
Use this function:
procedure Append_Person(thetable: TTable; firstname, lastname, phone: String);
var DoAppend: Boolean;
begin
with thetable do
begin
if not Locate('LastName', name, []) then
DoAppend := true
else
if (FieldByName('FirstName').
DoAppend := true
else
DoAppend := false;
if DoAppend then
begin
Append;
FieldByName('FirstName').A
FieldByName('LastName').As
FieldByName('Phone').AsStr
Post;
end;
end;
end;
Forgot to say that MyTable is defined as:
var MyTable: TTable;
var MyTable: TTable;
ASKER
Epsylon,
Ok so that idea did not work too well but I had another idea. borrowed some code from my brother and incorporated into this program. Instead of using a Tlist what about using a just a listbox, then somehow compare if a name is a dublicate on that listbox. If there is remove it and and reorder it. Here is what my precedure looks like. I will add comments to it to help clarify my code.
procedure TfrmMain.bImportClick(Send er: TObject);
var
i, logNum, VolNum : Integer;
LogNo, VolId, act : String;
ln, fn, phone : String;
sDir, code, CallNo : String;
begin
AssignFile ( InpFile, edit1.text); //open the file
Reset ( InpFile ); //open the file
lastln := 'xxx'; //compare to xxx so the first loop continues
LogNum := 2001; //start at 2001 so you dont over write data
VolNum := 11; // same thing
Date := '08/02/1999 10:00'; // put in whatever is todays date could have
while ( not EOF(InpFile) ) do begin // used now
memo1.Lines.Clear;
readln ( inpfile, DataRec ); // read in data file
memo1.Lines.add(Datarec); // for display purpose only
//this is the import of data
ln := Trim(copy ( Datarec, 1, 17)); //this is the location of lastname on txt file
fn := Trim(copy ( Datarec, 18, 11)); //this is fisrtname on the txt file
Phone := Trim(copy ( Datarec, 36, 7)); //this is the phone number
LogNum := LogNum + 1; //generate a log number
logNo := inttostr(LogNum); //since logno is a string convert it
Volnum := Volnum + 1; //same kind of thing
VolId := inttostr(VolNum); // same
if Lastln = ln then continue; //this will add poeple to the lbVol list
count := count + 1;
lbVol.Items.Add ( format ( '%-5.5s %s, %s, %s, %s', [VolId, Ln, Fn, phone]));
lastln := ln; //this will make the last name equal to the last one loaded
//here is where some kind of loop to compare to see
for 0 to count do begin //if their are duplicate lastname + firstnames
if lbActivity.Selected[i] then begin
bDidSelect := True;
break;
end;
end;
end;
what do you think of this idea?
Mark
Ok so that idea did not work too well but I had another idea. borrowed some code from my brother and incorporated into this program. Instead of using a Tlist what about using a just a listbox, then somehow compare if a name is a dublicate on that listbox. If there is remove it and and reorder it. Here is what my precedure looks like. I will add comments to it to help clarify my code.
procedure TfrmMain.bImportClick(Send
var
i, logNum, VolNum : Integer;
LogNo, VolId, act : String;
ln, fn, phone : String;
sDir, code, CallNo : String;
begin
AssignFile ( InpFile, edit1.text); //open the file
Reset ( InpFile ); //open the file
lastln := 'xxx'; //compare to xxx so the first loop continues
LogNum := 2001; //start at 2001 so you dont over write data
VolNum := 11; // same thing
Date := '08/02/1999 10:00'; // put in whatever is todays date could have
while ( not EOF(InpFile) ) do begin // used now
memo1.Lines.Clear;
readln ( inpfile, DataRec ); // read in data file
memo1.Lines.add(Datarec); // for display purpose only
//this is the import of data
ln := Trim(copy ( Datarec, 1, 17)); //this is the location of lastname on txt file
fn := Trim(copy ( Datarec, 18, 11)); //this is fisrtname on the txt file
Phone := Trim(copy ( Datarec, 36, 7)); //this is the phone number
LogNum := LogNum + 1; //generate a log number
logNo := inttostr(LogNum); //since logno is a string convert it
Volnum := Volnum + 1; //same kind of thing
VolId := inttostr(VolNum); // same
if Lastln = ln then continue; //this will add poeple to the lbVol list
count := count + 1;
lbVol.Items.Add ( format ( '%-5.5s %s, %s, %s, %s', [VolId, Ln, Fn, phone]));
lastln := ln; //this will make the last name equal to the last one loaded
//here is where some kind of loop to compare to see
for 0 to count do begin //if their are duplicate lastname + firstnames
if lbActivity.Selected[i] then begin
bDidSelect := True;
break;
end;
end;
end;
what do you think of this idea?
Mark
ASKER
The proposed asnwer never worked. I will ask a new question instead that is similar to this question.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Dave,
That will do for now. Show me the rest of your work on this program so I can compare our two codes.
Mark
That will do for now. Show me the rest of your work on this program so I can compare our two codes.
Mark
ASKER