?
Solved

Add data to a Tlist and compare with 2nd Tlist

Posted on 1999-08-01
19
Medium Priority
?
362 Views
Last Modified: 2010-04-04
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
0
Comment
Question by:Bekkerus
[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
  • 11
  • 7
19 Comments
 

Author Comment

by:Bekkerus
ID: 1392256
Edited text of question.
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 1392257
You could write the info directly to the table without using lists:

procedure TForm1.Append_Person(firstname, 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').AsString := firstname;
      FieldByName('LastName').AsString := lastname;
      FieldByName('Phone').AsString := phone;
      Post;
    end;
  end;
end;


Regards,

Epsylon.

0
 

Author Comment

by:Bekkerus
ID: 1392258
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').AsString <> 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').AsString := ln);
        (qryQry.FieldByName('First_name').AsString := fn);
        (qryQry.FieldByName('Phone').AsString := ph);
        Post;
     end;
   end;
end;


Regards,

Mark
0
Technology Partners: 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!

 

Author Comment

by:Bekkerus
ID: 1392259
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').AsString <> 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').AsString := ln);
        (qryQry.FieldByName('First_name').AsString := fn);
        (qryQry.FieldByName('Phone').AsString := ph);
        Post;
     end;
   end;
end;


Regards,

Mark
0
 

Author Comment

by:Bekkerus
ID: 1392260
Ahh
 
   Doe!!! I posted the same message twice.

Mark
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 1392261
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').AsString := firstname;
      FieldByName('LastName').AsString := lastname;
      FieldByName('Phone').AsString := phone;
      Post;
    end;
  end;
end;


Now call it with AppendPerson(tblPerson, fn, ln, ph);

where tblPerson is a TTable.

Epsylon.
0
 

Author Comment

by:Bekkerus
ID: 1392262
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').AsDateTime);
     if DoAppend then begin        
        Append;                 //'(' expected but ':' found.
        FieldByName('Last_name').AsString := ln;    //missing operator or semicolon
        FieldByName('First_name').AsString := fn;    //missing operator or semicolon
        FieldByName('Phone').AsString := phone;     //missing operator or semicolon
        Post;                    //Undeclared identifier: 'Post'.
     end;
   end;
end;

Regards,

Mark
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 1392263
What Delphi version are you using and how did you set up your table? How is tblMgr.tblPhone defined?
0
 

Author Comment

by:Bekkerus
ID: 1392264
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').AsInteger;
  RVar:= i;
  qryQry.close;
  result := 1;
end;    }


procedure InitApplication;
begin
   tblMgr  := TtblMgr.Create;
   //Application.CreateForm(TDM, 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.LoadtblvolunteerObj;
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('Volunteer_id').AsString;
       otblVolunteer.Call_number     := qryQry.FieldByName('Call_number').AsString;
       otblVolunteer.Last_name       := qryQry.FieldByName('Last_name').AsString;
       otblVolunteer.First_name      := qryQry.FieldByName('First_name').AsString;
       otblVolunteer.Middle_name     := qryQry.FieldByName('Middle_name').AsString;
       otblVolunteer.Name_suffix     := qryQry.FieldByName('Name_suffix').AsString;
       otblVolunteer.DOB             := qryQry.FieldByName('DOB').AsString;
       otblVolunteer.House_number    := qryQry.FieldByName('House_number').AsString;
       otblVolunteer.Street          := qryQry.FieldByName('Street').AsString;
       otblVolunteer.Street_suffix   := qryQry.FieldByName('Street_suffix').AsString;
       otblVolunteer.Direction       := qryQry.FieldByName('Direction').AsString;
       otblVolunteer.Apt_number      := qryQry.FieldByName('Apt_number').AsString;
       otblVolunteer.City            := qryQry.FieldByName('City').AsString;
       otblVolunteer.State           := qryQry.FieldByName('State').AsString;
       otblVolunteer.Zip             := qryQry.FieldByName('Zip').AsString;
       otblVolunteer.Home_phone      := qryQry.FieldByName('Home_phone').AsString;
       otblVolunteer.Work_phone      := qryQry.FieldByName('Work_phone').AsString;
       otblVolunteer.Cell_phone      := qryQry.FieldByName('Cell_phone').AsString;
       otblVolunteer.Pager_number    := qryQry.FieldByName('Pager_number').AsString;
       otblVolunteer.District        := qryQry.FieldByName('District').AsString;
       otblVolunteer.Entry_date      := qryQry.FieldByName('Entry_date').AsString;
       otblVolunteer.Modify_date     := qryQry.FieldByName('Modify_date').AsString;
       otblVolunteer.ObjStatus        := OK;
       otblVolunteer.ObjState         := ExistingObject;
       tblvolunteer.Add ( otblvolunteer );
       qryQry.Next;
   end;

   qryQry.Close;

end;

procedure  TtblMgr.SavetblvolunteerObj;
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_suffix ) ) > 0 then
                          qryQry.Sql.Add ( '''' + otblVolunteer.Street_suffix + ''', ' )
                       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_suffix ) ) > 0 then
                          qryQry.Sql.Add ( 'Street_suffix =  ''' + otblVolunteer.Street_suffix + ''', ' )
                       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]).ObjState  := ExistingObject;
             Ttblvolunteer(tblvolunteer[x]).ObjStatus := 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
0
 

Author Comment

by:Bekkerus
ID: 1392265
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').AsInteger;
  RVar:= i;
  qryQry.close;
  result := 1;
end;    }


procedure InitApplication;
begin
   tblMgr  := TtblMgr.Create;
   //Application.CreateForm(TDM, 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.LoadtblvolunteerObj;
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('Volunteer_id').AsString;
       otblVolunteer.Call_number     := qryQry.FieldByName('Call_number').AsString;
       otblVolunteer.Last_name       := qryQry.FieldByName('Last_name').AsString;
       otblVolunteer.First_name      := qryQry.FieldByName('First_name').AsString;
       otblVolunteer.Middle_name     := qryQry.FieldByName('Middle_name').AsString;
       otblVolunteer.Name_suffix     := qryQry.FieldByName('Name_suffix').AsString;
       otblVolunteer.DOB             := qryQry.FieldByName('DOB').AsString;
       otblVolunteer.House_number    := qryQry.FieldByName('House_number').AsString;
       otblVolunteer.Street          := qryQry.FieldByName('Street').AsString;
       otblVolunteer.Street_suffix   := qryQry.FieldByName('Street_suffix').AsString;
       otblVolunteer.Direction       := qryQry.FieldByName('Direction').AsString;
       otblVolunteer.Apt_number      := qryQry.FieldByName('Apt_number').AsString;
       otblVolunteer.City            := qryQry.FieldByName('City').AsString;
       otblVolunteer.State           := qryQry.FieldByName('State').AsString;
       otblVolunteer.Zip             := qryQry.FieldByName('Zip').AsString;
       otblVolunteer.Home_phone      := qryQry.FieldByName('Home_phone').AsString;
       otblVolunteer.Work_phone      := qryQry.FieldByName('Work_phone').AsString;
       otblVolunteer.Cell_phone      := qryQry.FieldByName('Cell_phone').AsString;
       otblVolunteer.Pager_number    := qryQry.FieldByName('Pager_number').AsString;
       otblVolunteer.District        := qryQry.FieldByName('District').AsString;
       otblVolunteer.Entry_date      := qryQry.FieldByName('Entry_date').AsString;
       otblVolunteer.Modify_date     := qryQry.FieldByName('Modify_date').AsString;
       otblVolunteer.ObjStatus        := OK;
       otblVolunteer.ObjState         := ExistingObject;
       tblvolunteer.Add ( otblvolunteer );
       qryQry.Next;
   end;

   qryQry.Close;

end;

procedure  TtblMgr.SavetblvolunteerObj;
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_suffix ) ) > 0 then
                          qryQry.Sql.Add ( '''' + otblVolunteer.Street_suffix + ''', ' )
                       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_suffix ) ) > 0 then
                          qryQry.Sql.Add ( 'Street_suffix =  ''' + otblVolunteer.Street_suffix + ''', ' )
                       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]).ObjState  := ExistingObject;
             Ttblvolunteer(tblvolunteer[x]).ObjStatus := 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
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 1392266
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.
0
 

Author Comment

by:Bekkerus
ID: 1392267
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
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 1392268
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.
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 1392269
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').AsString := firstname;
      FieldByName('LastName').AsString := lastname;
      FieldByName('Phone').AsString := phone;
      Post;
    end;
  end;
end;
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 1392270
Forgot to say that MyTable is defined as:

var MyTable: TTable;
0
 

Author Comment

by:Bekkerus
ID: 1392271
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(Sender: 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
0
 

Author Comment

by:Bekkerus
ID: 1392272

  The proposed asnwer never worked. I will ask a new question instead that is similar to this question.
0
 
LVL 1

Accepted Solution

by:
nex1999 earned 200 total points
ID: 1392273
Mark,

   This should do what you were asking me about a few weeks ago. If not talk to me later.

type
  PMyList = ^AList;
  AList = record
    id   : String;
    l    : String;
    f    : String;
    d    : String;
    cn   : String;
end;
var
 SdateYY, SdateMM, SdateDD, Sdate, thours, lastln : string;
 EdateYY, EdateMM, EdateDD, Edate, stime, etime   : string;
 date, stimeHH, stimeMM, etimeHH, etimeMM  : string;
 sstime, eetime, pass, scn, sdi, sln, sid, sfn :String;
 startHH, endHH, i, m, logNum, VolNum : integer;
 MyList  : TList;
 PAList  : PMyList;
 Index   : Integer;
begin
   oVol := TtblVolunteer.Create;
   MyList := TList.Create;
   lbVol.Items.Clear;
   AssignFile ( InpFile, edit1.text);              //open the file
   Reset ( InpFile );                              //open the file
   lastln := 'jhfjhdjfhjdhfkjdhkf';
   LogNum := 2001;
   VolNum := 11;
   Date := '07/24/1999 10:00';
   while ( not EOF(InpFile) ) do begin
     memo1.Lines.Clear;
     readln ( inpfile, NaoRec );
     memo1.Lines.add(naorec);
     ln       := Trim(copy ( naorec, 1, 17));
     fn       := Trim(copy ( naorec, 18, 11));
     Dist     := Trim(copy ( naorec, 35, 1));
     CallNo   := Trim(copy ( naorec, 36, 4));
     SdateYY  := Trim(copy ( naorec, 29, 2));
     SdateMM  := Trim(copy ( naorec, 31, 2));
     SdateDD  := Trim(copy ( naorec, 33, 2));
     SDate    := SdateMM + '/' + SdateDD + '/' + '19' + SdateYY + ' ' + '10:00';  //add the date together in correct format
     EdateYY  := Trim(copy ( naorec, 29, 2));
     EdateMM  := Trim(copy ( naorec, 31, 2));
     EdateDD  := Trim(copy ( naorec, 33, 2));
     EDate    := EdateMM + '/' + EdateDD + '/' + '19' + EdateYY + ' ' + '10:00';  //add the date together in correct format
     stimeHH  := Trim(copy ( naorec, 40, 2));
     stimeMM  := Trim(copy ( naorec, 42, 2));
     stime    := SdateMM + '/' + SdateDD + '/' + '19' + SdateYY + ' ' + stimeHH + ':' + stimeMM;
     etimeHH  := Trim(copy ( naorec, 44, 2));
     etimeMM  := Trim(copy ( naorec, 46, 2));

     If eTimeHH = '24' then begin
          eTimeHH := '00';
          etime := DateToStr(StrToDate(eDateMM +'/'+eDateDD+'/'+'19'+eDateYY)+1)+' '+eTimeHH+':'+eTimeMM;
     end
     else
         etime := eDateMM +'/'+eDateDD+'/'+'19'+eDateYY+' '+etimeHH+':'+etimeMM;

     tHours := FloatToStrF(((StrToDateTime(etime)-StrToDateTime(stime)) * 24),ffFixed,20,2);


     LogNum  := LogNum + 1;
     logNo := inttostr(LogNum);
     Volnum := Volnum + 1;
     VolId  := inttostr(VolNum);


     {System.New(PAList);    //missing operator or semicolon.
     PAList^.id  := VolId;
     PAList^.l   := ln;
     PAList^.f   := fn;
     PAList^.d   := dist;
     PAList^.cn  := callno;}
     //MyList.Add(PAList);
     
     //NaoMgr.tblVolunteer.Add (oVol);

     MyList.add(NaoMgr.tblvolunteer);
     for m := 0 to MyList.Count - 1 do begin
        if lastln = TVList(Mylist[m]).l then begin
           MyList.Remove(Mylist[m]);
           continue
        end
        else
           MyList.add(TVList);
     end;                           //add to listbox
     lastln :=  ln;

     //lbVol.Items.Add ( format ( '%-5.5s %s, %s, %s, %s', [VolId, Ln, Fn, callno, dist]) );
     //Yourstring := PMyList(Mylist[Index])^.l;
    end;

    for m := 0 to MyList.Count - 1 do begin
       sid         := TVList(Mylist[m]).id;
       sfn         := TVList(Mylist[m]).l;
       sln         := TVList(Mylist[m]).f;
       sdi         := TVList(Mylist[m]).d;
       scn         := TVList(Mylist[m]).cn;
       lbVol.Items.Add ( format ( '%-4.4s%s', [scn, sdi, sln, sid, sfn]) );
     end;


end;

David
0
 

Author Comment

by:Bekkerus
ID: 1392274
Dave,

  That will do for now. Show me the rest of your work on this program so I can compare our two codes.

Mark
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
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 video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

719 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