Home arrow Delphi-Kylix arrow Page 2 - Looking at the Details for an Invoicing Application in Delphi
DELPHI-KYLIX

Looking at the Details for an Invoicing Application in Delphi


In the previous article we discussed the requirements and purpose of the invoicing application that we are creating. We also listed the main application code. In this part of the article we are going to look at how to connect the database that we created earlier to the application code. We will also look at some of the code in detail.

Author Info:
By: Chris Neeman
Rating: 5 stars5 stars5 stars5 stars5 stars / 4
July 16, 2007
TABLE OF CONTENTS:
  1. · Looking at the Details for an Invoicing Application in Delphi
  2. · Settings Unit
  3. · New Invoice Form and Code
  4. · Invoice Management Code and Output
  5. · Client Management Code
  6. · Final output and Conclusion

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Looking at the Details for an Invoicing Application in Delphi - Settings Unit
(Page 2 of 6 )

unit settings;

interface

uses

  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

  Dialogs, StdCtrls, Buttons,INIFiles;

type

  TForm3 = class(TForm)

    StaticText1: TStaticText;

    btnsave: TBitBtn;

    edVat: TEdit;

    StaticText2: TStaticText;

    Label1: TLabel;

    btnexit: TBitBtn;

    StaticText3: TStaticText;

    edcon: TEdit;

    StaticText4: TStaticText;

    StaticText5: TStaticText;

    Label2: TLabel;

    procedure btnsaveClick(Sender: TObject);

    procedure FormCreate(Sender: TObject);

    procedure btnexitClick(Sender: TObject);

  private

    { Private declarations }

  public

    { Public declarations }

  end;

var

  Form3: TForm3;

implementation

 uses invmain;

{$R *.dfm}

procedure TForm3.btnsaveClick(Sender: TObject);

var

settings : TINIFile;

begin

 settings := TINIFile.Create(ExtractFilePath(Application.EXEName) + 'settings.ini');

    try

    settings.WriteFloat('Settings', 'vat', strtofloat(edvat.Text));

    settings.WriteString('Settings', 'con', edcon.Text);

    messagedlg('Your settings will take effect the next time you start the Invoice Manager.', mtinformation , [mbOK], 0);

    finally

    settings.Free;

    close;

      end;

end;

procedure TForm3.FormCreate(Sender: TObject);

begin

label1.caption:=floattostr(form1.vat);

label2.caption:=form1.con;

end;

procedure TForm3.btnexitClick(Sender: TObject);

begin

close;

end;

end.

Of these three values that are stored in the ini file, the one that is most critical to the application is the "con" variable. As I’ve stated already, the value stored within this variable is used by the application to connect to the database tables. The database connections are made after the form is created, and just before the form is shown. Below is the code responsible for doing this:

procedure TForm1.FormShow(Sender: TObject);

var

i:integer;

begin

//set ado properties

ado1.ConnectionString:=con;

ado1.TableName:='invoices';

ado1.Active:=true;

 label1.caption:=inttostr(ado1.RecordCount);

  i:=ado1.RecordCount;

label2.Caption:=inttostr(i);

end;

Currently the "con" variable contains the following path:

Provider=Microsoft.Jet.OLEDB.4.0;Data Source=inv.mdb;Persist Security Info=False

Within the above line you can clearly see the name of the database. I wanted to point that out before we discuss the FormShow procedure, because this procedure shows code that only loads the table, and of course anyone looking at the code would ask, "How does the application know which database to use?" The code starts by setting the ado1 table’s connection string to the path specified in the con variable and then (since it knows which database to use) it sets the tablename property of the ado table component and activates it. Label1 and label2 displays the total number of records (invoices) in the database and the invoice number of the the current location of the record pointer.


blog comments powered by Disqus
DELPHI-KYLIX ARTICLES

- Loading an XML Document into the DOM
- Delphi Wrapper Classes and XML
- Delphi and the DOM
- Delphi and XML
- Internet Access: Client Service
- Finishing the Client for an Internet Access ...
- The Client for an Internet Access Control Ap...
- User Management for an Internet Access Contr...
- Important Procedures for an Internet Access ...
- Server Code for an Internet Access Control A...
- Constructing the Interface for an Internet A...
- Building a Server Application for an Interne...
- Building an Internet Access Control Applicat...
- Client Dataset: Working with Data Packets an...
- Using the Client Dataset in an N-Tiered Appl...

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 4 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials