Delphi Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreDelphi Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 24th, 2012, 07:43 AM
havsys havsys is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2012
Posts: 12 havsys User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 40 m 3 sec
Reputation Power: 0
Help to create buttons - beginner

Hello, Im a beginner and i need help with my problem.
How to create insert/save/update/delete and clear Fields(DBEdit) buttons for mysql database using delphi.

This is my example.

First I create mysql database:
create database Contacts;

create table coktacts(
id int auto_increment primary key not null,
First_name varchar(25) not null,
Last_name varchar(25) not null,
Address varchar(50) not null,
Country varchar(25) not null,
Phone varchar(13));


Then I create application in delphi.

File -> New -> VLC Forms Application

In Forms I Use:

DBGrid
5 buttons (insert/save/Update/delete/clear)
AdoConnection
AdoDataset
Data Source

then set my AdoConnection:
- ConnectionString: Find my source to connection ...
- LoginPrompt: false
- Connected: True
- Name: AdoConnection1

Then set AdoDataSet:
Connection: AdoConnection1
Name: AdoDataSet1
CommandType: cmdTable
CommandText: Contacts
for dataset I use Field Editor-add fields-Drag and Drop to Form.

Then set DAtaSource:
DataSet: AdoDataSet1
Name: DataSource1

Then set DBGrid:
DataSource: DataSource1
ColumnsTDBGridColumns): id, First Name, Last Name, Address, Country, Phone.

For Show my database into DBgrid I use Code:
for procedure TForm3.FormCreate(Sender: TObject);
begin
ADODataSet1.Active := true;
end;

Question 1: how to create insert/save/update/delete/clear buttons?
I dont want to use DBnavigator.

When I click INSERT button I want to clear DBEdits fiels(Firstname,lastname,address ...) input new contact info and SAVE to my database.

Reply With Quote
  #2  
Old July 24th, 2012, 11:54 PM
Luthfi Luthfi is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2012
Posts: 140 Luthfi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 4 h 58 m 17 sec
Reputation Power: 2
Quote:
Originally Posted by havsys
Question 1: how to create insert/save/update/delete/clear buttons?
I dont want to use DBnavigator.


Basically just place a button (either TButton, TBitBtn, or TSpeedButton - I recommend TBitBtn) for each operation to your form then put appropriates codes in their OnClick events. Like for example I show for your next question.

Quote:
When I click INSERT button I want to clear DBEdits fiels(Firstname,lastname,address ...) input new contact info and SAVE to my database.


When a new record is appended to a dataset, its fields will be initialized to default values predefined for the dataset. If no default value defined for a field, it will be given the value of null (for now you can consider this value similar with empty). Therefore if the code in your INSERT button OnClick event adds new record to a dataset, its current record will contain fields with either default values or empty.

If there is no default values defined, then all the fields will be empty, which looks like the same with clearing the TDBEdit controls. So assuming your INSERT button is named btnInsert, you can use the following code in its OnClick event handler.

Code:
procedure TForm1.btnInsertClick(Sender: TObject);
begin
  AdoDataSet1.Append;
end;


Note that Append does not automatically save the new record into database. If you do not change anything in your new record and you change your active record, the new record will be lost (deleted).

to save the new record, you can put the following code for your SAVE button.

Code:
procedure TForm1.btnSaveClick(Sender: TObject);
begin
  AdoDataSet1.Post;
end;

Reply With Quote
  #3  
Old July 25th, 2012, 04:20 AM
havsys havsys is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2012
Posts: 12 havsys User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 40 m 3 sec
Reputation Power: 0
Thank you Luthfi, your post is very helpful for me

Reply With Quote
  #4  
Old July 25th, 2012, 08:23 AM
majlumbo majlumbo is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2008
Posts: 255 majlumbo User rank is Lance Corporal (50 - 100 Reputation Level)majlumbo User rank is Lance Corporal (50 - 100 Reputation Level)majlumbo User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 3 Days 2 m 15 sec
Reputation Power: 5
One of the nice things about the DBNavigator control is that it will enable/disable buttons as appropriate depending on the current state of the datasource. So if you are just browsing your records, the post button is not enabled, but is when you start making any changes to a record. Adding a new record, will disable the new record button, but will enable your cancel and post buttons.

They all work in unison, so just attaching the event handler for each button is only half the story. You would also need to add code to enable/disable those buttons as the state of your datasource changes.

These actions are appropriate to be coded in the DataSource's OnStateChange event, something like:
Code:
procedure TForm1.DataSource1StateChange(Sender: TObject);
begin
   PostButton.Enabled := DataSource1.State in [dsInsert, dsEdit];
   NextButton.Enabled := DataSource1.State in ...
end;


The valid states a datasource can be in is:

dsInactive
dsBrowse
dsEdit
dsInsert
dsSetKey
dsCalcFields
dsFilter
dsNewValue - Internal use only
dsOldValue - Internal use only
dsCurValue - Internal use only
dsBlockRead
dsInternalCalc - Internal use only
dsOpening

Reply With Quote
  #5  
Old July 27th, 2012, 06:02 AM
selvakarthi selvakarthi is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2012
Posts: 7 selvakarthi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 10 m 40 sec
Reputation Power: 0
Creating buttons

Choose Edit > Deselect All, or click an empty area of the Stage to ensure that nothing is selected on the Stage.

Choose Insert > New Symbol.

In the Create New Symbol dialog box, enter a name. For the symbol Type, select Button.

Flash Pro switches to symbol-editing mode. The Timeline changes to display four consecutive frames labeled Up, Over, Down, and Hit. The first frame, Up, is a blank keyframe.

To create the Up state button image, select the Up frame in the Timeline. Then use the drawing tools, import a graphic, or place an instance of another symbol on the Stage.

You can use graphic symbols or movie clip symbols inside a button, but you cannot use another button symbol.


Regards,
Selva.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreDelphi Programming > Help to create buttons - beginner

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap