Link to home
Start Free TrialLog in
Avatar of error77
error77

asked on

Project Approach advice needed

Hi all,

I need some advice here on how to best approach this.

I am working on a project where I need to add people's details for example:

Name, Surname and address.

So, I have the fields -  eg: two textboxes and  a memo (for example) for each person.

So, everytime I click on add record I get a new two textboxes and  a memo ... if I click 3 times then I get 3 etc.

But everytime the new fields are added they are added after each other at runtime so scrolling might be necessary?

Each record would have a name or id so:

id = 1

has 4 people

id = 2

has 7 people

etc etc...

What's the best way to approach this project please?

I'll need to later search and read different records so I would need to save to database?

Thanks
Avatar of BdLm
BdLm
Flag of Germany image

you should work with lists (TObjectList) and classes eg.  define
a class

   Person= class
       Name, Surname and address : String
      end;

Create a new Class / person and add this one to your object List .....
     
ASKER CERTIFIED SOLUTION
Avatar of BdLm
BdLm
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
last 2 comments:  
----------------------------    1 -------------------------------------------------------
change    TCustomer = class
    private
      // The data fields of this new class
      CustomerName   : String;
      CustomerNumber : Integer
      CustomerAddress : String;
      CustomerSurname :String

........

----------------------------------   2 --------------------------------------------------

insterad of myList : TList  later I recommend
                  myList : TObjectList


but first ---  is this the solution you are looking for ??
To store the data into a database or text file we can discuss later on
Avatar of Geert G
the approach ?
the first thing, ask questions about your project

first > what budget do you have ?
none > free databases (mysql, oracle express, sql express)
no limit > oracle/sqlserver enterprise and RemObjects

second > knowledge
> delphi, are you a beginner ?
  >> look for tutorials > about.com has a lot
  >> look for ready made components or projects on torry.net or embarcadero.com
> advanced ???

third > project scope
> what time do you have ?
> what does the project do ?
> how many users ?
> how much data ?
> lan/wan ?
> type ? website ? exe ? service ?
> can you find all the resources ?

fourth > 
> project blueprint
> development plan
> testing plan
> deployment plan

>finally > you can get started with coding ... :)
Avatar of error77
error77

ASKER

2 Things...

1.   On myList : TObjectList  I get Undeclared identifier: 'TObjectList'

and also...How can I visually test this please?

THanks

i would advice looking for complete projects on torry.net

a CD catalogueing program with a database is a nice start for learning ...
http://www.torry.net/pages.php?id=1216




can you get the demo code running - compiled , .....  (if not I can create a zip and post that code here)

TObjectList    http://delphi.wikia.com/wiki/TObjectList_Class

need a unit to be added    

 uses ContNrs;
Avatar of error77

ASKER

Geert_Gruwez: Source is not available on these projects.
Avatar of error77

ASKER

BdLm: The project now compiles fine but it just shows a blank form.

What do I need to do to have a visual please?
place a TMemo on you form and a Button, double click the button and add code here like :




form1.Bottonclick (.....)
var  i : Integer;
begin
  // And redisplay the list
  for i := 0 to myList.Count-1 do
  begin
      memo1.lines.add(TCustomer(myList[i]).Name+' is customer number '+ IntToStr(TCustomer(myList[i]).Number));
  end;

end;

Open in new window

you may add other buttons for add elements, clear the list ......    do you need more help on that also ?
Avatar of error77

ASKER

I get access violation here: for i := 0 to myList.Count-1 do

Here is what I have in full below

 
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ContNrs;

type
  // The customer class definition
  TCustomer = class
    private
      // The data fields of this new class
       // The data fields of this new class
      CustomerName   : String;
      CustomerNumber : Integer;
      CustomerAddress : String;
      CustomerSurname :String;

    public
      // Properties to read these data values
      property Name : String
          read CustomerName;
      property Number : Integer
          read CustomerNumber;

      // Constructor
      constructor Create(const CustomerName   : String;
                         const CustomerNumber : Integer);
  end;

  // The form class definition
  TForm1 = class(TForm)
    Memo1: TMemo;
    Button1: TButton;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);

  private
    // The TList object we use in this code
      myList : TObjectList;

    // Method to show the contents of our list object
    procedure ShowListContents;

  public

  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}


// Customer constructor
// --------------------------------------------------------------------------
constructor TCustomer.Create(const CustomerName   : String;
                             const CustomerNumber : Integer);
begin
  // Save the passed parameters
  self.CustomerName   := CustomerName;
  self.CustomerNumber := CustomerNumber;
end;


// TList sort routine : compare customers by name
// --------------------------------------------------------------------------
// The returned integer has the following value :
//
//   > 0 : (positive) Item1 is less than Item2
//     0 : Item1 is equal to Item2
//   < 0 : (negative) Item1 is greater than Item2
function compareByName(Item1 : Pointer; Item2 : Pointer) : Integer;
var
  customer1, customer2 : TCustomer;
begin
  // We start by viewing the object pointers as TCustomer objects
  customer1 := TCustomer(Item1);
  customer2 := TCustomer(Item2);

  // Now compare by string
  if      customer1.Name > customer2.Name
  then Result := 1
  else if customer1.Name = customer2.Name
  then Result := 0
  else Result := -1;
end;


// A routine to display the contents of our list
// --------------------------------------------------------------------------
procedure TForm1.ShowListContents;
var
  i : Integer;
begin
  // And redisplay the list
  for i := 0 to myList.Count-1 do
  begin
    ShowMessage(TCustomer(myList[i]).Name+' is customer number '+
                IntToStr(TCustomer(myList[i]).Number));
  end;
end;

// Form constructor
// --------------------------------------------------------------------------
procedure TForm1.Button1Click(Sender: TObject);
var  i : Integer;
begin
  // And redisplay the list
  for i := 0 to myList.Count-1 do
  begin
      memo1.lines.add(TCustomer(myList[i]).Name+' is customer number '+ IntToStr(TCustomer(myList[i]).Number));
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
var
  customer : TCustomer;

begin
  // Create the TList object to hold a set of customer objects
  myList := TObjectList.Create;

  // Create some customer objects and add to our object list
  customer := TCustomer.Create('Neil Moffatt', 123);
  myList.Add(customer);
  customer := TCustomer.Create('Bill Gates', 64);
  myList.Add(customer);

  // We can add the object without assigning to an intermediate variable
  myList.Add(TCustomer.Create('Henry Cooper', 999));
  myList.Add(TCustomer.Create('Alan Sugar', 2));

  // Now display the list
  ShowListContents;

  // We will now sort the list into name sequence and redisplay
  myList.Sort(compareByName);

  // And redisplay the list
  ShowListContents;

  // Now do some object inserts and deletes
  // Note that indices start at 0
  myList.Insert(2, TCustomer.Create('Added as item 3', 33));
  myList.Delete(4);

  // And redisplay the list
  ShowListContents;

  // Free up the list
  myList.free;
end;

end.
Show full unit code
   Neil Moffatt is customer number 123
   Bill Gates is customer number 64
   Henry Cooper is customer number 999
   Alan Sugar is customer number 2
  
   Alan Sugar is customer number 2
   Bill Gates is customer number 64
   Henry Cooper is customer number 999
   Neil Moffatt is customer number 123
  
   Alan Sugar is customer number 2
   Bill Gates is customer number 64
   Added as item 3 is customer number 33
   Henry Cooper is customer number 999

Open in new window

google ... your best resource ...

code central in edn on embarcadero.com

http://ddaf.sourceforge.net/
http://sourceforge.net/projects/acctgsys/

what bdlm is trying to show you is the very tip of the iceberg ...
the start of a database framework

how you do it
> create a TCustomer class
> this class will read and write customer info to the database

> next create a TCustomers container > for managing multiple customers

this implies that you know all the ins and outs of delphi database programming ...
Avatar of error77

ASKER

What I'm after is a delphi version of a html table ... each instance of the table would be added at runtime.

Is this more clear?
ugh ?
this is completely different than your original question...
Avatar of error77

ASKER

Might be my way of explaining it :o/ Will open another question.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial