Benshark was engaged in program development in January 2003 and has been working for 19 months. Among them, the work intermittently is all because of the shoddy things developed by one's own lack of experience, which leads to wandering and employment difficulties! Now Bensha has reached the ability of a qualified programmer.
Generally speaking, the development task for newly graduated programmers is just a module in a subproject in a project. A module has almost 5-6 forms with a code volume of about 2,000 lines. In fact, this amount of tasks is not as good as the graduation design, so it should be able to be completed, but the development time is relatively small, about 6-12 working days, rather than 1-2 months in school, and there are also classmates to help. So, it is proficient in developers' development tools, syntax, frameworks and libraries. In addition, you can understand the system platform operation mechanism and algorithm requirements and know what is going on. It is required that programmers be able to work actively rather than passively. Can take the initiative to find information, ask colleagues, and ask colleagues to provide assistance with unknown tasks.
This shark is mainly engaged in the development tasks of the database system front desk, so it mainly uses common database components to illustrate that the tasks of the data system front desk are the heaviest and are always criticized by users.
Generally, the development steps of this shark are:
0 Understand task requirements
1. Implement the function first
2. Resolve function exception handling
3. Achieve user-friendliness
4 Solve user-friendliness
The performance problem will be left to the user to solve it if the data volume is large in the future! At present, it is important to catch up with the task. It is nothing more than adding new deletion, modification, saving query statistics! The following components are commonly used
TEdit TComboBox TListView TTreeView TCheckListBox TLabel TDBGrid TImage TMemo TButton TDBChart TPanel TMaskEdit TDateTimePicker TPageControl
1. Code style. Only during the interview will your code style have an impact on the interviewer. The style is for people to see and naturally meets the aesthetic conditions. Although many companies have completed a set of style standards, I think it is boring. There is no need to force things, styles, etc. Since you are using Borland tools, it is best to follow the Borland style.
2 component attribute settings
1 TLabel : AutoSize = Flase;
2 TEdit Set the MaxLength value default input method value
3 TComboBox If only selection is allowed, Style:= csDropDownList; Sorted :=True;
When adding data to its Items
FontCombo->Items->BeginUpdate(); // PRevent repaints until done
FontCombo->Items->Add("XXX"); //
FontCombo->Items->EndUpdate(); //reenable painting
No matter how much data TListView TTreeView TDBGird has similar data display blocking functions.
4 TTreeView If you do not modify the text of the node, you need to readOnly RowSelect = true;
5 TListView ViewStyle vsReportReadOnly RowSelect = true; if not modified
6 TPageControl PageControl1.ActivePageIndex := 0;
7 TDateTimePicker DateFormat := dfLong If time is copied to Edit
Edit.Text := DateTimeFormate("YYYY-MM-DD", DateTimePicker1.Date)
8 TButton To set Cancel ModalResult Hint
3 Components with the same interface layout should be placed together and aligned with the surroundings, up, down, left and right. And aligned with the components of other containers, which many newbies ignore! Because the Borland alignment tool can only be used for the parent container, and finally give it to people. Neatly beautiful.
Interface layout details
1): Use Frame to frame buttons that complete the same or similar functions, and commonly used buttons must support shortcuts.
2): Elements that complete the same function or task are placed in a centralized position to reduce the distance of the mouse movement.
3): Divide local blocks of the interface according to the function, enclose them with a Frame box, and have a function description or title.
4): The interface must support the keyboard automatic browsing button function, that is, the automatic switching function of pressing the Tab key.
5): The controls that should first enter and important information on the interface should be in front of the Tab order, and should also be placed in a more conspicuous position on the window.
6): It is best not to exceed 10 controls on the same interface. If there are more than 10, you can consider using the pagination interface to display it.
7): The pagination interface should support quick switching between pages, and the commonly used combination shortcut keys Ctrl+Tab
8): The default button must support Enter and select operations, that is, after pressing Enter, the corresponding operations of the default button are automatically executed.
9): After the writable control detects illegal input, the description should be given and the focus can be automatically obtained.
10): The order of the Tab keys and the order of the controls should be consistent. At present, the popular way is generally from top to bottom and from left to right between lines.
11): Check boxes and option boxes are arranged one after another according to the high bottom of the selection probability.
12): Check boxes and option boxes must have default options and support Tab selection.
13): When the number of options is the same, use the option box instead of the drop-down list box.
14): Use the drop-down box instead of option box when the interface space is small.
15): When the number of options is called small, use the option box, instead use the drop-down list box.
16): Software with strong professionalism should use relevant professional terms, while the universal interface advocates the use of universal words.
4 Codes
1 Functional inspection: Check whether all functions and restrictions required by the requirements are implemented
2 Boundary check: Perform boundary checks on functions such as input from different data types or data of different ranges
3 Illegal access check: Test whether there is an illegal memory access error. The reference error message for determining whether it belongs to this type of error is similar:
”…not found”, ”List index out of bounds…”, “access violation at address…”
4: Prompt information guidance check: Enter any characters at will, including edit boxes, table boxes, and selection boxes, including English and Chinese characters, test whether illegal access errors will be caused, and whether unacceptable characters will be used. There are prompts and tips to be guided.
5 Unit-based inspection: Check whether the unit header description in this unit, the description of each function, and the annotation description are correct. Citation instructions: Is there any extra citations
//Especially, if the C++ header file contains unnecessary Include, unnecessary problems will occur for other units.
In fact, these are called white-collar tests and unit test content. If you want to write test code according to the test book, I think every developer doesn’t want it! But it won’t work, it’s easy to make mistakes and make it difficult to deliver. Therefore, it is very necessary to understand the methods of testing, these methods
There are introductions to software engineering in universities, and software designers must also be taken. Whenever you write a program, you will be careful to consider what errors may occur in different situations! Although will the variables to be used when implementing the function be empty? Is the value valid? Is it overflowing? Do you clear the space of the variable? Is it a case requirement? Are there spaces in front and after?
These judgments must first be written in the function and the beginning of the process!
if(TreeView->Selected ==NULL) // Will the variable be empty?
then return ;
std::vecotr<int> intArray;// Is it overflowing?
if(intArray <=0)
Then return;
if( i< ListView.Items->Count) // Is it overflowing and crossing the boundary?
Edit->Text = ListView->Items-Item[i].Caption;
Edit->Text.Trim();//Is there any space before and after?
char a[10];
memcpy(a,"/0",10);// Do you clear the space of the variable?
a[9]='I'; //In fact, if your current function wants to write something to the transmitted variable and write it in its space, you must clear it and write it
//The person who uses your function writes a loop to call your function variable will bring the last value. If your function has a judgment in the middle but does not write data to it, then return the last data to the caller ! And the caller's judgment conditions will lose their effect!
if(Name.Trim() ==”DELPHI”) then Name=”BCB”; Is the value valid?
switch() { case to Break; to default: ;}
5 Default data, prompts, positioning and friendliness
When the interface is displayed, the data will be displayed by default. TDBGird TListView TTreeView ComboBox. All data should be displayed.
ComboBox1.ItemIndex := 0;
Generally speaking, new additions and modifications will be edited in a single pair using one interface. When the new addition is completed, all components must be positioned on the newly added record, and the same is true for modification. When deleting, locate the next record.
ListView and DBGird To have the function of sorting click the title to go up/down by numeric letter date
ListView and DBGird When the selected data focus is moved on the button, which row is currently selected? !
void __fastcall TfrmGather760::lvDataCustomDrawItem(TCustomListView *Sender, TListItem *Item, TCustomDrawState State,bool &DefaultDraw) //This code will draw a yellow bottom on the selected line
{
if(Sender->Selected !=NULL)
if(Item->Index == Sender->Selected->Index)
{
Sender->Canvas->Brush->Color = clYellow;
Sender->Canvas->Font->Color = clBlue;
}
}
For operations that usually exceed 2 seconds, it must be in the function.
TCursor OldCursor;
OldCursor = Screen->Cursor;
Screen->Cursor = crSQLWait;
try{ . . . . . . } __ finally{Screen->Cursor = OldCursor;}
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;Shift: TShiftState);
Begin
if (Shift = []) and (Key = VK_RETURN) then //Replace the Tab key with Enter
Perform(WM_NEXTDLGCTL, 0, 0);
if Key = VK_NEXT then //Press PageUp PageDown to make TPageControl switch page
Begin
if PageControl.ActivePageIndex = PageControl.PageCount - 1 then
PageControl.ActivePageIndex := 0
else
PageControl.ActivePageIndex := PageControl.ActivePageIndex + 1;
end
else if Key = VK_PRIOR then
Begin
if PageControl.ActivePageIndex = 0 then
PageControl.ActivePageIndex := PageControl.PageCount - 1
else
PageControl.ActivePageIndex := PageControl.ActivePageIndex - 1;
end;
end;
end.
6 Button Interchange
Whenever an operation is completed, some buttons will become invalid, and under what circumstances will they be restored to validity? Although there is only one paragraph, if it is not set ineffective, it will often cause various fatal errors! Because you cannot predict how users will operate your software, you can use Rose to draw a status diagram or use Word to represent it!
7 Performance
When there are more than 100 data, the data display components such as ComboBox Listbox TreeView ListView DBGrid are entered and query while entering.
Supporting fuzzy queries is nothing more than Like '%XXX%'. You can make a separate window to display the found data in the window.
void __fastcall TfrmGather760::Edt_NameKeyPress(TObject *Sender,char &Key)
{
if(Key != VK_RETURN)
return;
String sSQL;
sSQL =" Select Name as Name, Sales as Sales, from employee";
sSQL +=" where Name like '%"+ LowerCase(Edt_Name->Text.Trim()) + "%' ";
TfrmPubDlg *pubDlg = new TfrmPubDlg(this);
pubDlg->ExecuteQuery(sSQL);
pubDlg->ShowModal();
.....
}
8 Others
When developing a module, individual units and DFM are used as common units. Will make a character transmission structure in the unit
Struct TableName
{
String Name;
String FiledName;
......
}; //The main thing is to keep consistency in more units, especially when the table name changes
std::vector<String> sErrorArry //Unified error prompt
And the Delphi ResoucString segment can be resourced and easier to localize
When adding and modifying, all the data checks are concentrated under the save button
void __fastcall TForm3::Btn_SaveClick(Sender)
{
if(Edt_Name->Text.IsEmpty())
{
ShowMessage("");
Edit_Name->SetFocus(); //Focus should be positioned
return;
}
ModalResult = mrOk;
}
Most of the graduation designs of students in school are databases, such as two or three layers. You must do the graduation design program seriously, and spend money to ask your classmates to help you do the test, and propose more operational convenience. Only by passing other people's tests can your ability be improved, and most of the code is exception handling and user-friendly! It will be very easy to find a good company when you look for a job with your works
In fact, when engaged in database front desk development, the important thing is to write user-friendly code! Being a programmer is not only an intellectual labor, but also a physical and mental labor!